I'm trying to convert a .docx with some text place holder document to .pdf but the checkbox element gets lost in the process.
I'm using FreeSpire.Doc 7.11.0 and using these lines of code:
- Code: Select all
if (splitPlaceHolder[0] == "cb")
{
_logger.LogInformation( $"{nameof(DocumentGeneratorService)} - process for check box");
var bolCheck = !string.IsNullOrEmpty(templateContentKeyValue.Value) && System.Convert.ToBoolean(templateContentKeyValue.Value);
var selections = document.FindAllString(key, true, true);
if (selections == null) continue;
foreach (var selection in selections)
{
_logger.LogInformation( $"{nameof(DocumentGeneratorService)} - process for check box of {templateContentKeyValue.Key} with value {bolCheck}");
var sdt = new StructureDocumentTagInline(document)
{
CharacterFormat = {FontSize = sizeCheckBox, TextColor = Color.FromArgb(argb)}
};
var range = selection.GetAsOneRange();
var index = range.OwnerParagraph.ChildObjects.IndexOf(range);
range.OwnerParagraph.ChildObjects.Insert(index, sdt);
sdt.SDTProperties.SDTType = SdtType.CheckBox;
var scb = new SdtCheckBox();
sdt.SDTProperties.ControlProperties = scb;
var tr = new TextRange(document)
{
CharacterFormat =
{
FontName = "MS Gothic",
FontSize = sizeCheckBox,
TextColor = Color.FromArgb(argb)
}
};
sdt.ChildObjects.Add(tr);
scb.Checked = bolCheck;
sdt.SDTProperties.Alias = "CheckoBox";
sdt.SDTProperties.Tag = "Checkbox";
range.OwnerParagraph.ChildObjects.Remove(range);
}
}
else
document.Replace(key, safeValue, true, true);
//////////////////////////////////////
document.SaveToStream(outStream, FileFormat.PDF);
And we run local this code work well with the attached image
, but when deploying azure, this function does not display the correct checkbox.
Many thanks for any assistance that can help resolve this issue.