I found a solution to the problem, not a good one, but it works...
######################
Adding margins to the document:
######################
using(PdfDocument doc = PdfReader.Open(path))
{
foreach (PdfPage page in doc.Pages)
{
XPoint newLocation = new XPoint(-((printSize.Width - page.Width) / 2), -((printSize.Height - page.Height) / 2));
PdfRectangle newMediaBox = new PdfRectangle(newLocation, new XSize(printSize.Width, printSize.Height));
page.MediaBox = newMediaBox;
}
doc.Save(documentPath);
}
######################################
Then you have to do this to get the x and y back to normal
######################################
double newX = -((page.Width - contentSize.Width)/2);
double newY = (page.Height - contentSize.Height)/2;
xGraphics.TranslateTransform(newX, newY);
|