List of usage examples for com.lowagie.text.pdf PdfAction gotoLocalPage
public static PdfAction gotoLocalPage(int page, PdfDestination dest, PdfWriter writer)
From source file:com.logiware.accounting.reports.ArDisputeReportCreator.java
private void init(String fileName) throws Exception { document = new Document(PageSize.A4); document.setMargins(5, 5, 5, 30);// w w w. j ava 2 s .c om writer = PdfWriter.getInstance(document, new FileOutputStream(fileName)); writer.setPdfVersion(PdfWriter.PDF_VERSION_1_7); writer.setUserunit(1f); writer.setPageEvent(new ArDisputeReportCreator(arReportsForm, contextPath)); document.open(); writer.setOpenAction( PdfAction.gotoLocalPage(1, new PdfDestination(PdfDestination.XYZ, -1, -1, 1f), writer)); }
From source file:com.qcadoo.report.api.pdf.ReportPdfView.java
License:Open Source License
@Override protected final void buildPdfDocument(final Map<String, Object> model, final Document document, final PdfWriter writer, final HttpServletRequest request, final HttpServletResponse response) { String fileName;// ww w . ja v a2 s .c om try { PdfAction ac = PdfAction.gotoLocalPage(1, new PdfDestination(PdfDestination.XYZ, -1, -1, 1f), writer); writer.setOpenAction(ac); fileName = addContent(document, model, LocaleContextHolder.getLocale(), writer); } catch (DocumentException e) { throw new IllegalStateException(e.getMessage(), e); } catch (IOException e) { throw new IllegalStateException(e.getMessage(), e); } response.setHeader("Content-disposition", "inline; filename=" + fileName + "." + ReportService.ReportType.PDF.getExtension()); }
From source file:gov.utah.health.uper.reports.Registration.java
@Override protected void buildPdfDocument(Map<String, Object> model, Document document, PdfWriter writer, HttpServletRequest request, HttpServletResponse response) throws DocumentException { try {//from w ww .j a v a2 s . co m Map<String, Object> dataCollections = (Map<String, Object>) model.get("formData"); ApplicationBean app = (ApplicationBean) dataCollections.get("application"); PatientBean pt = (PatientBean) dataCollections.get("patient"); setUpPage(document); buildHeader(document, app); buildPatient(document, pt); buildParent(document, pt); buildPhysician(document, pt); buildFooter(document); writer.setOpenAction( PdfAction.gotoLocalPage(1, new PdfDestination(PdfDestination.XYZ, 0, 10000, 1), writer)); } catch (Exception e) { LOG.error("Exception was caught while preparing UPER Registration.", e); } }
From source file:questions.importpages.ConcatenateWithTOC.java
public static void main(String[] args) { try {//from w ww .j a v a 2 s. c om // suppose we have some TEST PDF files for (int i = 0; i < TEST.length; i++) { createTestPdf(i); } // and we want to concatenate them Document document = new Document(); PdfCopy copy = new PdfCopy(document, new FileOutputStream(RESULT)); copy.setViewerPreferences(PdfWriter.PageModeUseOutlines); document.open(); // but we want to create an outline tree PdfOutline root = copy.getRootOutline(); // we also want an extra page with the file name Document coverpage; ByteArrayOutputStream baos; PdfReader reader; // we want to add page numbers too int pagenumber = 0; BaseFont bf = BaseFont.createFont(); for (int i = 0; i < TEST.length; i++) { // we create the coverpage in memory coverpage = new Document(); baos = new ByteArrayOutputStream(); PdfWriter.getInstance(coverpage, baos); coverpage.open(); coverpage.add(new Paragraph("file: " + TEST[i])); coverpage.close(); // we import that page reader = new PdfReader(baos.toByteArray()); pagenumber++; copy.addPage(getStampedPage(reader, copy, 1, pagenumber, bf)); // we create the bookmark to that page PdfDestination dest = new PdfDestination(PdfDestination.FIT); new PdfOutline(root, PdfAction.gotoLocalPage(pagenumber, dest, copy), TEST[i]); // we import the document itself reader = new PdfReader(TEST[i]); for (int j = 1; j <= reader.getNumberOfPages(); j++) { pagenumber++; copy.addPage(getStampedPage(reader, copy, j, pagenumber, bf)); } } document.close(); } catch (IOException ioe) { ioe.printStackTrace(); } catch (DocumentException de) { de.printStackTrace(); } }
From source file:questions.importpages.ConcatenateWithTOC2.java
public static void main(String[] args) { try {/* w w w . jav a2 s . c om*/ // suppose we have some TEST PDF files for (int i = 0; i < TEST.length; i++) { createTestPdf(i); } // and we want to concatenate them Document document = new Document(); ByteArrayOutputStream os = new ByteArrayOutputStream(); PdfCopy copy = new PdfCopy(document, os); copy.setViewerPreferences(PdfWriter.PageModeUseOutlines); document.open(); // but we want to create an outline tree PdfOutline root = copy.getRootOutline(); // we also want an extra page with the file name Document coverpage; ByteArrayOutputStream baos; PdfReader reader; // we want keep track of the page numbers int pagenumber = 0; for (int i = 0; i < TEST.length; i++) { // we create the coverpage in memory coverpage = new Document(); baos = new ByteArrayOutputStream(); PdfWriter.getInstance(coverpage, baos); coverpage.open(); coverpage.add(new Paragraph("file: " + TEST[i])); coverpage.close(); // we import that page reader = new PdfReader(baos.toByteArray()); pagenumber++; copy.addPage(copy.getImportedPage(reader, 1)); // we create the bookmark to that page PdfDestination dest = new PdfDestination(PdfDestination.FIT); new PdfOutline(root, PdfAction.gotoLocalPage(pagenumber, dest, copy), TEST[i]); // we import the document itself reader = new PdfReader(TEST[i]); for (int j = 1; j <= reader.getNumberOfPages(); j++) { pagenumber++; copy.addPage(copy.getImportedPage(reader, j)); } } document.close(); // we want to add page X of Y reader = new PdfReader(os.toByteArray()); int n = reader.getNumberOfPages(); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT)); BaseFont bf = BaseFont.createFont(); for (int i = 1; i <= n; i++) { PdfContentByte canvas = stamper.getOverContent(i); canvas.beginText(); canvas.setFontAndSize(bf, 12); canvas.showTextAligned(Element.ALIGN_LEFT, "page " + i + " of " + n, 36, 26, 0); canvas.endText(); } stamper.close(); } catch (IOException ioe) { ioe.printStackTrace(); } catch (DocumentException de) { de.printStackTrace(); } }
From source file:questions.stamppages.BookmarksToTOC1.java
@SuppressWarnings("unchecked") public static void main(String[] args) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try {/*from w w w . ja v a 2 s .c om*/ Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, baos); writer.setViewerPreferences(PdfWriter.PageModeUseOutlines); writer.setPageEvent(new ParagraphBookmarkEvents(false)); document.open(); BufferedReader reader = new BufferedReader(new FileReader(RESOURCE)); String line; Paragraph p; while ((line = reader.readLine()) != null) { p = new Paragraph(line); p.setAlignment(Element.ALIGN_JUSTIFIED); document.add(p); document.add(Chunk.NEWLINE); } reader.close(); document.close(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } try { PdfReader reader = new PdfReader(baos.toByteArray()); Rectangle rect = reader.getPageSizeWithRotation(1); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT)); stamper.insertPage(1, rect); ColumnText column = new ColumnText(stamper.getOverContent(1)); column.setSimpleColumn(rect.getLeft(36), rect.getBottom(36), rect.getRight(36), rect.getTop(36)); column.addElement(new Paragraph("TABLE OF CONTENTS")); List<Map> list = SimpleBookmark.getBookmark(reader); Chunk link; PdfAction action; String info; int p = 1; float y = 10; for (Map<String, String> bookmark : list) { link = new Chunk(bookmark.get("Title")); info = bookmark.get("Page"); p = Integer.parseInt(info.substring(0, info.indexOf(' '))); y = Float.parseFloat(info.substring(info.lastIndexOf(' ') + 1) + "f"); action = PdfAction.gotoLocalPage(p, new PdfDestination(PdfDestination.FITH, y), stamper.getWriter()); link.setAction(action); column.addElement(new Paragraph(link)); } column.go(); stamper.close(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } }