| |
29. 61. 3. 命名行动 |
|
import java.io.FileOutputStream;
import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.Element;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Phrase;
import com.lowagie.text.pdf.PdfAction;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;
public class MainClass {
public static void main(String[] args) throws Exception {
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
document.open();
PdfPTable table = new PdfPTable(4);
table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
table
.addCell(new Phrase(new Chunk("First Page").setAction(new PdfAction(PdfAction.FIRSTPAGE))));
table.addCell(new Phrase(new Chunk("Prev Page").setAction(new PdfAction(PdfAction.PREVPAGE))));
table.addCell(new Phrase(new Chunk("Next Page").setAction(new PdfAction(PdfAction.NEXTPAGE))));
table.addCell(new Phrase(new Chunk("Last Page").setAction(new PdfAction(PdfAction.LASTPAGE))));
Paragraph p = new Paragraph(new Chunk("Click to print").setAction(new PdfAction(
PdfAction.PRINTDIALOG)));
for (int k = 1; k <= 30; ++k) {
document.add(new Paragraph("This is page " + k));
document.add(Chunk.NEWLINE);
document.add(table);
document.add(p);
document.newPage();
}
document.close();
}
}
|
|
|