Content is shifted after rendering to PDF

Hi @alexey.noskov … in addition to above provided solution, is any more specific code change required to take care of font sizes/height/width … upon upgrading the Aspose library from 15.11 to latest version 25.1?
I am getting following output upon upgrade and adding above changes.
Please let me know if you want any more details from me.

@rootforms Could you please attach your input and output documents here for our reference? We will check the issue and provide you more information.

Thanks for responding, @alexey.noskov !
Here are the input template, Older output as reference point, and the current output.

Thanks!

Input_template.docx (29.3 KB)

Output With Aspose 25.1.pdf (358.2 KB)

Output With Older Aspose.pdf (402.0 KB)

@rootforms Could you please save the output document as DOCX and attach it here or provide code that you use to fill the template with data? Simple conversion to PDF does not allow to reproduce the problem:
out.pdf (65.2 KB)

Most likely the problem occurs because size of the generated barcode differs.

@alexey.noskov , as I am extracting the code for you, in the meanwhile could you please confirm if there is a need to upgrade Barcode library as well alongwith Aspose Words library upgrade? (anything you are aware of from the usage point of view).

public void executeMailMerge ( String outputDocumentName ) throws Exception {
	try {
		doc = new Document ( FileUtil.DIRECTORY_SOURCEDATA + param.getWorkingFolder() + templateFile ) ;
			
		// Remove those pesky macros - if any added
		if ( doc.hasMacros()) {
			doc.removeMacros(); 
		}
		merge = doc.getMailMerge() ;
		merge.setUnconditionalMergeFieldsAndRegions(true);

		// Reading the data from xml file for the mail merge
		DataSet dataSet = new DataSet() ;
		dataSet.readXml( xmlFilepath ) ;

		int cleanupOptions = MailMergeCleanupOptions.REMOVE_UNUSED_REGIONS |
			    MailMergeCleanupOptions.REMOVE_EMPTY_PARAGRAPHS;

		merge.setCleanupOptions(MailMergeCleanupOptions.REMOVE_CONTAINING_FIELDS); 
		merge.executeWithRegions(dataSet);
			
		// merge the header fields
		DataTableCollection tables = dataSet.getTables() ;
		if (tables != null && tables.getCount() > 0) {
			merge.execute( tables.get("PrintForm") );
		}
		cleanupOptions |= MailMergeCleanupOptions.REMOVE_CONTAINING_FIELDS;
		cleanupOptions |= MailMergeCleanupOptions.REMOVE_UNUSED_FIELDS;
		cleanupOptions |= MailMergeCleanupOptions.REMOVE_EMPTY_TABLES;
		merge.setCleanupOptions(cleanupOptions);
			
		doc.getFieldOptions().setBarcodeGenerator(new BarcodeGenerator());

		// Required with upgraded jar
		doc.setFontSettings(new FontSettings()); 
		doc.getFontSettings().setFontsSources(new FontSourceBase[] { new FolderFontSource(".fonts/", true)});
		doc.setWarningCallback(new FontSubstitutionWarningCollector());
			
		//Image compression issue is solved with this. If any impact on KDOCS, comment this impl. 
		com.aspose.words.PdfSaveOptions saveOption = new com.aspose.words.PdfSaveOptions();
		com.aspose.words.DownsampleOptions downSampleOption = new DownsampleOptions();
		downSampleOption.setDownsampleImages(false);			
		saveOption.setDownsampleOptions(downSampleOption);		
		//END

		doc.getMailMerge().deleteFields(); // upgrade impact. hence required
		doc.updateFields(); 
		//Saving document as pdf

		doc.save(FileUtil.DIRECTORY_SOURCEDATA + param.getWorkingFolder() + outputDocumentName,saveOption) ;
	}
	catch ( Exception e) {
		System.out.println( e.getMessage());
		e.printStackTrace();
		throw new MergeException("There was an error printing the document!");
	}
}

@rootforms Thank you for additional information. But you do not provided data using for executing mail merge. It would be easier to save the output as DOCX and attach it here, so we can convert this document to PDF on our side to check the rendering.

<PrintForm>
<Case_Quantity>12.000000</Case_Quantity>
<Item_Name>P8S1-220-220</Item_Name>
<Work_Order_Number>WO-0000675158</Work_Order_Number>
<Putaway>Specials</Putaway>
<WO_Quantity>1.0</WO_Quantity>
<Case_Barcode>01P8S1-220-22001200100675158</Case_Barcode>
<Case_Nbr>001</Case_Nbr>
<SO>SO-0000509995</SO>
<DESC3>8</DESC3>
<DESC1>MULTI-PLEAT XL</DESC1>
<DESC2>22x22x1</DESC2>
</PrintForm>

@alexey.noskov , hope this helps.

@rootforms Could you please also provide your implementation of IBarcodeGenerator? I tested with the implementation provided in our documentation, but size of barcodes is incorrect and content is wrapped improperly.

barcode-Impl.docx (18.1 KB)

@alexey.noskov , here is the implementation you are looking for. Thanks for staying on course!

@rootforms Thank you for additional information. unfortunately, the class is not compliable on my side. but as I suspected the problem is in size of the generated barcode. By the way if correct the display barcode field code and save the generated document to PDF using MS Word, you will see the same problem as in the latest version of Aspose.Words. So it looks like new Aspose.Words behavior is correct.
out.docx (20.8 KB)
ms.pdf (69.8 KB)

So to resolve the problem you should either modify your template or adjust the generated barcode size in your implementation of IBarcodeGenerator.

Thank you @alexey.noskov, for sharing your analysis!

As suggested by you, I have been trying to adjust the size of the generated barcode, in order to get the coveted output.
However, I am not yet able to render the side-by-side output (like the older Aspose output) with the as-is template, by mere resizing the barcode.

Without altering the size of the other fields in template, the side-by-side rendering is not possible with the latest Aspose Words. (you may have noticed the same in above provided ms.pdf)
And this is the last thing we want to tell our customers while we ask them to take the upgrade.

Could you please confirm if you see the side-by-side output by pointing to Aspose Words 15.11 with your test code? This will help us assess that whatever you see with prior and latest versions are in sync with ours.

Thanks!

@rootforms The development goal of the Aspose.Words Document Layout Engine is to make it as close to MS Word as possible, rather than maintaining the same rendering results as older versions of Aspose.Words. This means that differences in document layout may occur between older and newer versions due to continuous improvements in the layout engine.

You’re comparing versions 15.11 and 25.1 of Aspose.Words, which represent about 10 years of development. The output produced by the newer version is closer to the results in MS Word. It’s likely that the older version had a bug or a missing feature that, by coincidence, produced the rendering result you expected.

The only way I can suggest to achieve the desired result with the new version of Aspose.Words is to refactor your template.

Thanks @alexey.noskov for providing the insights into the Aspose upgrades and the clarity on what to expect!

1 Like