我已经创建了将Original.pdf提取到[outputFileName.pdf]的函数,我想为输出文件设置上边距,但它不适用于下面的代码(vb.net)。输出文件与原始文件的边距相同。
通过
调用此功能ExtractPdfPage("sourcePath", 1, "destinationPath")
Private Sub ExtractPdfPage(ByVal sourcePdf As String, ByVal pageNumberToExtract As Integer, ByVal outPdf As String)
Dim reader As iTextSharp.text.pdf.PdfReader = Nothing
Dim doc As iTextSharp.text.Document = Nothing
Dim pdfCpy As iTextSharp.text.pdf.PdfCopy = Nothing
Dim page As iTextSharp.text.pdf.PdfImportedPage = Nothing
Try
reader = New iTextSharp.text.pdf.PdfReader(sourcePdf)
doc = New iTextSharp.text.Document(reader.GetPageSizeWithRotation(1), 0, 0, 180, 0)
pdfCpy = New iTextSharp.text.pdf.PdfCopy(doc, New IO.FileStream(outPdf, IO.FileMode.Create))
doc.Open()
page = pdfCpy.GetImportedPage(reader, pageNumberToExtract)
pdfCpy.AddPage(page)
doc.Close()
reader.Close()
doc.Dispose()
reader.Dispose()
pdfCpy.Dispose()
Catch ex As Exception
Throw ex
End Try
End Sub