Convert HTML to Single Page PDF using Aspose.PDF for .NET - Html A4 page converts to 2 pdf pages

Hi, we have used Apsose.Ppd.Generator earlier but then we changed to DOM the following html file suddenly konverts to 2 pages. I had to change page height to 27 cm to fit it into one page.
Can you try this and see if you can recreate the error?
I have added the original html page and also the workaround that I had to (40.5 KB)

Best Regards
Per Rodstrom


Thanks for your query with sample HTML files.

Please elaborate with sample code (if possible), which Aspose API you are using? Are you using Aspose.PDF?
After getting details, we will be able to help you appropriately.

Hi, here is a sample code. We are using Aspose.pdf 18.8 in C# (41.7 KB)
Best Regards
Per Rodstrom


We have worked with the data shared by you but the PDF file is not generated fine, also the definition of method GetImageCompressingFactor() is not present in the code. Please share a sample application reproducing this issue along with respective PDF files which are generated in your environment so that we may proceed further to help you out.

Here is an example project that shows the error.
Best Regards
Per Rodstrom

hmm the file did not attach …trying again

Something is wrong the file does not attach. It is an 18Mbyte zip file.

Can I email or ftp the file?


Please note that upload limit on forums is 3MB so you can always share bigger data via Google Drive, Dropbox etc. so that we may proceed further to help you out.

OK here is the zip file.


Thank you for sharing requested resources.

You can convert HTML file to a PDF document while specifying page dimensions in HtmlLoadOptions and generated PDF contains single page. Please try using below code snippet in your environment and then share your kind feedback with us.

Aspose.Pdf.HtmlLoadOptions objLoadOptions = new Aspose.Pdf.HtmlLoadOptions();
objLoadOptions.PageInfo.Margin.Bottom = 0;
objLoadOptions.PageInfo.Margin.Top = 0;
objLoadOptions.PageInfo.Margin.Right = 0;
objLoadOptions.PageInfo.Margin.Left = 0;
objLoadOptions.PageInfo.Width = 595.27584; // 21cm to points
objLoadOptions.PageInfo.Height = 841.88952; // 29.7cm to points
Aspose.Pdf.Document doc = new Aspose.Pdf.Document(dataDir + "htmlGebyrInbetalning3.html", objLoadOptions);
doc.Save(dataDir + "Long_Table_HTML.pdf");

Generated PDF file has been attached for your kind reference Table_HTML.pdf. Please also note that basic measuring unit in Aspose.PDF for .NET is point, where 1 inch = 72 points and 1 cm = 1/2.54 inch = 0.3937 inch = 28.3 points.

We hope this will be helpful. Please feel free to contact us if you need any further assistance.

I doesn´t work for me and also we dont want to hardcode the page to one pdf page outside the html.
Actually the html code is setting up the page size and the pdf should follow the html code.
The html should be able to fit inside one pdf page.
This used to work with apsose.generator. I have added the modified code and the result in the public google drive folder that we are using on this case.
Best Regards
Per Rodstrom
htmlGebyrInbetalning3.html.pdf (128 KB)


Thank you for sharing your feedback.

We have logged an investigation ticket with ID PDFNET-45480 has been logged in our issue management system for further investigation and resolution. The ticket ID has been linked with this thread so that you will receive notification as soon as the ticket is resolved.

We are sorry for the inconvenience.


Aspose.PDF for .NET now offers the feature to convert HTML to Single Page PDF document using IsRenderToSinglePage property of HtmlLoadOptions Class. You may please try using following code snippet:

HTML to PDF - Render all contents in single page

string outFile = "out.pdf";
HtmlLoadOptions options = new HtmlLoadOptions();
options.IsRenderToSinglePage = true;
Document doc = new Document("HTML/input.htm", options);