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.

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

@cpiock,

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.

@page{size:a3}

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.

@cpiock,

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

did you have maybe any news for me

@cpiock,

We have converted the HTML file, provided by you (testaspose.html), to PDF (out.pdf), using Aspose.HTML 20.3.0 and the following code snippet:

using (HTMLDocument htmlDocument = new HTMLDocument(File.ReadAllText(“testaspose.html”), “”))
{
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.OptionsPriority,
AdjustToWidestPage = false,
}
};
Aspose.Html.Converters.Converter.ConvertHTML(htmlDocument, saveOptions, “out.pdf”);
}

The resulting PDF page size is exactly 210mm/297mm. Could you please clarify, how you are receiving wrong page size?out.pdf (55.7 KB)

yes but you see that now the page is not complete at the right side. There is missing a part.

@cpiock.

Thanks for sharing information with us.