我正在使用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)。请务必先咨询官方网站,然后询问是否存在某些您不明白的问题。 –