我正在使用vb.net構建一個工作流程,用於處理大量PDF文件。我需要做的一件事是在每個PDF文檔的第一頁的左下角放置一個條形碼。在PDF文檔中增加頁面大小以適應條形碼(itextsharp)
我已經制定了放置條形碼的代碼,但問題是它可能會覆蓋第一頁上的現有內容。
我想增加頁面大小並在第一頁的底部添加約40個像素的空白區域,以便放置條形碼。但我不知道如何做到這一點!
這裏是現有代碼:
Public Sub addBarcodeToPdf(byval openPDFpath as string, byval savePDFpath as string, ByVal barcode As String)
Dim myPdf As PdfReader
Try
myPdf = New PdfReader(openPDFpath)
Catch ex As Exception
logEvent("LOAD PDF EXCEPTION " & ex.Message)
End Try
Dim stamper As PdfStamper = New PdfStamper(myPDF, New FileStream(savePDFpath, FileMode.Create))
Dim over As PdfContentByte = stamper.GetOverContent(1)
Dim textFont As BaseFont = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED)
Dim BarcodeFont As BaseFont = BaseFont.CreateFont("c:\windows\fonts\FRE3OF9X.TTF", BaseFont.IDENTITY_H, BaseFont.EMBEDDED)
over.SetColorFill(BaseColor.BLACK)
over.BeginText()
over.SetFontAndSize(textFont, 15)
over.SetTextMatrix(30, 3)
over.ShowText(barcode)
over.EndText()
over.BeginText()
over.SetFontAndSize(BarcodeFont, 28)
over.SetTextMatrix(5, 16)
over.ShowText("*" & barcode & "*")
over.EndText()
stamper.Close()
myPdf.Close()
End Sub
預先感謝您! /M
這是一個幾乎完全複製了Java問題[如何擴展PDF的頁面大小添加水印?] (http://stackoverflow.com/questions/29775893/how-to-extend-the-page-size-of-a-pdf-to-add-a-watermark)請將該示例的代碼轉換爲VB代碼並你有你的答案。這個例子也可以在[官方網站]上找到(http://developers.itextpdf.com/question/how-extend-page-size-pdf-add-watermark)。請務必先諮詢官方網站,然後詢問是否存在某些您不明白的問題。 –