Landscape pages are rendered as portrait pages when converting DOCX to PDF

Hi,

When converting a DOCX with some portrait and landscape pages to PDF using Aspose.Words, the pages in the PDF all became portrait.

Code:

        var doc = new Document(@".\test.docx");
        doc.Save(@".\out.pdf");

I’ve attached the test files and a screenshot for your reference. Could you please help to check?

test.zip (176.0 KB)

Thanks,

@ServerSide527

Cause

The issue you’re experiencing, where landscape pages in a DOCX document are rendered as portrait pages in the resulting PDF, is often due to the page setup settings not being correctly applied during the conversion process.

Solution

To ensure that both portrait and landscape pages are preserved during the conversion from DOCX to PDF, you can explicitly set the page setup for each section in your document. This includes specifying the orientation for each section before saving the document.

Code

Here’s a code snippet that demonstrates how to set the page orientation for each section:

var doc = new Document(@".\test.docx");

// Loop through each section in the document
foreach (Section section in doc.Sections)
{
    // Check if the section is set to landscape
    if (section.PageSetup.Orientation == Orientation.LANDSCAPE)
    {
        // Ensure the section is correctly set to landscape
        section.PageSetup.Orientation = Orientation.LANDSCAPE;
    }
    else
    {
        // Ensure the section is set to portrait
        section.PageSetup.Orientation = Orientation.PORTRAIT;
    }
}

// Save the document as PDF
doc.Save(@".\out.pdf");

Next Steps

  1. Ensure that your DOCX document has the correct page setup for each section.
  2. Use the provided code to loop through the sections and explicitly set the orientation.
  3. Test the conversion again to confirm that the landscape pages are now rendered correctly in the PDF.

If you have any further questions or need additional assistance, please let me know!

@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-28448

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.

The issues you have found earlier (filed as WORDSNET-28448) have been fixed in this Aspose.Words for .NET 25.8 update also available on NuGet.