/** * Create a new document to hold the PDF contents. * <p>By default returns an A4 document, but the subclass can specify any * Document, possibly parameterized via bean properties defined on the View. * @return the newly created iText Document instance * @see com.lowagie.text.Document#Document(com.lowagie.text.Rectangle) */ protected Document newDocument() { return new Document(PageSize.A4); }
/** * Signals that an new page has to be started. * * @return <CODE>true</CODE> if the page was added, <CODE>false</CODE> * if not. */ boolean newPage() { return document.newPage(); }
private void addToDocument(Element element) throws DocumentException { document.add(element); } }
Element createParagraphElement(String paragraphTitle, String iconName) throws DocumentException, IOException { final Paragraph paragraph = new Paragraph("", paragraphTitleFont); paragraph.setSpacingBefore(5); paragraph.setSpacingAfter(5); if (iconName != null) { paragraph.add(new Chunk(getParagraphImage(iconName), 0, -5)); } final Phrase element = new Phrase(' ' + paragraphTitle, paragraphTitleFont); element.setLeading(12); paragraph.add(element); // chapter pour avoir la liste des signets final ChapterAutoNumber chapter = new ChapterAutoNumber(paragraph); // sans numéro de chapitre chapter.setNumberDepth(0); chapter.setBookmarkOpen(false); chapter.setTriggerNewPage(false); return chapter; }
private void writeRequest(CounterRequestContext context, PdfPCell cell, int margin) throws DocumentException, IOException { final Paragraph paragraph = new Paragraph( getDefaultCell().getLeading() + cellFont.getSize()); paragraph.setIndentationLeft(margin); if (context.getParentCounter().getIconName() != null) { paragraph.add(new Chunk(getImage(context.getParentCounter().getIconName()), 0, -1)); } paragraph.add(new Phrase(context.getCompleteRequestName(), cellFont)); cell.addElement(paragraph); }
private void addPsCommandReference() throws DocumentException { final Anchor psAnchor = new Anchor("ps command reference", PdfFonts.BLUE.getFont()); psAnchor.setName("ps command reference"); psAnchor.setReference("http://en.wikipedia.org/wiki/Ps_(Unix)"); psAnchor.setFont(PdfFonts.BLUE.getFont()); final Paragraph psParagraph = new Paragraph(); psParagraph.add(psAnchor); psParagraph.setAlignment(Element.ALIGN_RIGHT); addToDocument(psParagraph); }
private void createWriter(Document document, String title) throws DocumentException, IOException { final PdfWriter writer = PdfWriter.getInstance(document, output); //writer.setViewerPreferences(PdfWriter.PageLayoutTwoColumnLeft); // title final HeaderFooter header = new HeaderFooter(new Phrase(title), false); header.setAlignment(Element.ALIGN_LEFT); header.setBorder(Rectangle.NO_BORDER); document.setHeader(header); // simple page numbers : x //HeaderFooter footer = new HeaderFooter(new Phrase(), true); //footer.setAlignment(Element.ALIGN_RIGHT); //footer.setBorder(Rectangle.TOP); //document.setFooter(footer); // add the event handler for advanced page numbers : x/y writer.setPageEvent(new PdfAdvancedPageNumberEvents()); }
@Override protected final void renderMergedOutputModel( Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { // IE workaround: write into byte array first. ByteArrayOutputStream baos = createTemporaryOutputStream(); // Apply preferences and build metadata. Document document = newDocument(); PdfWriter writer = newWriter(document, baos); prepareWriter(model, writer, request); buildPdfMetadata(model, document, request); // Build PDF document. document.open(); buildPdfDocument(model, document, writer, request, response); document.close(); // Flush to HTTP response. writeToResponse(response, baos); }
Paragraph preface = new Paragraph(); preface.setAlignment(Element.ALIGN_CENTER);
private void writeCountry(SessionInformations session) throws IOException, BadElementException { final String country = session.getCountry(); if (country == null) { addCell(""); } else { final String fileName = "flags/" + country + ".gif"; final Image image = getImageByFileName(fileName); if (image == null) { addCell(country); } else { addCell(new Phrase(new Chunk(image, 0, 0))); } } }
private void addText(String text) throws DocumentException { final Paragraph paragraph = new Paragraph(text, normalFont); paragraph.setIndentationLeft(margin); addToDocument(paragraph); }
private void writeNoRequests() throws DocumentException { final String msg; if (isJobCounter()) { msg = "Aucun_job"; } else if (isErrorCounter()) { msg = "Aucune_erreur"; } else { msg = "Aucune_requete"; } addToDocument(new Phrase(getString(msg), normalFont)); }
private static Font getFont(float size, int style) { return FontFactory.getFont(FontFactory.HELVETICA, size, style); }
private Image getFolderImage() throws BadElementException, IOException { if (folderImage == null) { folderImage = PdfDocumentFactory.getImage("folder.png"); folderImage.scalePercent(40); } return folderImage; } }
private void addConfigurationReference() throws DocumentException { final Anchor quartzAnchor = new Anchor("Configuration reference", PdfFonts.BLUE.getFont()); quartzAnchor.setName("Quartz configuration reference"); quartzAnchor.setReference("http://www.quartz-scheduler.org/docs/index.html"); quartzAnchor.setFont(PdfFonts.BLUE.getFont()); final Paragraph quartzParagraph = new Paragraph(); quartzParagraph.add(quartzAnchor); quartzParagraph.setAlignment(Element.ALIGN_RIGHT); addToDocument(quartzParagraph); }
/** * Adds an <CODE>Element</CODE> to the <CODE>Document</CODE>. * * @param element * the <CODE>Element</CODE> to add * @return <CODE>true</CODE> if the element was added, <CODE>false * </CODE> if not * @throws DocumentException * when a document isn't open yet, or has been closed */ boolean addToDocument(Element element) throws DocumentException { return document.add(element); }
/** * Create a new document to hold the PDF contents. * <p>By default returns an A4 document, but the subclass can specify any * Document, possibly parameterized via bean properties defined on the View. * @return the newly created iText Document instance * @see com.lowagie.text.Document#Document(com.lowagie.text.Rectangle) */ protected Document newDocument() { return new Document(PageSize.A4); }
private void addConfigurationReference() throws DocumentException { final Anchor ehcacheAnchor = new Anchor("Configuration reference", PdfFonts.BLUE.getFont()); ehcacheAnchor.setName("Ehcache configuration reference"); ehcacheAnchor.setReference( "http://ehcache.sourceforge.net/apidocs/net/sf/ehcache/config/CacheConfiguration.html#field_summary"); ehcacheAnchor.setFont(PdfFonts.BLUE.getFont()); final Paragraph ehcacheParagraph = new Paragraph(); ehcacheParagraph.add(ehcacheAnchor); ehcacheParagraph.setAlignment(Element.ALIGN_RIGHT); addToDocument(ehcacheParagraph); }