aspose.zip (71.8 KB)
We have attached 3 files, an rtf file which is the input and 2 pdf’s generated using this input, one is generated from ms word with save as pdf feature and other through aspose. The aspose pdf is highlighting the text that is drop down field options in rtf file, whereas ms word is not highlighting. We would like the aspose pdf to be similar to ms word pdf. Can you help us to disable the hightlighting?
Below is our code snippet:
com.aspose.words.PdfSaveOptions options = new com.aspose.words.PdfSaveOptions();
options.setPreserveFormFields(true);
options.setUpdateSdtContent(true);
options.setCustomPropertiesExport(PdfCustomPropertiesExport.STANDARD);
options.setExportDocumentStructure(true);
options.setSaveFormat(SaveFormat.PDF);
doc.save(outStream, options);
@ramachandra1988 In your code PreserveFormFields
option is enabled. In this case form fields are exported as PDF form fields and they are highlighted. If you need to get the result same as MS Word, you should disable this option.
Hi @alexey.noskov it did fix the highlighting issue but we still to need have spaces in the last line.Removing PreserveFormFields is also removing the space between the words as seen in attached file. Can you please help us with how to keep the space intact?aspose123.pdf (52.2 KB)
@ramachandra1988 As a workaround you can simply add spaces after empty dropdown form fields. For example see the following code:
Document doc = new Document("C:\\temp\\in.rtf");
Run fourSpacesRun = new Run(doc, ControlChar.NON_BREAKING_SPACE + ControlChar.NON_BREAKING_SPACE + ControlChar.NON_BREAKING_SPACE + ControlChar.NON_BREAKING_SPACE);
for (Field f : doc.getRange().getFields())
{
if (f.getType() == FieldType.FIELD_FORM_DROP_DOWN)
f.getEnd().getParentNode().insertAfter(fourSpacesRun.deepClone(true), f.getEnd());
}
com.aspose.words.PdfSaveOptions options = new com.aspose.words.PdfSaveOptions();
options.setCustomPropertiesExport(PdfCustomPropertiesExport.STANDARD);
options.setExportDocumentStructure(true);
options.setSaveFormat(SaveFormat.PDF);
doc.save("C:\\Temp\\out.docx");
doc.save("C:\\Temp\\out.pdf", options);