Imports iTextSharp.text.pdf Imports iTextSharp.text Imports System.IO Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim pdfDoc As New Document() Dim pdfWrite As PdfWriter = PdfWriter.GetInstance(pdfDoc, New FileStream("Test.pdf", FileMode.Create)) pdfDoc.Open() pdfDoc.Add(New Paragraph("Hello World")) pdfDoc.Close() End Sub End Class
Dim oldFile As String = "oldfile.pdf" Dim newFile As String = "newfile.pdf" ' open the reader Dim reader As PdfReader = New PdfReader(oldFile) Dim size As Rectangle = reader.GetPageSizeWithRotation(1) Dim document As Document = New Document(size) ' open the writer Dim fs As FileStream = New FileStream(newFile, FileMode.Create, FileAccess.Write) Dim writer As PdfWriter = PdfWriter.GetInstance(document, fs) document.Open() ' the pdf content Dim cb As PdfContentByte = writer.DirectContent ' select the font properties Dim bf As BaseFont = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED) cb.SetColorFill(BaseColor.DARK_GRAY) cb.SetFontAndSize(bf, 10) ' write the text in the pdf content cb.BeginText() Dim text As String = "Some blablablabla...." ' put the alignment and coordinates here cb.ShowTextAligned(1, text, 520, 640, 0) cb.EndText() ' create the new page and add it to the pdf Dim page As PdfImportedPage = writer.GetImportedPage(reader, 1) cb.AddTemplate(page, 0, 0) ' close the streams and voilá the file should be changed :) document.Close() fs.Close() writer.Close() reader.Close()
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question