We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

PageSetup does not retain the Page orientation

Hi Team,

We have an issue in setting orientation to the pages in word document when converting to PDF.

A sample word document which has one page in portrait and one page in Landscape is attached. To convert to PDF if we use below code, the PageSetup.setOrientation accepts either Orientation.Landscape or Orientation.Portrait.

There is no option to retain the orientation from the original source document.

SectionCollection sections = doc.getSections();

for(int i = 1; i < sections.getCount(); i++)
{
PageSetup pageSetup = sections.get(i).getPageSetup();
pageSetup.setOrientation(pageSettings.orientation);
pageSetup.setLeftMargin(ConvertUtil.inchToPoint(pageSettings.marginLeft));
pageSetup.setRightMargin(ConvertUtil.inchToPoint(pageSettings.marginRight));
pageSetup.setBottomMargin(ConvertUtil.inchToPoint(pageSettings.marginBottom));
pageSetup.setTopMargin(ConvertUtil.inchToPoint(pageSettings.marginTop));

}

But in above code, if we do not use pageSetup.setOrientation() at all(comment out that line obove), then the output PDF has the retained orientation of source document.

Is there any plan to provide an option to retain the orientation in Orientation class in future? Or is it available now in some other API?

We cannot opt to not use pageSetup.setOrientation() as there are lot of documents with different orientation requirements.

Thanks,

Satyendra

Hi,

Any updates on this please?

Thanks,

Satyendra

Hi Satyendra,


Thanks for your inquiry. Please note that Aspose.Words mimics the same behavior as MS Word do. The PageLayout orientation is either Orientation.Landscape or Orientation.Portrait. If you want to retain the page orientation in output document, please do not call PageSetup.setOrientation method.

Could you please share some more detail about your query what exact you want to achieve by using Aspose.Words? We will then provide you more information on this along with code.

Hi,

We see data/image overlaps in attached word document.

NOT WORKING:

The overlap happens if we use the pageSetup.setPaperSize(PaperSize.A4) in combination with pageSetup.setOrientation(Orientation.LANDSCAPE).

WORKING:

We dont see this issue if the pageSetup.setPaperSize(PaperSize.LETTER) is used

Can you please test from your side and lets us know if there is any workaround or confirm this as a bug in Aspose.Words. Let me know if you need anymore details.

Thanks,

Satyendra

Hi Satyendra,


Thanks for sharing the detail. Perhaps, you are using an older version of Aspose.Words; as with Aspose.Words v13.7.0, I am unable to reproduce this problem on my side. I would suggest you please upgrade to the latest version of Aspose.Words i.e. v13.7.0 and let us know how it goes on your side. I hope, this will help.

I have tested the scenario with following code snippet and have attached the output Pdf file with this post for your kind reference.

Document doc = new
Document(MyDir + “D4507101048+(2).doc”);<o:p></o:p>

for (Section section : (Iterable<Section>) doc.getSections())

{

PageSetup pageSetup = section.getPageSetup();

pageSetup.setOrientation(Orientation.LANDSCAPE);

pageSetup.setPaperSize (PaperSize.A4);

}

doc.save(MyDir + "OutJava.pdf");


Hi,

Thank you for your prompt response. I am using Aspose.words 13.7.0.

Looking at your output PDF, i investigated more on this and found out that setting margins is causing this issue (Which is strange and not acceptable as customer can choose to add any margins and overlapping should not happen)

Please set margins - MARGINBOTTOM="0.5" MARGINLEFT="0.5" MARGINRIGHT="0.5" MARGINTOP="0.5" in your code and we see the overlap issue occuring.

pageSetup.setLeftMargin(ConvertUtil.inchToPoint(pageSettings.marginLeft));
pageSetup.setRightMargin(ConvertUtil.inchToPoint(pageSettings.marginRight));
pageSetup.setBottomMargin(ConvertUtil.inchToPoint(pageSettings.marginBottom));
pageSetup.setTopMargin(ConvertUtil.inchToPoint(pageSettings.marginTop));

Please let me know your observations.

Thanks,

Satyendra

Hi,

Any updates regarding this please?

Thanks,

Satyendra

Hi Satyendra,

Thanks for your inquiry. I have managed to reproduce the same issue at my side. I have logged this issue as WORDSNET-8821 in our issue tracking system. I have linked this forum thread to the same issue and you will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

Hi Satyendra,

It is to inform you that the undesired behavior you're observing is actually not a bug in Aspose.Words. So, we have closed this issue as 'Not a Bug'.

Please note that Aspose.Words mimics the same behavior as MS Word do. If you set the Left, Right, Top and Bottom margin by using MS Word, you will get the same output. Please open your input document in MS Word and set the margin to .5 for whole document. MS Word shows the same behavior. Please see the attached image for detail. I have attached the modified input MS Word document with this post for your kind reference.