hi. i want to resize pdf in actual size. but can’t remove margins. my code is here:
Private Shared Function resizeStrech(loadFullFileName As String, saveFullFileName As String, newWidth As Decimal, newHeight As Decimal) As Boolean
If IO.File.Exists(loadFullFileName) = False Then
Throw New Exception("file not found")
End If
Dim doc As New Document(loadFullFileName)
If doc.Pages.Count > 1 Then
Throw New Exception("file have more than one page")
End If
doc.Pages(1).PageInfo.Margin.Bottom = 0
doc.Pages(1).PageInfo.Margin.Top = 0
doc.Pages(1).PageInfo.Margin.Left = 0
doc.Pages(1).PageInfo.Margin.Right = 0
Dim editor As New PdfFileEditor
Dim parameter As New PdfFileEditor.ContentsResizeParameters(
Nothing, PdfFileEditor.ContentsResizeValue.Units(mil2pix(newWidth)),
Nothing,
Nothing, PdfFileEditor.ContentsResizeValue.Units(mil2pix(newHeight)),
Nothing)
'
'
editor.ResizeContents(doc, {1}, parameter)
'
doc.Save("temp.pdf")
Dim info As New PdfFileInfo("temp.pdf")
Dim pw = info.GetPageWidth(1)
Dim ph = info.GetPageHeight(1)
Dim left = (pw - mil2pix(newWidth)) / 2
Dim bottom = (ph - mil2pix(newHeight)) / 2
Dim PageEditor As New Aspose.Pdf.Facades.PdfPageEditor()
PageEditor.BindPdf("temp.pdf")
PageEditor.MovePosition((-1 * left), (-1 * bottom))
PageEditor.Save("temp.pdf")
Dim newDoc As New Document("temp.pdf")
newDoc.Pages(1).SetPageSize(mil2pix(newWidth), mil2pix(newHeight))
newDoc.Save(saveFullFileName)
Return True
End Function