Mega Code Archive

 
Categories / Java Tutorial / PDF
 

Page Labels

import java.io.FileOutputStream; import com.lowagie.text.Document; import com.lowagie.text.Paragraph; import com.lowagie.text.pdf.PdfPageLabels; import com.lowagie.text.pdf.PdfWriter; public class MainClass {   public static void main(String[] args) throws Exception {     Document document = new Document();     PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));     writer.setViewerPreferences(PdfWriter.PageModeUseThumbs);     document.open();     Paragraph hello = new Paragraph("(English:) hello, ");     document.add(new Paragraph("1. To the Universe:"));     document.add(hello);     PdfPageLabels pageLabels = new PdfPageLabels();     pageLabels.addPageLabel(1, PdfPageLabels.LOWERCASE_ROMAN_NUMERALS);     pageLabels.addPageLabel(5, PdfPageLabels.DECIMAL_ARABIC_NUMERALS);     pageLabels.addPageLabel(8, PdfPageLabels.DECIMAL_ARABIC_NUMERALS, "A-", 8);     writer.setPageLabels(pageLabels);     document.close();   } }