I have formatting issues with Aspose.pdf .NET. I have never had problems with margin, heights, bottom… until I upgraded from version 16.12.0.0 to 23.9.0. I use external CSS resources for formatting my PDF file. But at some point, my margin is not set correctly as it should be on the old version. The other CSS classes are recognized well. (only the @page) where I define the margin and height.‘I use HtmlLoadOptions(“with basepath to my css resource”)’
This is my c# code
var hlo = new HtmlLoadOptions(" url path of my css files"); // the basepath of my css class stored in the blobstorage
var doc = new Document(htmlStream, hlo);
and this is how i define my css class for the @page
@page {
margin-top: 20mm;
margin-right: 20mm;
margin-bottom: 20mm;
margin-left: 20mm;
}
@page :first {
margin-top: 10mm;
}
//In the old versions, was working with no issues.
@page {
margin-top: 20mm;
margin-right: 20mm;
margin-bottom: 20mm;
margin-left: 20mm;
}
@page :first {
margin-top: 10mm;
}
this is my css file
and this is the margin result what i get
MarginInfo=
{
Bottom:72,
Left:90,
Right:90,
Top:72
}
but this is not correct is should be points
@souf123
Thanks for the data provided.
I consulted with the development team and they explained to me that now
“there is a setting in the options, which by default means that the options take precedence over what is set via CSS, so if you specify margin values in HtmlLoadOptions, they will be applied. Even if they are not set, they are set in the library by default: Margin.Top = 72, Margin.Bottom = 72, Margin.Left = 90, Margin.Right = 90. This applies to the page”
Accordingly, I will create a task for the development team so that they can choose which settings to use: from options or from css (or solve this situation in some other way).
@souf123
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): PDFNET-56373
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
Thanks for your response.
So, the standard margin settings will always be filled in, even if I provide a CSS file? Is there then a possibility to ensure that the margins that come from the CSS (@page) should take precedence? Or will I have to provide a temporary workaround for this?"
“there is a setting in the options” which setting options?
@souf123
I hope the attached code with comments will make it clear to you.
var hlo = new HtmlLoadOptions(" url path of my css files"); // the basepath of my css class stored in the blobstorage
// You can try set desired values here
// hlo.PageInfo.Margin.Bottom = ...; also Margin.Left etc
var htmlStream = new MemoryStream();
// When you create doc with HtmlLoadOptions object: hlo - Margins gets from it (not from css file).
// Even if you did not set or touch them, the Margins values are taken from hlo.PageInfo.Margin... (they will just be set by default).
var doc = new Document(htmlStream, hlo);
how do i set specific the margin top of the first page?
var hlo = new HtmlLoadOptions();
hlo.PageInfo.Margin.Bottom = your_Bottom_Margin;
hlo.PageInfo.Margin.Top = your_Top_Margin;
hlo.PageInfo.Margin.Left = your_Left_Margin;
hlo.PageInfo.Margin.Right = your_Right_Margin;
var doc = new Document(new MemoryStream(), hlo);
The other pages should be different from the first.
this is for all the page i think?
the margin top of the first page should be different of the others, is there a way to set different margins settings for different pages?
@souf123
Not now.
In version 24.02, improvements are planned and it will be possible to use margins specified in css.
Great, indeed that would be the best solution for me to extract the settings and formatting from the CSS. Do you know when a new version will be available?
oke thank you, i will wait