In the original document SISMS-06-01-SFP-FORM-006320.docx (107.7 KB), row 54 appears on page 9. However, after converting the document to PDF using Aspose version 25.6, row 54 is shifted to page 8 in the output file SISMS-06-01-SFP-FORM-006320.pdf (94.7 KB).
please find the comparison screenshots,
Pdf output:
The issue you’re experiencing, where a specific row in your document shifts to a different page after converting from DOCX to PDF, can occur due to differences in how Microsoft Word and Aspose.Words handle layout and pagination. Factors such as page size, margins, and content flow can affect the positioning of elements in the document.
Solution
To address this, you can adjust the layout options when saving the document to PDF. Specifically, you can use the PdfSaveOptions class to control various rendering settings that may influence the output.
Code
Here’s a sample code snippet that demonstrates how to set up PdfSaveOptions for better control over the PDF rendering:
import com.aspose.words.Document;
import com.aspose.words.PdfSaveOptions;
public class DocxToPdf {
public static void main(String[] args) throws Exception {
// Load the document
Document doc = new Document("path/to/your/document.docx");
// Create PdfSaveOptions
PdfSaveOptions options = new PdfSaveOptions();
options.setCompliance(PdfCompliance.PDF_17); // Set PDF compliance
options.setExportDocumentStructure(true); // Export document structure
options.setPreserveFormFields(true); // Preserve form fields if any
// Save the document as PDF
doc.save("path/to/output/document.pdf", options);
}
}
Next Steps
Test the above code to see if it resolves the pagination issue.
If the problem persists, review the document’s formatting in Word to ensure there are no hidden elements or formatting that could affect layout.
Experiment with different PDF compliance settings or layout options in PdfSaveOptions to see if they yield better results.
Please implement these steps and let me know if you need further assistance!
@rnaraDM Sans font used in your original document is not available on my side. Could you please provide this font here for testing? Also, please save the original document as PDF using MS Word on your side and attach the resulting PDF document here for our reference.
@rnara Thank you for additional information. As I can see PDF produce on my side looks the same as PDF produced by MS Word on your side. Here is the output document produced on my side: out.pdf (115.3 KB)
I used the following simple code for testing:
// 'C:\Temp\fonts' folder contains additional fonts.
FontSettings.getDefaultInstance().setFontsSources(new FontSourceBase[]{new SystemFontSource(), new FolderFontSource("C:\\Temp\\fonts", true)});
Document doc = new Document("C:\\Temp\\in.docx");
doc.setWarningCallback(new FontSubstitutionWarningCollector());
doc.save("C:\\Temp\\out.pdf");