' 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 Imports jp.ujihara.java.util Class Glossary Inherits PdfPageEventHelper ' we will keep a glossary of words and the pages they appear on in a TreeMap Dim glossary As New TreeMap() ' we override only the onGenericTag method Public Overrides Sub onGenericTag(ByVal writer As PdfWriter, ByVal document As Document, ByVal rect As Rectangle, ByVal text As String) glossary.put(text, writer.getPageNumber()) End Sub ' we add a method to retrieve the glossary Public Function getGlossary() As TreeMap Return glossary End Function End Class Public Class Chap0209 Public Shared Sub Main(ByVal args As String()) Console.WriteLine("Chapter 2 example 9: generic tags") ' step 1: creation of a document-object Dim Document As New Document() ' step 2: ' we create a writer that listens to the document ' and directs a PDF-stream to a file Dim Writer As PdfWriter = PdfWriter.getInstance(Document, New FileOutputStream("Chap0209.pdf")) ' step 3: we open the document Document.open() ' step 4: ' we create an Event and add it to the writer Dim pageEvent As New Glossary() Writer.setPageEvent(pageEvent) ' we add some content Dim f(13) As String f(0) = "Courier" f(1) = "Courier Bold" f(2) = "Courier Italic" f(3) = "Courier Bold Italic" f(4) = "Helvetica" f(5) = "Helvetica bold" f(6) = "Helvetica italic" f(7) = "Helvetica bold italic" f(8) = "Times New Roman" f(9) = "Times New Roman bold" f(10) = "Times New Roman italic" f(11) = "Times New Roman bold italic" f(12) = "Symbol" f(13) = "Zapfdingbats" Dim fonts(13) As Font fonts(0) = FontFactory.getFont(FontFactory.COURIER, 12, Font.NORMAL) fonts(1) = FontFactory.getFont(FontFactory.COURIER, 12, Font.BOLD) fonts(2) = FontFactory.getFont(FontFactory.COURIER, 12, Font.ITALIC) fonts(3) = FontFactory.getFont(FontFactory.COURIER, 12, Font.BOLD Or Font.ITALIC) fonts(4) = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL) fonts(5) = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD) fonts(6) = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.ITALIC) fonts(7) = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD Or Font.ITALIC) fonts(8) = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL) fonts(9) = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.BOLD) fonts(10) = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.ITALIC) fonts(11) = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.BOLD Or Font.ITALIC) fonts(12) = FontFactory.getFont(FontFactory.SYMBOL, 12, Font.NORMAL) fonts(13) = FontFactory.getFont(FontFactory.ZAPFDINGBATS, 12, Font.NORMAL) Dim i As Integer For i = 0 To 13 Dim chunk As New Chunk("This is font ", fonts(i)) Dim p As New Paragraph(chunk) p.add(New Phrase(New Chunk(f(i), fonts(i)).setGenericTag(f(i)))) Document.add(p) If i Mod 4 = 3 Then Document.newPage() End If Next ' we add the glossary Document.newPage() Dim Glossary As TreeMap = pageEvent.getGlossary() Dim it As Iterator = Glossary.keySet().iterator() While it.hasNext() Dim key As String = DirectCast(it.next(), String) Dim page As Integer = DirectCast(Glossary.get(key), Integer) Dim g As New Paragraph(key) g.add(" : page ") g.add(CStr(page)) Document.add(g) End While ' step 5: we close the document Document.close() End Sub End Class