【发布时间】:2016-09-30 07:47:56
【问题描述】:
我正在使用 vb.net 构建一个工作流程,我正在处理多个 PDF 文件。我需要做的一件事是在每个 PDF 文档的第一页左下角放置一个条形码。
我已经制定了放置条形码的代码,但问题是它可能会覆盖第一页上的现有内容。
我想增加页面大小并在第一页底部添加大约 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 问题How to extend the page size of a PDF to add a watermark? 的完全相同的副本,请将该示例的代码转换为 VB 代码,您就有答案了。这个例子也可以在official web site 上找到。一定要先咨询官网,有不懂的地方再问。