Free Support Forum -

Customize size issue while generating PDF from HTML (C#)

I create a pdf from a complex html structure. I have added in my html these styles to have only a size of A4

 <style type="text/css">
      html, body {
        width: 210mm;
        min-height: 297mm;
      body {                  
            padding: 0;
            margin: 0;
      .subpage {                        
        height: 257mm;

I also use this code to generate pdf from html
using (HTMLDocument htmlDocument = new HTMLDocument(innerDocHtml, “”))
using (MemoryStreamProvider streamProvider = new MemoryStreamProvider())
Aspose.Html.Saving.PdfSaveOptions saveOptions = new Aspose.Html.Saving.PdfSaveOptions
PageSetup = {
AnyPage = new Aspose.Html.Drawing.Page
Margin = new Margin(40, 40, 40, 40),
Size = new Size(Length.FromCentimeters(21), Length.FromCentimeters(29.7))
AtPagePriority = AtPagePriority.CssPriority,
AdjustToWidestPage = false,
Aspose.Html.Converters.Converter.ConvertHTML(htmlDocument, saveOptions, streamProvider);
return streamProvider.Streams[0].ToArray();

Why it ignore my size configs and always i have a pdf with 11,6 x 16,5 in instead of 8,27X11,69.
Thanks for help


Would you kindly share the output PDF document that have been obtained at your side using shared code snippet. We will further proceed to assist you accordingly.

If you open it with Acrobat Reader and in the Print Dialog you choose Actual Size you will see that it is not a A4. But on CSS Site i have configured that it is a A4 and also if I take a look to the generated html everything is fine

Fattura Uscita Tizio Caio per Pinco Palo Nr. ACCETTATA E DA CONSERVARE del 29.06.2019 (53).pdf (34.8 KB)


Can you please share which version of Aspose.HTML you are using on your end along with complete environment details.

We are using version 19.11.0 of Aspose HTML. What kind of data did you need from my environment?


Please share which OS you are using on your end.

Windows 10 but also on our web application servers with windows we have the same problems


We have tried to reproduce problem on our end and everything is working fine. Can you please share your HTML file which you used to generate PDF.

Hi @Adnan.Ahmad here is my html example. Sorry for the delay (77.7 KB)


We are looking into this and will get back to you with feedback soon.

Hi @Adnan.Ahmad did you have any feedback for me? Thanks Christoph


Thanks for contacting support.

We have tested this scenario in our environment and have been able to observe the issue that you have mentioned. We have logged issue with ID HTMLNET-2346 in our issue tracking system. We will share with you as soon as logged issue is fixed.

@Adnan.Ahmad changed to the latest aspose version but nothing changed


I like to inform that we have investigated this issue on our end and want to share our findings with you. Can you please check style sheet in your document and that contains page size definition.


And because of following option:

AtPagePriority = AtPagePriority.CssPriority

it takes priority over page size defined in PdfSaveOptions. To receive desired behavior you should change this options value to:

AtPagePriority = AtPagePriority.OptionsPriority

Please share feedback with us if there is still an issue.

@Adnan.Ahmad yes i’am using in my css
@page {
size: A4;
box-shadow: 0;
But also changed to optionspriority doesn’t solve the problem.