We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Speciy Margins of PDF Page while generating PDF document in C# .NET

Hello,

I need some help with my footer. I wanted to have a footer with no space between it and the bottom of my page but even with no margin there's still space. Heres' my code :

var doc = new Pdf();
(new Aspose.Pdf.License()).SetLicense("Aspose.Total.lic");


//création footer
var footer = new HeaderFooter { Margin = new MarginInfo { Top = 10 } };
var table = new Table();
var row = new Row(table);
var cellEmpty = row.Cells.Add();
cellEmpty.FitWidth =200;
var cell = row.Cells.Add();
cell.Padding = new MarginInfo { Left = 5, Right = 5, Bottom = 10, Top = 5 };
cell.VerticalAlignment = VerticalAlignmentType.Bottom;
cell.BackgroundColor = new Color
{
ColorSpaceType = ColorSpaceType.Rgb,
RgbColorSpace = System.Drawing.Color.Black
};

var colTxtFooter = new Color
{
ColorSpaceType = ColorSpaceType.Rgb,
RgbColorSpace = System.Drawing.Color.White
};
var text = new Text("Blablabla") { TextInfo = new TextInfo { Color = colTxtFooter } };
cell.Paragraphs.Add(text);
table.Rows.Add(row);
table.SetColumnWidth(1, table.GetMaxColumnWidth(doc, 1));
footer.Paragraphs.Add(table);

var section = new Section
{
PageInfo =
{
PageHeight = 794,
Margin = new MarginInfo{Bottom = 0,Top=0,Left=0,Right=0}
},
EvenFooter = footer,
OddFooter = footer
};
section.Paragraphs.Add(new Text("testing"));
doc.Sections.Add(section);

const string file = @"D:/AsposeSampleFooter.pdf";
doc.Save(file);
(new System.Diagnostics.Process { StartInfo = { FileName = file } }).Start();

Can you help me, please?

Thanks in advance

Hi Anouk,

Thank you for the sample code. I tried using your code to test your issue. You can remove space by changing bottom property with -ve value as mentioned in below code.

//création footer
var footer = new HeaderFooter { Margin = new MarginInfo { Top = 10, Bottom = -20 } };

Please do let us know if you need any further assistance.

Thanks & Regards,

Thanks for the help. It works. I just wonder why I have to use this negative margin, please. Is it because there is a margin at te page even if I specify that I wanted a bottom margin at 0 in my section.PageInfo properties?

Hi Anouk,

The Footer is bit higher from the page bottom because the MarginInfo for the table cell placed inside this Footer has Bottom margin as 10. Even though if you update it to 0, still the Footer is not close to the bottom of page, just like the text string "testing" which is added as a normal paragraph in PDF section. I think it has something to do with the code and it needs to be fixed by product development team.

Hi Anouk,

I have tested the scenario and I am able to notice the same problem after setting BottomMargin = 0. For the sake of correction, I have logged this problem as PDFNEWNET-32189 in our issue tracking system. We will further look into the details of this problem and will keep you updated on the status of correction.

We apologize for your inconvenience.

Thanks & Regards,

Hi Anouk,


Thanks for your patience.

I am pleased to share that the issue reported earlier has
been resolved in latest release version of Aspose.Pdf for .NET 7.3.0. Please
try using the latest release version and in case the problem still persists or
you have any further query, please feel free to contact.

For your reference, I have also attached the resultant PDF
which I have generated.

<o:p></o:p>


Hello.

I have a completely opposite issue. In my case the bottom margin is not added at all when I write: HtmlLoadOptions(0, 0, 50, 0), but is added when I write: HtmlLoadOptions(0, 0, 100, 0). The latter case adds too much margin, while the former case does not add the bottom margin at all.

I posted the question over here. If you will have time, could you help, please?

@y.trofimovedocs

You may specify margins during HTML to PDF conversion as following:

HtmlLoadOptions loadoptions = new HtmlLoadOptions(dataDir);
loadoptions.PageInfo.Margin = new MarginInfo(72, 72, 72, 72); // 72 points = 1 inch
Document doc = new Document("input.html", loadoptions);

In case you are facing any issue, please share your sample HTML content in ZIP format so that we can test the scenario in our environment and address it accordingly.