Top margin of first page of pdf generated with aspose.words

Hi,

We are in the process of evaluating aspose as PDF converter for one of our esteemed client, and working with POCs as of now.

I have observed that the top margin is not customizable for the first page of the pdf generated with aspose.words for java.

Wanted to confirm, if its happening only with trial version of aspose.

Please find the attached files for the reference. If we observe .png file, the top margin of the first page of my pdf is huge, I tried setting it with
builder.getPageSetup().setTopMargin(90);

but still it shows some default margin. below is the sample code which am using to genreate the pdf.

InputStream is =
new ByteArrayInputStream(mergedHtml.getBytes(“UTF-8”));
com.aspose.words.Document doc = new com.aspose.words.Document(is);
com.aspose.words.DocumentBuilder builder = new com.aspose.words.DocumentBuilder(doc);

builder.getPageSetup().setTopMargin(90);

builder.getPageSetup().setBottomMargin(190);
//lastly save the document
builder.getDocument().save(“c:\pdffiles\MyPdfWords_File.pdf”);

Please advice me as how can we avoid this.

Thanks in advance!

-Shivaji

Hi Shivaji,

Thanks for your inquiry. Could you please attach your input Word document here for testing? I will investigate the issue on my side and provide you more information.

Hi,

I am using html to pdf conversion. not word to pdf.

Pls let me know if you need html also.

Thanks,

Hi Shivaji,

Thanks for your inquiry.
Yes, please share the input html document for investigation purposes.

Hi,

Please find the attached html which I am using as input for the pdf generation using Aspose.

Thanks,
Shivaji

Hi Shivaji,

Thanks for sharing the detail. Please note that Aspose.Words mimics the same behavior as MS Word does. If you load the html document in MS Word and convert it to Pdf, you will get the same output.

I have tested the scenario using latest version of Aspose.Words for Java 15.7.0 and have not found the shared issue. Please use Aspose.Words for Java 15.7.0. Please set the top and bottom margins of first section using following code example. I have attached the output document with this post for your kind reference.

Document doc = new Document(MyDir + "input.html");

doc.getFirstSection().getPageSetup().setTopMargin(10);

doc.getFirstSection().getPageSetup().setBottomMargin(10);

doc.save(*MyDir* + "Out.pdf");

Hi,

Thank you for the information provide, its working as expected.

Will let you know if any issues I face further.

Thanks,
Shivaji

Hi Shivaji,

Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.