How can I resize all pages of an existing file to A4 keeping page direcetion and content?
I write the following code (based on your example), but the content is cutted
Thanks!
public static byte[] PdfToA4(byte[] source)
{
//Load your original Pdf
PdfDocument pdf = new PdfDocument(source);
//Create a new Pdf
PdfDocument newPdf = new PdfDocument();
foreach (PdfPageBase page in pdf.Pages)
{
//Set the new page size to A4
PdfPageBase newPage = newPdf.Pages.Add(PdfPageSize.A4, new PdfMargins(0));
//Draw the original Pdf page to the new page
page.CreateTemplate().Draw(newPage, new PointF(0, 0));
}
//Save the Pdf file
var ms = new MemoryStream();
newPdf.SaveToStream(ms, FileFormat.PDF);
newPdf.Close();
return ms.ToArray();
}