The main cause of the issue with checkbox misalignment was the workaround for the unsupported Scaling. So, we have now added support for CharacterFormat.Scaling
in output PDF:
Install-Package GemBox.Document -Version 35.0.1517-hotfix
The issue with the missing lines occurs because these are the VML polyline shapes that need to be converted to custom geometry shapes, but unfortunately, GemBox.Document currently doesn’t support this conversion.
We will introduce this in the future, but for now, perhaps something like this can be used:
var document = DocumentModel.Load("Minnesota-HIPAA-Auth-Form.docx");
var preservedInlines = document.GetChildElements(true).OfType<PreservedInline>().ToList();
foreach (var preservedInline in preservedInlines)
{
string rawXml = preservedInline.ToString();
var xml = XElement.Parse(rawXml);
if (xml.Name != "{http://schemas.openxmlformats.org/wordprocessingml/2006/main}pict")
continue;
var polyline = xml.Element("{urn:schemas-microsoft-com:vml}polyline");
if (polyline == null)
continue;
var points = polyline.Attribute("points").Value
.Split(',')
.Select(coord => ParseNumber(coord))
.ToList();
if (points.Count != 4)
continue;
string style = polyline.Attribute("style").Value;
string horizontal = Regex.Match(style, "mso-position-horizontal-relative:([a-z]+)").Groups[1].Value;
var horizontalAnchor = horizontal switch
{
"page" => HorizontalPositionAnchor.Page,
_ => throw new NotImplementedException()
};
string vertical = Regex.Match(style, "mso-position-vertical-relative:([a-z]+)").Groups[1].Value;
var verticalAnchor = vertical switch
{
"page" => VerticalPositionAnchor.Page,
"text" => VerticalPositionAnchor.Paragraph,
_ => throw new NotImplementedException()
};
string strokecolor = polyline.Attribute("strokecolor").Value;
var color = new Color(int.Parse(strokecolor.TrimStart('#'), NumberStyles.HexNumber));
string strokeweight = polyline.Attribute("strokeweight").Value;
var weight = ParseNumber(strokeweight);
var horizontalLine = new Shape(document, ShapeType.Line,
new FloatingLayout(
new HorizontalPosition(points[0], LengthUnit.Point, horizontalAnchor),
new VerticalPosition(points[1], LengthUnit.Point, verticalAnchor),
new Size(points[2] - points[0], points[3] - points[1]))
{ WrappingStyle = TextWrappingStyle.InFrontOfText });
horizontalLine.Outline.Fill.SetSolid(color);
horizontalLine.Outline.Width = weight;
var parent = preservedInline.ParentCollection;
int index = parent.IndexOf(preservedInline);
parent.RemoveAt(index);
parent.Insert(index, horizontalLine);
double ParseNumber(string value)
{
int unitIndex = value.Length - 2;
double number = double.Parse(value.Remove(unitIndex));
LengthUnit unit = value.Substring(unitIndex) switch
{
"pt" => LengthUnit.Point,
"px" => LengthUnit.Pixel,
"in" => LengthUnit.Inch,
_ => throw new NotImplementedException()
};
return LengthUnitConverter.Convert(number, unit, LengthUnit.Point);
}
}
document.Save("Output.pdf");
The issue with the new line appearing in the place of the column break is usually the expected behavior. However, in this document, it seems there is some sort of an exception.
Unfortunately, we were unable to find the reason why that is, the layout is very complex.
What’s worse is we noticed that nothing changes in the Word document even when we remove that column break (as if it’s being ignored completely).