Hi,
When converting a DOCX file to PDF using Aspose.Words, I noticed extra text appears at page 2.
Code:
var doc = new Document(@".\test.docx");
doc.LayoutOptions.TextShaperFactory = HarfBuzzTextShaperFactory.Instance;
doc.Save(@".\out.pdf");
After checking the Word document, the text seems to come from an out of boundary textbox from the footer, but it is not supposed to be visible in Word or PDF.
I’ve attached the test files and screenshot for your reference. Could you please help to take a look?
test.zip (1.3 MB)
Thanks,
@ServerSide527
Cause
The issue of extra text appearing when converting a DOCX file to PDF is often related to out-of-bound text boxes or other elements in the document that may not be visible in Word but still affect the layout during conversion. In your case, it seems to stem from a text box in the footer.
Solution
To resolve this issue, please follow these steps:
-
Check Text Box Properties: Ensure that the text box in the footer is properly configured. It may be set to display in a way that causes it to appear in the PDF output.
-
Adjust Layout Options: Modify the layout options when saving the document to PDF. Specifically, set the TextShaperFactory
to a different value or adjust the PdfSaveOptions
.
-
Update Fields: If your document contains fields (like page numbers or references), ensure they are updated before saving. This can help eliminate any discrepancies.
Code
Here’s a code snippet that demonstrates how to set the PdfSaveOptions
and update fields before saving:
var doc = new Document(@".\test.docx");
// Update fields in the document
doc.UpdateFields();
// Create PdfSaveOptions
PdfSaveOptions options = new PdfSaveOptions();
options.TextCompression = PdfTextCompression.Flate; // Adjust compression if needed
// Save the document to PDF
doc.Save(@".\out.pdf", options);
Next Steps
- Review the footer and text box settings in your DOCX file to ensure they are not causing layout issues.
- Test the provided code snippet to see if it resolves the extra text issue during conversion.
- If the problem persists, consider simplifying the document structure or removing any unnecessary elements.
Please implement these steps and let me know if you need further assistance!
@ServerSide527
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): WORDSNET-28372
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.