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

@Adnan.Ahmad did you have maybe any news for me? thanks

@cpiock,

I like to inform that we have investigated this issue and like to share our findings with you.The attached document contains such style declaration

body {
max-width: 1000px;
width: 1000px;
margin-top: 0px;
padding-top: 0;
}

The width of the body element is set to 1000px, which is near 265mm, so the content of the attached document is wider than A4.
I have attached the screenshot (print.zip) of print preview received using Mozilla Firefox, as you can see the content is clipped. You said that you have made some modifications of the document styles, this may be the reason we receive different results. Can you please share the modified document with us.

print.zip (39.0 KB)

as i write below even if i change the css to a4 it doens’t change see here my sample
The PDF size is always to big
Thanks for your help an patience :slight_smile:

testaspose.zip (94.3 KB)

@cpiock,

Thanks for sharing file with us. We are looking into this.

@Adnan.Ahmad did you have any news for me?

@cpiock,

We are working on this and will get back to you with feedback soon.

@Adnan.Ahmad did you have any news for me?

@cpiock,

We have investigated the last provided document, it contains such style:

@media print {
.container, body {
min-width: 992px!important;
}
}
By default we are using “print” media, that’s why the content size is still wider than A4, media type can be changed using options:

saveOptions.Css.MediaType = Aspose.Html.Rendering.MediaType.Screen;
Also, this document contains such style:

html, body {
width: 210mm;
min-height: 297mm;
}
I
f you specifies page width equal to 210mm and margins equal to 40px the available content width will be 210mm - 40px - 40px = 188.8mm, which may lead to content clipping.
we have converted the attached document using these options, the resulting page size is A4 and no content is clipped:

using (Aspose.Html.HTMLDocument htmlDocument = new Aspose.Html.HTMLDocument(System.IO.File.ReadAllText(“testaspose.html”), “”))
{
Aspose.Html.Saving.PdfSaveOptions saveOptions = new Aspose.Html.Saving.PdfSaveOptions
{
PageSetup =
{
AnyPage = new Aspose.Html.Drawing.Page
{
Size = new Aspose.Html.Drawing.Size(Aspose.Html.Drawing.Length.FromCentimeters(21), Aspose.Html.Drawing.Length.FromCentimeters(29.7))
},
AtPagePriority = Aspose.Html.Rendering.AtPagePriority.OptionsPriority,
AdjustToWidestPage = false,
},
Css = {MediaType = Aspose.Html.Rendering.MediaType.Screen}
};
Aspose.Html.Converters.Converter.ConvertHTML(htmlDocument, saveOptions, “out.pdf”);
}