' Copyright (c) 2003 UJIHARA Kazuya. All rights reserved. ' ' Redistribution and use in source and binary forms, with or without ' modification, are permitted provided that the following conditions ' are met: ' ' 1. Redistributions of source code must retain the above copyright ' notice, this list of conditions and the following disclaimer. ' ' 2. Redistributions in binary form must reproduce the above copyright ' notice, this list of conditions and the following disclaimer in ' the Documentation and/or other materials provided with the ' distribution. ' ' 3. The end-user Documentation included with the redistribution, ' if any, must include the following acknowledgment: ' "This product includes software developed by ' Kazuya Ujihara ." ' Alternately, this acknowledgment may appear in the software itself, ' if and wherever such third-party acknowledgments normally appear. ' ' THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED ' WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES ' OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE ' DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ' ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ' SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ' LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES LOSS OF ' USE, DATA, OR PROFITS OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ' ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ' OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ' OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ' SUCH DAMAGE. ' ==================================================================== ' ' This code is free software. It may only be copied or modified ' if you include the following copyright notice: ' ' --> Copyright 2001 by Bruno Lowagie <-- ' ' This code is part of the 'iText Tutorial'. ' You can find the complete tutorial at the following address: ' http:'www.lowagie.com/iText/tutorial/ ' ' This code is distributed in the hope that it will be useful, ' but WITHOUT ANY WARRANTY without even the implied warranty of ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ' ' itext@lowagie.com Option Strict On Imports System Imports com.lowagie.text Imports com.lowagie.text.pdf Imports java.io Public Class Chap0112 Public Shared Sub Main(ByVal args As String()) Console.WriteLine("Chapter 1 example 12: reading an existing PDF file") ' we create a reader for a certain document Dim Reader As New PdfReader("Chap0703.pdf") ' we retrieve the total number of pages Dim n As Integer = Reader.getNumberOfPages() ' we retrieve the size of the first page Dim psize As Rectangle = Reader.getPageSize(1) Dim width As Single = psize.width() Dim height As Single = psize.height() ' step 1: creation of a document-object Dim Document As New Document(psize, 50, 50, 50, 50) ' step 2: we create a writer that listens to the document Dim Writer As PdfWriter = PdfWriter.getInstance(Document, New FileOutputStream("Chap0112.pdf")) ' step 3: we open the document Try Dim Watermark As New Watermark(Image.getInstance("watermark.jpg"), 200, 320) Document.add(Watermark) Catch e As Exception Console.WriteLine("Are you sure you have the file 'watermark.jpg' in the right path?") End Try Document.open() ' step 4: we add content Dim cb As PdfContentByte = Writer.getDirectContent() Dim i As Integer = 0 Dim p As Integer = 0 Console.WriteLine("There are " & n & " pages in the document.") While (i < n) Document.newPage() p = p + 1 i = i + 1 Dim page1 As PdfImportedPage = Writer.getImportedPage(Reader, i) cb.addTemplate(page1, 0.5F, 0, 0, 0.5F, 0, height / 2) Console.WriteLine("processed page " & i) If (i < n) Then i = i + 1 Dim page2 As PdfImportedPage = Writer.getImportedPage(Reader, i) cb.addTemplate(page2, 0.5F, 0, 0, 0.5F, width / 2, height / 2) Console.WriteLine("processed page " & i) End If If (i < n) Then i = i + 1 Dim page3 As PdfImportedPage = Writer.getImportedPage(Reader, i) cb.addTemplate(page3, 0.5F, 0, 0, 0.5F, 0, 0) Console.WriteLine("processed page " & i) End If If (i < n) Then i = i + 1 Dim page4 As PdfImportedPage = Writer.getImportedPage(Reader, i) cb.addTemplate(page4, 0.5F, 0, 0, 0.5F, width / 2, 0) Console.WriteLine("processed page " & i) End If cb.setRGBColorStroke(255, 0, 0) cb.moveTo(0, height / 2) cb.lineTo(width, height / 2) cb.stroke() cb.moveTo(width / 2, height) cb.lineTo(width / 2, 0) cb.stroke() Dim bf As BaseFont = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED) cb.beginText() cb.setFontAndSize(bf, 14) cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "page " & p & " of " & ((n / 4) + CInt(IIf(n Mod 4 > 0, 1, 0))), width / 2, 40, 0) cb.endText() End While ' step 5: we close the document Document.close() End Sub End Class