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
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.
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.