Free Support Forum - aspose.com

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 {
        position:fixed;
        top:0;
        bottom:0;
        left:0;
        right:0;
        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

@cpiock

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)

@cpiock,

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?

@cpiock,

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

@cpiock,

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

printproblem.zip (77.7 KB)

@cpiock,

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

@cpiock,

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.