/** * Create a new PdfWriter for the given iText Document. * @param document the iText Document to create a writer for * @param os the OutputStream to write to * @return the PdfWriter instance to use * @throws DocumentException if thrown during writer creation */ protected PdfWriter newWriter(Document document, OutputStream os) throws DocumentException { return PdfWriter.getInstance(document, os); }
private static PdfPTable createJavaInformationsTable() throws DocumentException { final PdfPTable table = new PdfPTable(2); table.setHorizontalAlignment(Element.ALIGN_LEFT); table.setWidthPercentage(100); table.setWidths(new int[] { 2, 8 }); table.getDefaultCell().setBorder(0); return table; }
private static PdfPTable createAttributesTable() { final PdfPTable table = new PdfPTable(3); table.setWidthPercentage(100); final PdfPCell defaultCell = table.getDefaultCell(); defaultCell.setPaddingLeft(2); defaultCell.setPaddingRight(2); defaultCell.setVerticalAlignment(Element.ALIGN_TOP); defaultCell.setBorder(0); return table; }
/** {@inheritDoc} */ @Override public void onEndPage(PdfWriter writer, Document document) { final int pageN = writer.getPageNumber(); final String text = pageN + " / "; final float len = bf.getWidthPoint(text, 8); cb.beginText(); cb.setFontAndSize(bf, 8); final float width = document.getPageSize().getWidth(); cb.setTextMatrix(width / 2, 30); cb.showText(text); cb.endText(); cb.addTemplate(template, width / 2 + len, 30); }
protected void addColumnValue(PdfPTable pdfTable, String value) { PdfPCell cell = new PdfPCell(new Paragraph(value, facetFont)); if (facetBgColor != null) { cell.setBackgroundColor(facetBgColor); } pdfTable.addCell(cell); }
void addCell(PdfPCell cell) { table.addCell(cell); }
/** {@inheritDoc} */ @Override public void onOpenDocument(PdfWriter writer, Document document) { cb = writer.getDirectContent(); template = cb.createTemplate(50, 50); }
@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(); PdfReader reader = readPdfResource(); PdfStamper stamper = new PdfStamper(reader, baos); mergePdfDocument(model, stamper, request, response); stamper.close(); // Flush to HTTP response. writeToResponse(response, baos); }
/** * Initialize opens the document for reading. This is done implicitly * by the constuctor. This should only need to be called directly following * a reset. * @throws IOException */ protected void initialize() throws IOException{ if(document != null){ documentReader = new PdfReader(document); } catalog = documentReader.getCatalog(); }
/** {@inheritDoc} */ @Override public void onCloseDocument(PdfWriter writer, Document document) { template.beginText(); template.setFontAndSize(bf, 8); template.showText(String.valueOf(writer.getPageNumber() - 1)); template.endText(); } }
private PdfPCell getDefaultCell() { return currentTable.getDefaultCell(); }
/** * Read the raw PDF resource into an iText PdfReader. * <p>The default implementation resolve the specified "url" property * as ApplicationContext resource. * @return the PdfReader instance * @throws IOException if resource access failed * @see #setUrl */ protected PdfReader readPdfResource() throws IOException { String url = getUrl(); Assert.state(url != null, "'url' not set"); return new PdfReader(obtainApplicationContext().getResource(url).getInputStream()); }
PdfAdvancedPageNumberEvents() throws DocumentException, IOException { super(); bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); }
/** * Prepare the given PdfWriter. Called before building the PDF document, * that is, before the call to {@code Document.open()}. * <p>Useful for registering a page event listener, for example. * The default implementation sets the viewer preferences as returned * by this class's {@code getViewerPreferences()} method. * @param model the model, in case meta information must be populated from it * @param writer the PdfWriter to prepare * @param request in case we need locale etc. Shouldn't look at attributes. * @throws DocumentException if thrown during writer preparation * @see com.lowagie.text.Document#open() * @see com.lowagie.text.pdf.PdfWriter#setPageEvent * @see com.lowagie.text.pdf.PdfWriter#setViewerPreferences * @see #getViewerPreferences() */ protected void prepareWriter(Map<String, Object> model, PdfWriter writer, HttpServletRequest request) throws DocumentException { writer.setViewerPreferences(getViewerPreferences()); }
BarcodeEAN codeEAN = new BarcodeEAN(); codeEAN.setCodeType(codeEAN.EAN13); codeEAN.setCode("9780201615883"); Image imageEAN = codeEAN.createImageWithBarcode(cb, null, null);
void addCell(Image image) { table.addCell(image); }
/** * Create a new PdfWriter for the given iText Document. * @param document the iText Document to create a writer for * @param os the OutputStream to write to * @return the PdfWriter instance to use * @throws DocumentException if thrown during writer creation */ protected PdfWriter newWriter(Document document, OutputStream os) throws DocumentException { return PdfWriter.getInstance(document, os); }
@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(); PdfReader reader = readPdfResource(); PdfStamper stamper = new PdfStamper(reader, baos); mergePdfDocument(model, stamper, request, response); stamper.close(); // Flush to HTTP response. writeToResponse(response, baos); }
PdfPCell getDefaultCell() { return table.getDefaultCell(); }
void addCell(Phrase phrase) { table.addCell(phrase); }