The code adds a PDF template (a blank page with a border) to the main PDF doc.
In the paid version, the margins and templates are not cleared when I set them to 0 and null. So the template pdf is drawn in the middle of the page and not at 0,0 coordinates of the page.
In the free version it's correctly drawn at 0,0 coordinates. I'm not quite sure what was changed in the new version.
- Code: Select all
PdfDocument doc1 = new PdfDocument();
doc1.LoadFromFile($@"wwwroot\border.pdf");
doc.PageSettings.SetMargins(0, 0, 0, 0);
//Remove temporary header and footer
doc.Template.Top = null;
doc.Template.Bottom = null;
PdfTemplate template1 = doc1.Pages[0].CreateTemplate();
var pageSettings = doc.PageSettings;
var margin = pageSettings.Margins;
//apply the template
for (int i = 0; i < doc.Pages.Count; i++)
{
doc.Pages[i].DefaultLayerIndex = -1;
doc.Pages[i].Canvas.SetTransparency(0.25f, 0.25f, PdfBlendMode.Normal);
doc.Pages[i].Canvas.DrawTemplate(template1, new PointF(0, 0));
}
//Create header and footer
doc.PageSettings.SetMargins(72, 25, 72, 26);
doc.Template.Top = CreateHeaderTemplate(doc);
doc.Template.Bottom = DrawPageNumber(doc);