Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Tue Apr 11, 2023 5:16 am

I have the following code that works in the free version, but does not work once I upgraded to the paid version.

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);

alex.scholaro
 
Posts: 1
Joined: Wed Feb 22, 2023 12:35 am

Tue Apr 11, 2023 10:30 am

Hi,

Thanks for your message.
I simulated tow PDF documents and tested with our latest Spire.PDF Pack (Hot Fix) Version: 9.4.0, but I did not reproduce your issue. If you were using an old version? I suggest that you switch to the latest version to test again. If your issue persists after testing, please provide the following information for us to investigate further.
1.Your input files as well as your final saved file. You can upload them here or provide to us by email ([email protected]).
2. Your system information (E.g. Win10, 64 bit) and region setting (E.g. China, Chinese).

Best Regards,
Herman
E-iceblue support team
User avatar

Herman.Yan
 
Posts: 115
Joined: Wed Mar 08, 2023 2:00 am

Return to Spire.PDF

cron