Hi, PDFSharp Team,
I am trying to resize an existing PDF file but the result is not centered, what am I doing wrong? I am using PDFsharp and a cropped PDF as input, please see below code:
Code:
Private Sub ResizePDF(sourcePDF As String, outPDF As String)
Dim form As XPdfForm = XPdfForm.FromFile(sourcePDF)
Dim doc2 As New PdfSharp.Pdf.PdfDocument()
doc2.Options.CompressContentStreams = True
doc2.Options.ColorMode = PdfSharp.Pdf.PdfColorMode.Rgb
For pagenumber As Integer = 1 To (form.PageCount + 1) - 1
Dim page As PdfSharp.Pdf.PdfPage = doc2.Pages.Add()
form.PageNumber = pagenumber
page.Width = form.PixelWidth + 15.36
page.Height = form.PixelHeight + 40.32
Dim graph As XGraphics = XGraphics.FromPdfPage(page)
Dim rect As New XRect(0, 0, page.Width, page.Height)
graph.DrawImage(form, rect)
Next
If IO.Directory.Exists(IO.Path.GetDirectoryName(outPDF)) = False Then IO.Directory.CreateDirectory(IO.Path.GetDirectoryName(outPDF))
doc2.Save(outPDF)
End Sub
Please see below input and output file:
Input file:
https://www.dropbox.com/s/po87x8c44r90p ... 1.pdf?dl=0Ouput File:
https://www.dropbox.com/s/pt5pcyfayri6o ... t.pdf?dl=0I guess the problem here is I need to remove first the margins of cropped PDF but I don't know how to do that in PDFSharp, can someone point me into right direction? Thank you very much in advance.