Setting page margins on html loaded into Document

Hi I’m trying load html from an Oracle Database into a document that will be saved as a pdf later.

I do this using

LoadOptions options = new LoadOptions();
options.setLoadFormat(LoadFormat.HTML);
try {
   newDocument = new Document(dataStream, options);

then later on i have

formatDocConst = com.aspose.words.SaveFormat.PDF;
newDocument.save(outputStream, formatDocConst);

this is all working fine except the margins around the page are too large. Is there a way of setting the margins on the document once it has been loaded into the document?

Thanks
Anthony.

Hi Anthony,

Thanks for your inquiry. Could you please save your Html stream to disk and then attach this input Html file, you’re getting this problem with, here for testing? I will investigate the issue on my side and provide you more information.

Best regards,

Hi Awais,
the attached is a very simple html page. When I convert this it creates a pdf where the top margin of the page is 4cm and the left and right margins are 3.5 cm. This also happens with plain text files.
for plain text files I just use newDocument = new Document(dataStream); where the datastream is the text file from the db. When I do this with a word document the margin settings are preserved from the word document. I presume because html and .txt files do not contain any information about margins etc Aspose is setting this to some default value. So I think the question is can I set these margins within my java? Is this the best way to convert html and text files to pdf?
Thanks
Anthony

Hi Anthony,

Thanks for your inquiry.

Please note that Aspose.Words’ page layout engine tries to mimic the way the Microsoft Word’s page layout engine works. To you, this means that if you convert a Html document into PDF using Aspose.Words, the output will appear almost exactly as if it was done by Microsoft Word.

Secondly, please check the PageSetup class that contains all the page setup attributes of a section (left margin, bottom margin, paper size, and so on) as properties. For example the Document.FirstSection.PageSetup.LeftMargin returns or sets the distance (in double points) between the left edge of the page and the left boundary of the body in document. Please let me know if I can be of any further assistance.

Best regards,

Hi Awais,
Setting the margins works for me thank you. A futher question though I have attached another simple html page and it’s output after conversion to to pdf. You can see the first column is wrapping per word. I have tried various settings on the TH tag to set the width etc but nothing seems to work. I would like the TH not to wrap but the TD to wrap.
Thanks
Anthony

Hi Awais,
I got it working by using width=“30%”
Thanks for your help
Anthony

Hi Anthony,

Thanks for your inquiry. Alternatively, you can also call UpdateTableLayout method before exporting to PDF (or any other fixed-page format), only in rare cases where you confirmed that tables appear incorrectly laid out in the output document. I hope, calling this method will help to correct the PDF output. If we can help you with anything else, please feel free to ask.

Best regards,

Hi Awais
Thanks again using UpdateTableLayout solved another problem I was having where the table was not spanning the width of the page.
Anthony

Hi Anthony,

Please let us know any time you have any further queries. We’re always glad to help you.

Best regards,