Я нашел решение: Инициализировать переменную с нужными значениями кадрирования.
Dim nLeft as integer = 20
Dim nRight as integer = 20
Dim nBoth as integer = 40
Dim nUp as integer = 20
Я создал растеризованный объект с помощью Ghostscript.
Dim rasterize As Rasterizer.GhostscriptRasterizer = New Rasterizer.GhostscriptRasterizer()
rasterize.Open("PDFPath")
Dim nHeightBased As Integer = rasterize.GetPage(72, 72, 1).Height
Dim nWidthBased As Integer = rasterize.GetPage(72, 72, 1).Width
rasterize.Close()
затем я создаю новый растеризатор для получения страницы размера высоты и ширины с помощью пользовательских переключателей ("-dPDFFitPage")
rasterize = New Rasterizer.GhostscriptRasterizer()
rasterize.CustomSwitches.Add("-dPDFFitPage")
rasterize.Open(cPathPDF)
Dim nHeightBound As Integer = nHeightBased - rasterize.GetPage(72, 72, 1).Height
Dim nWidthBound As Integer = nWidthBased - rasterize.GetPage(72, 72, 1).Width
Dim nWidthPDF As Integer = rasterize.GetPage(72, 72, 1).Width
Dim nHeightPDF As Integer = rasterize.GetPage(72, 72, 1).Height
rasterize.Close()
Dim nWidthCrop As Integer = (nWidthPDF + nWidthBound) - (nLeft + nRight)
Dim nHeightCrop As Integer = (nHeightPDF + (nHeightBound / 2)) - (nBoth + nUp)
CropPDF("PathPDF", nLeft, nBoth, nWidthCrop, nHeightCrop)
И я создаю функцию CropPDF:
Теперь мы берем gswinc32.exe или gswinc64.exe и .dll и копируем / вставляем новый путь, в моем примере я использую «PathEXE»
Public Function CropPDF(ByVal cPathPDF As String, ByVal nLeft As Integer, ByVal nBoth As Integer, ByVal nWidthCrop As Integer, ByVal nHeightCrop As Integer)
Dim cPathWithoutExtension = Path.GetDirectoryName("PDFPath") & "/" & Path.GetFileNameWithoutExtension("PDFPath")
Dim gsPath As String = HttpContext.Current.Server.MapPath("PathEXE")
Dim gsArgsList As List(Of String) = New List(Of String)
gsArgsList.Add("-sDEVICE=pdfwrite")
gsArgsList.Add(" -dFIXEDMEDIA")
gsArgsList.Add(" -dDEVICEWIDTHPOINTS=" & nWidthCrop)
gsArgsList.Add(" -dDEVICEHEIGHTPOINTS=" & nHeightCrop)
gsArgsList.Add(" -o """ & cPathWithoutExtension & "_Crop.pdf""")
gsArgsList.Add(" -c ""<</Install {-" & nLeft & " -" & nBoth & " translate} >> setpagedevice """)
gsArgsList.Add(" -f " & cPathPDF)
Dim gsArgs As String = String.Join(Nothing, gsArgsList)
Process.Start(gsPath, gsArgs).WaitForExit()
Dim OFI As FileInfo = New FileInfo(cPathPDF)
OFI.Delete()
Dim DestOFI As FileInfo = New FileInfo(cPathWithoutExtension & "_Crop.pdf")
DestOFI.MoveTo(cPathPDF)
Return cPath
End Function
Теперь идеальная работа сnLeft nRight nBoth nUp, надеясь, что это поможет некоторым людям: D