List of usage examples for com.lowagie.text Document setMargins
public boolean setMargins(float marginLeft, float marginRight, float marginTop, float marginBottom)
From source file:net.laubenberger.bogatyr.helper.HelperPdf.java
License:Open Source License
/** * Writes a PDF from multiple image files to a {@link File}. * /*from ww w .j av a 2 s .c o m*/ * @param pageSize * of the PDF * @param scale * images to fit the page size * @param file * output as PDF * @param files * for the PDF * @throws DocumentException * @throws IOException * @see File * @see Rectangle * @since 0.9.2 */ public static void writePdfFromImages(final Rectangle pageSize, final boolean scale, final File file, final File... files) throws DocumentException, IOException { // $JUnit$ if (log.isDebugEnabled()) log.debug(HelperLog.methodStart(pageSize, scale, file, files)); if (null == pageSize) { throw new RuntimeExceptionIsNull("pageSize"); //$NON-NLS-1$ } if (null == file) { throw new RuntimeExceptionIsNull("file"); //$NON-NLS-1$ } if (null == files) { throw new RuntimeExceptionIsNull("files"); //$NON-NLS-1$ } if (!HelperArray.isValid(files)) { throw new RuntimeExceptionIsEmpty("files"); //$NON-NLS-1$ } final Document document = new Document(pageSize); document.setMargins(0.0F, 0.0F, 0.0F, 0.0F); final FilterOutputStream fos = new BufferedOutputStream(new FileOutputStream(file)); try { PdfWriter.getInstance(document, fos); document.open(); for (final File inputFile : files) { if (null == inputFile) { throw new RuntimeExceptionIsNull("inputFile"); //$NON-NLS-1$ } final Image image = Image.getInstance(inputFile.getAbsolutePath()); if (scale) { image.scaleToFit(pageSize.getWidth(), pageSize.getHeight()); } document.add(image); document.newPage(); } } finally { document.close(); fos.close(); } if (log.isDebugEnabled()) log.debug(HelperLog.methodExit()); }
From source file:net.laubenberger.bogatyr.helper.HelperPdf.java
License:Open Source License
/** * Writes a PDF from multiple {@link java.awt.Image} to a {@link File}. * //from w ww . ja v a 2 s . co m * @param pageSize * of the PDF * @param scale * images to fit the page size * @param file * output as PDF * @param images * for the PDF * @throws DocumentException * @throws IOException * @see File * @see java.awt.Image * @see Rectangle * @since 0.9.2 */ public static void writePdfFromImages(final Rectangle pageSize, final boolean scale, final File file, final java.awt.Image... images) throws DocumentException, IOException { // $JUnit$ if (log.isDebugEnabled()) log.debug(HelperLog.methodStart(pageSize, scale, file, images)); if (null == pageSize) { throw new RuntimeExceptionIsNull("pageSize"); //$NON-NLS-1$ } if (null == file) { throw new RuntimeExceptionIsNull("file"); //$NON-NLS-1$ } if (null == images) { throw new RuntimeExceptionIsNull("images"); //$NON-NLS-1$ } if (!HelperArray.isValid(images)) { throw new RuntimeExceptionIsEmpty("images"); //$NON-NLS-1$ } final Document document = new Document(pageSize); document.setMargins(0.0F, 0.0F, 0.0F, 0.0F); final FilterOutputStream fos = new BufferedOutputStream(new FileOutputStream(file)); try { PdfWriter.getInstance(document, fos); document.open(); for (final java.awt.Image tempImage : images) { if (null == tempImage) { throw new RuntimeExceptionIsNull("tempImage"); //$NON-NLS-1$ } final Image image = Image.getInstance(tempImage, null); if (scale) { image.scaleToFit(pageSize.getWidth(), pageSize.getHeight()); } document.add(image); document.newPage(); } } finally { document.close(); fos.close(); } if (log.isDebugEnabled()) log.debug(HelperLog.methodExit()); }
From source file:net.laubenberger.wichtel.helper.HelperPdf.java
License:Open Source License
/** * Writes a PDF from multiple image files to a {@link File}. * //w ww . j a va 2 s .c o m * @param pageSize * of the PDF * @param scale * images to fit the page size * @param file * output as PDF * @param files * for the PDF * @throws DocumentException * @throws IOException * @see File * @see Rectangle * @since 0.0.1 */ public static void writePdfFromImages(final Rectangle pageSize, final boolean scale, final File file, final File... files) throws DocumentException, IOException { // $JUnit$ if (log.isDebugEnabled()) log.debug(HelperLog.methodStart(pageSize, scale, file, files)); if (null == pageSize) { throw new RuntimeExceptionIsNull("pageSize"); //$NON-NLS-1$ } if (null == file) { throw new RuntimeExceptionIsNull("file"); //$NON-NLS-1$ } if (null == files) { throw new RuntimeExceptionIsNull("files"); //$NON-NLS-1$ } if (!HelperArray.isValid(files)) { throw new RuntimeExceptionIsEmpty("files"); //$NON-NLS-1$ } final Document document = new Document(pageSize); document.setMargins(0.0F, 0.0F, 0.0F, 0.0F); try (FilterOutputStream fos = new BufferedOutputStream(new FileOutputStream(file))) { PdfWriter.getInstance(document, fos); document.open(); for (final File inputFile : files) { if (null == inputFile) { throw new RuntimeExceptionIsNull("inputFile"); //$NON-NLS-1$ } final Image image = Image.getInstance(inputFile.getAbsolutePath()); if (scale) { image.scaleToFit(pageSize.getWidth(), pageSize.getHeight()); } document.add(image); document.newPage(); } document.close(); } if (log.isDebugEnabled()) log.debug(HelperLog.methodExit()); }
From source file:net.laubenberger.wichtel.helper.HelperPdf.java
License:Open Source License
/** * Writes a PDF from multiple {@link java.awt.Image} to a {@link File}. * /*from w w w . j a va2s. c o m*/ * @param pageSize * of the PDF * @param scale * images to fit the page size * @param file * output as PDF * @param images * for the PDF * @throws DocumentException * @throws IOException * @see File * @see java.awt.Image * @see Rectangle * @since 0.0.1 */ public static void writePdfFromImages(final Rectangle pageSize, final boolean scale, final File file, final java.awt.Image... images) throws DocumentException, IOException { // $JUnit$ if (log.isDebugEnabled()) log.debug(HelperLog.methodStart(pageSize, scale, file, images)); if (null == pageSize) { throw new RuntimeExceptionIsNull("pageSize"); //$NON-NLS-1$ } if (null == file) { throw new RuntimeExceptionIsNull("file"); //$NON-NLS-1$ } if (null == images) { throw new RuntimeExceptionIsNull("images"); //$NON-NLS-1$ } if (!HelperArray.isValid(images)) { throw new RuntimeExceptionIsEmpty("images"); //$NON-NLS-1$ } final Document document = new Document(pageSize); document.setMargins(0.0F, 0.0F, 0.0F, 0.0F); try (FilterOutputStream fos = new BufferedOutputStream(new FileOutputStream(file))) { PdfWriter.getInstance(document, fos); document.open(); for (final java.awt.Image tempImage : images) { if (null == tempImage) { throw new RuntimeExceptionIsNull("tempImage"); //$NON-NLS-1$ } final Image image = Image.getInstance(tempImage, null); if (scale) { image.scaleToFit(pageSize.getWidth(), pageSize.getHeight()); } document.add(image); document.newPage(); } } if (log.isDebugEnabled()) log.debug(HelperLog.methodExit()); }
From source file:nl.knaw.dans.common.lang.pdf.PdfPageLayouter.java
License:Apache License
/** * Usage example//from ww w. j a va2s . c o m * * <pre> * final Document document = new Document(); * final PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("doc.pdf")); * writer.setPageEvent(new PdfPageLayouter(document,"footer", new URL("logo.png"))); * </pre> * * @param document * @param footerText optional text above the page number in the footer of the page * @param headerImage optional image for the page header * @throws HeaderImageException in case of problems with the image */ public PdfPageLayouter(final Document document, final String footerText, final URL headerImage) throws HeaderImageException { setFooterText(footerText); document.setMargins(MARGIN_LEFT, MARGIN_RIGHT, MARGIN_TOP, MARGIN_BOTTOM); setHeaderImage(headerImage); }
From source file:org.cocktail.superplan.server.gestionimpression.TabularEdtReport.java
License:CeCILL license
public NSData genererPdf(NSArray creneaux, NSTimestamp debutSemaine, String semaine, String libelleFormation) throws DocumentException { ByteArrayOutputStream os = new ByteArrayOutputStream(); Document document = new Document(); PdfWriter.getInstance(document, os); document.open();/*from w w w . j av a 2 s. c o m*/ document.setMargins(0, 0, 0, 0); Font font = new Font(Font.TIMES_ROMAN, 12, Font.BOLD, Color.DARK_GRAY); PdfPTable headerTable = new PdfPTable(1); PdfPCell cell = new PdfPCell(); Phrase ph = new Phrase(); ph.add(new Chunk(libelleFormation, font)); cell.setPhrase(ph); cell.setHorizontalAlignment(Element.ALIGN_CENTER); headerTable.addCell(cell); font = new Font(Font.TIMES_ROMAN, 10, Font.NORMAL, Color.DARK_GRAY); cell = new PdfPCell(); ph = new Phrase(); ph.add(new Chunk(semaine, font)); cell.setPhrase(ph); cell.setHorizontalAlignment(Element.ALIGN_CENTER); headerTable.addCell(cell); headerTable.setWidthPercentage(100); headerTable.setSpacingAfter(5.0f); document.add(headerTable); PdfPTable pdfTable = creerCreneauxTable(creneaux, debutSemaine); pdfTable.setWidthPercentage(100); document.add(pdfTable); document.close(); return new NSData(os.toByteArray()); }
From source file:org.forester.archaeopteryx.PdfExporter.java
License:Open Source License
static String writePhylogenyToPdf(final String file_name, final TreePanel tree_panel, int width, int height) throws IOException { if (height < HEIGHT_LIMIT) { height = HEIGHT_LIMIT;//from www . jav a 2s. c o m } if (width < WIDTH_LIMIT) { width = WIDTH_LIMIT; } final Phylogeny phylogeny = tree_panel.getPhylogeny(); if ((phylogeny == null) || phylogeny.isEmpty()) { return ""; } if (tree_panel.getMainPanel().getTreeFontSet().getSmallFont().getSize() < 1) { throw new IOException("fonts are too small for PDF export"); } final File file = new File(file_name); if (file.isDirectory()) { throw new IOException("[" + file_name + "] is a directory"); } final Document document = new Document(); document.setPageSize(new Rectangle(width, height)); document.setMargins(WIDTH_LIMIT / 2, WIDTH_LIMIT / 2, HEIGHT_LIMIT / 2, HEIGHT_LIMIT / 2); PdfWriter writer = null; try { writer = PdfWriter.getInstance(document, new FileOutputStream(file_name)); } catch (final DocumentException e) { throw new IOException(e); } document.open(); final DefaultFontMapper mapper = new DefaultFontMapper(); FontFactory.registerDirectories(); if (Util.isWindows()) { mapper.insertDirectory("C:\\WINDOWS\\Fonts\\"); } else if (Util.isMac()) { mapper.insertDirectory("/Library/Fonts/"); mapper.insertDirectory("/System/Library/Fonts/"); } else { mapper.insertDirectory("/usr/X/lib/X11/fonts/TrueType/"); mapper.insertDirectory("/usr/X/lib/X11/fonts/Type1/"); mapper.insertDirectory("/usr/share/fonts/default/TrueType/"); mapper.insertDirectory("/usr/share/fonts/default/Type1/"); } final PdfContentByte cb = writer.getDirectContent(); final Graphics2D g2 = cb.createGraphics(width, height, mapper); try { tree_panel.paintPhylogeny(g2, true, false, width - WIDTH_LIMIT, height - HEIGHT_LIMIT, 0, 0); } catch (final Exception e) { Util.unexpectedException(e); } finally { try { g2.dispose(); document.close(); } catch (final Exception e) { //Do nothing. } } String msg = file.toString(); if ((width > 0) && (height > 0)) { msg += " [size: " + width + ", " + height + "]"; } return msg; }
From source file:org.gbif.ipt.task.Eml2Rtf.java
License:Apache License
/** * Construct RTF document, mainly out of information extracted from Resource's EML object. Currently, the decision * has been made to always do this in English. * //from w w w. ja v a 2 s .c o m * @param doc Document * @param resource Resource * @throws DocumentException if problem occurs during add */ public void writeEmlIntoRtf(Document doc, Resource resource, String lng) throws DocumentException { // initialising resourceBundle. Locale loc = new Locale(lng); resourceBundle = ResourceBundle.getBundle("ApplicationResources", loc); // this.action = action; Eml eml = resource.getEml(); // configure page doc.setMargins(72, 72, 72, 72); System.out.println(DataDir.CONFIG_DIR); // write metadata doc.addAuthor(resource.getCreator().getName()); doc.addCreationDate(); doc.addTitle((eml.getTitle() == null) ? resource.getShortname() : eml.getTitle()); // add the keywords to the document StringBuilder keys = new StringBuilder(); for (KeywordSet kw : eml.getKeywords()) { if (keys.length() == 0) { keys.append(kw.getKeywordsString(", ")); } else { keys.append(", " + kw.getKeywordsString(", ")); } } String keysValue = keys.toString(); doc.addKeywords(keysValue); // write proper doc doc.open(); // title addPara(doc, eml.getTitle(), fontHeader, 0, Element.ALIGN_CENTER); doc.add(Chunk.NEWLINE); // Authors, affiliations and corresponging authors addAuthors(doc, eml); // Other various sections.. addDates(doc); //addCitations(doc); // Section called "Resource Citation" above "Abstract" addResourceCitation(doc, eml); setResAbs(eml); setPalKey(keysValue); setDisAgr(eml); //addAbstract(doc, eml); addRes(doc); //addKeywords(doc, keysValue); addPalcla(doc); addAbs(doc); addKeyWord(doc); addGeneralDescription(doc, eml); addProjectData(doc, eml); //addResourceLink(doc, resource); addTaxonomicCoverages(doc, eml, loc); addSpatialCoverage(doc, eml); addTemporalCoverages(doc, eml, loc); addNaturalCollections(doc, eml); addMethods(doc, eml); addResul(doc); addDatasetDescriptions(doc, resource); //addMetadataDescriptions(doc, eml); addDiscu(doc); addAgrad(doc); addReferences(doc, eml); doc.close(); }
From source file:org.geoserver.wms.map.PDFMapResponse.java
License:Open Source License
/** * Writes the PDF./*from w w w . j a v a2s . c o m*/ * <p> * NOTE: the document seems to actually be created in memory, and being written down to * {@code output} once we call {@link Document#close()}. If there's no other way to do so, it'd * be better to actually split out the process into produceMap/write? * </p> * * @see org.geoserver.ows.Response#write(java.lang.Object, java.io.OutputStream, * org.geoserver.platform.Operation) */ @Override public void write(Object value, OutputStream output, Operation operation) throws IOException, ServiceException { Assert.isInstanceOf(PDFMap.class, value); WMSMapContent mapContent = ((PDFMap) value).getContext(); final int width = mapContent.getMapWidth(); final int height = mapContent.getMapHeight(); if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("setting up " + width + "x" + height + " image"); } try { // step 1: creation of a document-object // width of document-object is width*72 inches // height of document-object is height*72 inches com.lowagie.text.Rectangle pageSize = new com.lowagie.text.Rectangle(width, height); Document document = new Document(pageSize); document.setMargins(0, 0, 0, 0); // step 2: creation of the writer PdfWriter writer = PdfWriter.getInstance(document, output); // step 3: we open the document document.open(); // step 4: we grab the ContentByte and do some stuff with it // we create a fontMapper and read all the fonts in the font // directory DefaultFontMapper mapper = new DefaultFontMapper(); FontFactory.registerDirectories(); // we create a template and a Graphics2D object that corresponds // with it PdfContentByte cb = writer.getDirectContent(); PdfTemplate tp = cb.createTemplate(width, height); PdfGraphics2D graphic = (PdfGraphics2D) tp.createGraphics(width, height, mapper); // we set graphics options if (!mapContent.isTransparent()) { graphic.setColor(mapContent.getBgColor()); graphic.fillRect(0, 0, width, height); } else { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("setting to transparent"); } int type = AlphaComposite.SRC; graphic.setComposite(AlphaComposite.getInstance(type)); Color c = new Color(mapContent.getBgColor().getRed(), mapContent.getBgColor().getGreen(), mapContent.getBgColor().getBlue(), 0); graphic.setBackground(mapContent.getBgColor()); graphic.setColor(c); graphic.fillRect(0, 0, width, height); type = AlphaComposite.SRC_OVER; graphic.setComposite(AlphaComposite.getInstance(type)); } Rectangle paintArea = new Rectangle(width, height); StreamingRenderer renderer = new StreamingRenderer(); renderer.setMapContent(mapContent); // TODO: expose the generalization distance as a param // ((StreamingRenderer) renderer).setGeneralizationDistance(0); RenderingHints hints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); renderer.setJava2DHints(hints); // we already do everything that the optimized data loading does... // if we set it to true then it does it all twice... java.util.Map rendererParams = new HashMap(); rendererParams.put("optimizedDataLoadingEnabled", new Boolean(true)); rendererParams.put("renderingBuffer", new Integer(mapContent.getBuffer())); // we need the renderer to draw everything on the batik provided graphics object rendererParams.put(StreamingRenderer.OPTIMIZE_FTS_RENDERING_KEY, Boolean.FALSE); // render everything in vector form if possible rendererParams.put(StreamingRenderer.VECTOR_RENDERING_KEY, Boolean.TRUE); if (DefaultWebMapService.isLineWidthOptimizationEnabled()) { rendererParams.put(StreamingRenderer.LINE_WIDTH_OPTIMIZATION_KEY, true); } rendererParams.put(StreamingRenderer.SCALE_COMPUTATION_METHOD_KEY, mapContent.getRendererScaleMethod()); renderer.setRendererHints(rendererParams); Envelope dataArea = mapContent.getRenderingArea(); // enforce no more than x rendering errors int maxErrors = wms.getMaxRenderingErrors(); MaxErrorEnforcer errorChecker = new MaxErrorEnforcer(renderer, maxErrors); // Add a render listener that ignores well known rendering exceptions and reports back // non // ignorable ones final RenderExceptionStrategy nonIgnorableExceptionListener; nonIgnorableExceptionListener = new RenderExceptionStrategy(renderer); renderer.addRenderListener(nonIgnorableExceptionListener); // enforce max memory usage int maxMemory = wms.getMaxRequestMemory() * KB; PDFMaxSizeEnforcer memoryChecker = new PDFMaxSizeEnforcer(renderer, graphic, maxMemory); // render the map renderer.paint(graphic, paintArea, mapContent.getRenderingArea(), mapContent.getRenderingTransform()); // render the watermark MapDecorationLayout.Block watermark = RenderedImageMapOutputFormat.getWatermark(wms.getServiceInfo()); if (watermark != null) { MapDecorationLayout layout = new MapDecorationLayout(); layout.paint(graphic, paintArea, mapContent); } // check if a non ignorable error occurred if (nonIgnorableExceptionListener.exceptionOccurred()) { Exception renderError = nonIgnorableExceptionListener.getException(); throw new ServiceException("Rendering process failed", renderError, "internalError"); } // check if too many errors occurred if (errorChecker.exceedsMaxErrors()) { throw new ServiceException("More than " + maxErrors + " rendering errors occurred, bailing out", errorChecker.getLastException(), "internalError"); } // check we did not use too much memory if (memoryChecker.exceedsMaxSize()) { long kbMax = maxMemory / KB; throw new ServiceException( "Rendering request used more memory than the maximum allowed:" + kbMax + "KB"); } graphic.dispose(); cb.addTemplate(tp, 0, 0); // step 5: we close the document document.close(); writer.flush(); writer.close(); } catch (DocumentException t) { throw new ServiceException("Error setting up the PDF", t, "internalError"); } }
From source file:org.gtdfree.addons.PDFExportAddOn.java
License:Open Source License
@Override public void export(GTDModel model, ActionsCollection collection, OutputStream out, ExportAddOn.ExportOrder order, FileFilter ff, boolean compact) throws Exception { fontSelector = new FontSelector(); fontSelectorB = new FontSelector(); fontSelectorB2 = new FontSelector(); fontSelectorB4 = new FontSelector(); baseFont = fontModel.getBaseFont();//from w w w . ja va 2 s.co m for (BaseFont bf : fontModel.getFonts()) { fontSelector.addFont(new Font(bf, baseFontSize)); fontSelectorB.addFont(new Font(bf, baseFontSize, Font.BOLD)); fontSelectorB2.addFont(new Font(bf, baseFontSize + 2, Font.BOLD)); fontSelectorB4.addFont(new Font(bf, baseFontSize + 4, Font.BOLD)); } boolean emptyH2 = false; boolean emptyH3 = false; PdfPTable actionTable = null; Document doc = new Document(); if (sizeSet) { doc.setPageSize(pageSize); } if (marginSet) { doc.setMargins(marginLeft, marginRight, marginTop, marginBottom); } //System.out.println("PDF size "+doc.getPageSize().toString()); //System.out.println("PDF m "+marginLeft+" "+marginRight+" "+marginTop+" "+marginBottom); @SuppressWarnings("unused") PdfWriter pw = PdfWriter.getInstance(doc, out); doc.addCreationDate(); doc.addTitle("GTD-Free PDF"); doc.addSubject("GTD-Free data exported as PDF"); HeaderFooter footer = new HeaderFooter(newParagraph(), true); footer.setAlignment(HeaderFooter.ALIGN_CENTER); footer.setBorder(HeaderFooter.TOP); doc.setFooter(footer); doc.open(); Phrase ch = newTitle("GTD-Free Data"); Paragraph p = new Paragraph(ch); p.setAlignment(Paragraph.ALIGN_CENTER); PdfPTable t = new PdfPTable(1); t.setWidthPercentage(100f); PdfPCell c = newCell(p); c.setBorder(Table.BOTTOM); c.setBorderWidth(2.5f); c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); c.setPadding(5f); t.addCell(c); doc.add(t); Iterator<Object> it = collection.iterator(order); while (it.hasNext()) { Object o = it.next(); if (o == ActionsCollection.ACTIONS_WITHOUT_PROJECT) { if (order == ExportAddOn.ExportOrder.FoldersProjectsActions) { doc.add(newSubSection(ActionsCollection.ACTIONS_WITHOUT_PROJECT)); emptyH2 = false; emptyH3 = true; } else { doc.add(newSection(ActionsCollection.ACTIONS_WITHOUT_PROJECT)); emptyH2 = true; emptyH3 = false; } continue; } if (o instanceof Folder) { Folder f = (Folder) o; if (actionTable != null) { doc.add(actionTable); actionTable = null; } if (f.isProject()) { if (order == ExportAddOn.ExportOrder.ProjectsActions || order == ExportAddOn.ExportOrder.ProjectsFoldersActions) { if (emptyH2 || emptyH3) { p = newParagraph(NONE_DOT); doc.add(p); } doc.add(newSection(f.getName())); if (compact) { if (f.getDescription() != null && f.getDescription().length() > 0) { p = newParagraph(f.getDescription()); p.setIndentationLeft(10f); p.setIndentationRight(10f); doc.add(p); } } else { t = new PdfPTable(2); t.setKeepTogether(true); t.setSpacingBefore(5f); t.setWidthPercentage(66f); t.setWidths(new float[] { 0.33f, 0.66f }); c = newCell("ID"); t.addCell(c); c = newCell(newStrongParagraph(String.valueOf(f.getId()))); t.addCell(c); c = newCell("Type"); t.addCell(c); c = newCell(newStrongParagraph("Project")); t.addCell(c); c = newCell("Open"); t.addCell(c); c = newCell(newStrongParagraph(String.valueOf(f.getOpenCount()))); t.addCell(c); c = newCell("All"); t.addCell(c); c = newCell(newStrongParagraph(String.valueOf(f.size()))); t.addCell(c); c = newCell("Description"); t.addCell(c); c = newDescriptionCell(f.getDescription()); t.addCell(c); doc.add(t); } emptyH2 = true; emptyH3 = false; } else { if (emptyH3) { p = newParagraph(NONE_DOT); doc.add(p); } doc.add(newSubSection("Project:" + " " + f.getName())); emptyH2 = false; emptyH3 = true; } continue; } if (order == ExportAddOn.ExportOrder.FoldersActions || order == ExportAddOn.ExportOrder.FoldersProjectsActions) { if (emptyH2 || emptyH3) { p = newParagraph(NONE_DOT); doc.add(p); } doc.add(newSection(f.getName())); if (compact) { if (f.getDescription() != null && f.getDescription().length() > 0) { p = newParagraph(f.getDescription()); p.setIndentationLeft(10f); p.setIndentationRight(10f); doc.add(p); } } else { t = new PdfPTable(2); t.setKeepTogether(true); t.setSpacingBefore(5f); t.setWidthPercentage(66f); t.setWidths(new float[] { 0.33f, 0.66f }); c = newCell("ID"); t.addCell(c); c = newCell(newStrongParagraph(String.valueOf(f.getId()))); t.addCell(c); String type = ""; if (f.isAction()) { type = "Action list"; } else if (f.isInBucket()) { type = "In-Bucket"; } else if (f.isQueue()) { type = "Next action queue"; } else if (f.isReference()) { type = "Reference list"; } else if (f.isSomeday()) { type = "Someday/Maybe list"; } else if (f.isBuildIn()) { type = "Default list"; } c = newCell("Type"); t.addCell(c); c = newCell(newStrongParagraph(type)); t.addCell(c); c = newCell("Open"); t.addCell(c); c = newCell(newStrongParagraph(String.valueOf(f.getOpenCount()))); t.addCell(c); c = newCell("All"); t.addCell(c); c = newCell(newStrongParagraph(String.valueOf(f.size()))); t.addCell(c); c = newCell("Description"); t.addCell(c); c = newDescriptionCell(f.getDescription()); t.addCell(c); doc.add(t); } emptyH2 = true; emptyH3 = false; } else { if (emptyH3) { p = newParagraph(NONE_DOT); doc.add(p); } doc.add(newSubSection("List:" + " " + f.getName())); emptyH2 = false; emptyH3 = true; } continue; } if (o instanceof Action) { emptyH2 = false; emptyH3 = false; Action a = (Action) o; if (compact) { if (actionTable == null) { actionTable = new PdfPTable(5); actionTable.setWidthPercentage(100f); actionTable.setHeaderRows(1); actionTable.setSpacingBefore(5f); c = newHeaderCell("ID"); actionTable.addCell(c); c = newHeaderCell("Pri."); actionTable.addCell(c); c = newHeaderCell("Description"); actionTable.addCell(c); c = newHeaderCell("Reminder"); actionTable.addCell(c); c = newHeaderCell(CHECK_RESOLVED); actionTable.addCell(c); float width = doc.getPageSize().getWidth() - doc.getPageSize().getBorderWidthLeft() - doc.getPageSize().getBorderWidthRight(); int i = model.getLastActionID(); float step = baseFontSize - 1; int steps = (int) Math.floor(Math.log10(i)) + 1; // ID column float col1 = 8 + steps * step; // Priority column float col2 = 4 + 3 * (baseFontSize + 4); // Reminder column float col4 = 10 + step * 11; // Resolved column float col5 = 8 + baseFontSize; // Description column float col3 = width - col1 - col2 - col4 - col5; actionTable.setWidths(new float[] { col1, col2, col3, col4, col5 }); } addSingleActionRow(a, actionTable); } else { addSingleActionTable(model, doc, a); } } } if (actionTable != null) { doc.add(actionTable); actionTable = null; } if (emptyH2 || emptyH3) { p = newParagraph(NONE_DOT); doc.add(p); } //w.writeCharacters("Exported: "+ApplicationHelper.toISODateTimeString(new Date())); doc.close(); }