List of usage examples for com.itextpdf.text.pdf PdfDestination FIT
int FIT
To view the source code for com.itextpdf.text.pdf PdfDestination FIT.
Click Source Link
From source file:at.laborg.briss.utils.DocumentCropper.java
License:Open Source License
private static File copyToMultiplePages(final CropDefinition cropDefinition, final PdfMetaInformation pdfMetaInformation) throws IOException, DocumentException { PdfReader reader = new PdfReader(cropDefinition.getSourceFile().getAbsolutePath()); HashMap<String, String> map = SimpleNamedDestination.getNamedDestination(reader, false); Document document = new Document(); File resultFile = File.createTempFile("cropped", ".pdf"); PdfSmartCopy pdfCopy = new PdfSmartCopy(document, new FileOutputStream(resultFile)); document.open();//from w ww .ja v a2 s .c o m Map<Integer, List<String>> pageNrToDestinations = new HashMap<Integer, List<String>>(); for (String single : map.keySet()) { StringTokenizer st = new StringTokenizer(map.get(single), " "); if (st.hasMoreElements()) { String pageNrString = (String) st.nextElement(); int pageNr = Integer.parseInt(pageNrString); List<String> singleList = (pageNrToDestinations.get(pageNr)); if (singleList == null) { singleList = new ArrayList<String>(); singleList.add(single); pageNrToDestinations.put(pageNr, singleList); } else { singleList.add(single); } } } int outputPageNumber = 0; for (int pageNumber = 1; pageNumber <= pdfMetaInformation.getSourcePageCount(); pageNumber++) { PdfImportedPage pdfPage = pdfCopy.getImportedPage(reader, pageNumber); pdfCopy.addPage(pdfPage); outputPageNumber++; List<String> destinations = pageNrToDestinations.get(pageNumber); if (destinations != null) { for (String destination : destinations) pdfCopy.addNamedDestination(destination, outputPageNumber, new PdfDestination(PdfDestination.FIT)); } List<Float[]> rectangles = cropDefinition.getRectanglesForPage(pageNumber); for (int j = 1; j < rectangles.size(); j++) { pdfCopy.addPage(pdfPage); outputPageNumber++; } } document.close(); pdfCopy.close(); reader.close(); return resultFile; }
From source file:net.atomique.ksar.export.FilePDF.java
License:Open Source License
private void export_treenode(SortedTreeNode node, PdfOutline root) { int num = node.getChildCount(); if (num > 0) { Object obj1 = node.getUserObject(); if (obj1 instanceof ParentNodeInfo) { ParentNodeInfo tmpnode = (ParentNodeInfo) obj1; List nodeobj = tmpnode.getNode_object(); if (nodeobj.isPrintSelected()) { root = new PdfOutline(root, new PdfDestination(PdfDestination.FIT), nodeobj.getTitle()); }// ww w .j a va 2 s .com } for (int i = 0; i < num; i++) { SortedTreeNode l = (SortedTreeNode) node.getChildAt(i); export_treenode(l, root); } } else { Object obj1 = node.getUserObject(); if (obj1 instanceof TreeNodeInfo) { TreeNodeInfo tmpnode = (TreeNodeInfo) obj1; Graph nodeobj = tmpnode.getNode_object(); if (nodeobj.isPrintSelected()) { new PdfOutline(root, new PdfDestination(PdfDestination.FIT), nodeobj.getTitle()); update_ui(); addchart(writer, nodeobj); document.newPage(); } } } }