Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process page breaks #16

Open
wants to merge 2 commits into
base: vNext
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion OpenXmlPowerTools/WmlToHtmlConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
Twitter: @EricWhiteDev
Email: [email protected]

Version : 3.1.12b ( Q2C )
* Add page break functionality

Version: 3.1.12
* Improve layout of list items, using "display: inline-block" with a width rule.
* Streamline HTML, omitting unnecessary formatting-related HTML (e.g., <b>bold</b>, <i>italic</i>).
Expand Down Expand Up @@ -405,6 +408,17 @@ private static void SetStyleElementValue(XElement xhtml, string styleValue)
}
}

private static bool HasAPageBreak(XElement element)
{
if(element != null && element.Descendants() != null)
{
var validElements = element.Descendants().Where(el => el.Name == W.br).ToList();
return validElements.Descendants().Any(dl => dl != null && dl.Attribute(W.type).Value != null && dl.Attribute(W.type).Value == "page");

}
return false;
}

private static object ConvertToHtmlTransform(WordprocessingDocument wordDoc,
WmlToHtmlConverterSettings settings, XNode node,
bool suppressTrailingWhiteSpace,
Expand Down Expand Up @@ -478,7 +492,15 @@ private static object ConvertToHtmlTransform(WordprocessingDocument wordDoc,
// Transform contents of runs.
if (element.Name == W.r)
{
return ConvertRun(wordDoc, settings, element);
if (HasAPageBreak(element)) //Page break must happen in the parent of the element ( in HTML). So no runs then.
{
return ProcessPageBreak(element);
}
else
{
return ConvertRun(wordDoc, settings, element);
}

}

// Transform w:bookmarkStart into anchor
Expand Down Expand Up @@ -686,6 +708,20 @@ private static object ProcessTab(XElement element)
return span;
}

private static object ProcessPageBreak(XElement element)
{
XElement div = new XElement(Xhtml.div);
div.SetAttributeValue(NoNamespace.style, "page-break-before:always;");
XElement span = null;

return new object[]
{
div,
new XEntity("#x200e"),
span
};
}

private static object ProcessBreak(XElement element)
{
XElement span = null;
Expand Down