Created
July 18, 2018 09:47
-
-
Save behumble/197dc883896a0d5e7e2b1a1d6d150d2b to your computer and use it in GitHub Desktop.
Multiple Outline Objects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.itextpdf.sample; | |
import com.itextpdf.text.Document; | |
import com.itextpdf.text.Paragraph; | |
import com.itextpdf.text.pdf.PdfDestination; | |
import com.itextpdf.text.pdf.PdfOutline; | |
import com.itextpdf.text.pdf.PdfPTable; | |
import com.itextpdf.text.pdf.PdfWriter; | |
import java.io.FileOutputStream; | |
public class OutlineDoubleEntry { | |
private static void addParagraphs(Document document, int count) throws Exception { | |
for(int i=0;i<count;i++) { | |
Paragraph p = new Paragraph("This is a Paragraph#"+i); | |
document.add(p); | |
} | |
} | |
private static void addTable(Document document, PdfWriter pdfWriter) throws Exception { | |
PdfPTable table = new PdfPTable(2); | |
table.addCell(""); | |
table.addCell("Second cell"); | |
// Two cells have shared Y position. | |
PdfDestination sharedDest = new PdfDestination(PdfDestination.FITH, pdfWriter.getVerticalPosition(false)); | |
PdfOutline firstOutline = new PdfOutline(pdfWriter.getRootOutline(), sharedDest, "First marker"); | |
PdfOutline secondOutline = new PdfOutline(pdfWriter.getRootOutline(), sharedDest, "Second marker"); | |
PdfOutline thridOutline = new PdfOutline(pdfWriter.getRootOutline(), sharedDest, "Third marker"); | |
PdfOutline fourthOutline = new PdfOutline(pdfWriter.getRootOutline(), sharedDest, "Fourth marker"); | |
document.add(table); | |
} | |
public static void main(String[] args) throws Exception { | |
Document document = new Document(); | |
FileOutputStream fos = new FileOutputStream("outline1.pdf"); | |
PdfWriter pdfWriter = PdfWriter.getInstance(document, fos); | |
document.open(); | |
// add a paragraphs | |
addParagraphs(document, 40); | |
addTable(document, pdfWriter); | |
// add a paragraphs | |
addParagraphs(document, 40); | |
document.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment