@Override public void export(FacesContext context, DataTable table, String filename, boolean pageOnly, boolean selectionOnly, String encodingType, MethodExpression preProcessor, MethodExpression postProcessor, ExporterOptions options, MethodExpression onTableRender) throws IOException { try { Document document = new Document(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); this.onTableRender = onTableRender; if (preProcessor != null) { preProcessor.invoke(context.getELContext(), new Object[]{document}); } if (!document.isOpen()) { document.open(); } if (options != null) { expOptions = options; } document.add(exportPDFTable(context, table, pageOnly, selectionOnly, encodingType)); if (postProcessor != null) { postProcessor.invoke(context.getELContext(), new Object[]{document}); } document.close(); writePDFToResponse(context.getExternalContext(), baos, filename); } catch (DocumentException e) { throw new IOException(e.getMessage()); } }
Document createDocument(boolean landscape) throws DocumentException, IOException { // creation of a document-object final Rectangle pageSize = getPageSize(landscape); // marges de 20 à gauche, à droite et en haut pour bien utiliser la largeur // et avoir une meilleur lisibilité sur les tableaux larges, // mais marge de 40 en bas pour ne pas empiéter sur les numéros de pages final Document document = new Document(pageSize, 20, 20, 20, 40); final String title; if (range == null) { title = I18N.getFormattedString("Monitoring_sur", application); } else { title = I18N.getFormattedString("Monitoring_sur", application) + " - " + range.getLabel(); } createWriter(document, title); // we add some meta information to the document (after writer) document.addAuthor(application); document.addCreator( "JavaMelody par E. Vernat, https://github.com/javamelody/javamelody/wiki"); document.addTitle(title); return document; }
/** * 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(); }
public void toPdf() throws IOException { try { document.open(); // il serait possible d'ouvrir la boîte de dialogue Imprimer de Adobe Reader // if (writer instanceof PdfWriter) { // ((PdfWriter) writer).addJavaScript("this.print(true);", false); // } pdfCoreReport.toPdf(); } catch (final DocumentException e) { throw createIOException(e); } document.close(); }
List<String> columnsName = Lists.newArrayList(); prepareProductColumnAlignment(productsTable.getDefaultCell(), ColumnAlignment.parseString(alignment)); productsTable.addCell(new Phrase(value, FontUtils.getDejavuRegular7Dark())); document.add(productsTable); document.add(Chunk.NEWLINE);
private void createDynamicHeaderTable(final Document document, final Entity offer, final Locale locale) throws DocumentException { PdfPTable dynaminHeaderTable = pdfHelper.createPanelTable(3); dynaminHeaderTable.getDefaultCell().setVerticalAlignment(Element.ALIGN_TOP); PdfPTable firstColumnHeaderTable = new PdfPTable(1); PdfPTable secondColumnHeaderTable = new PdfPTable(1); PdfPTable thirdColumnHeaderTable = new PdfPTable(1); setSimpleFormat(firstColumnHeaderTable); setSimpleFormat(secondColumnHeaderTable); setSimpleFormat(thirdColumnHeaderTable); dynaminHeaderTable.setSpacingBefore(7); Map<String, Object> firstColumn = createFirstColumn(offer); Map<String, Object> secondColumn = createSecondColumn(offer, locale); Map<String, Object> thirdColumn = createThirdColumn(offer); int maxSize = pdfHelper.getMaxSizeOfColumnsRows(Lists.newArrayList(Integer.valueOf(firstColumn.values().size()), Integer.valueOf(secondColumn.values().size()), Integer.valueOf(thirdColumn.values().size()))); for (int i = 0; i < maxSize; i++) { firstColumnHeaderTable = pdfHelper.addDynamicHeaderTableCell(firstColumnHeaderTable, firstColumn, locale); secondColumnHeaderTable = pdfHelper.addDynamicHeaderTableCell(secondColumnHeaderTable, secondColumn, locale); thirdColumnHeaderTable = pdfHelper.addDynamicHeaderTableCell(thirdColumnHeaderTable, thirdColumn, locale); } dynaminHeaderTable.addCell(firstColumnHeaderTable); dynaminHeaderTable.addCell(secondColumnHeaderTable); dynaminHeaderTable.addCell(thirdColumnHeaderTable); document.add(dynaminHeaderTable); document.add(Chunk.NEWLINE); }
private void addOutputProducts(final Document document, final Entity productionTracking, final Entity technology, final Locale locale) throws DocumentException { document.add(new Paragraph(translationService.translate("productionCounting.productionTrackingReport.report.paragraph3", locale), FontUtils.getDejavuBold11Dark())); List<String> outputProductsTableHeader = Lists.newArrayList(); outputProductsTable.addCell(new Phrase(translationService.translate("basic.product.globalTypeOfMaterial.value." + type, locale), FontUtils.getDejavuRegular9Dark())); outputProductsTable.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); if (trackingOperationProductOutComponent.getField(TrackingOperationProductOutComponentFields.USED_QUANTITY) == null) { outputProductsTable.addCell(new Phrase(L_N_A, FontUtils.getDejavuRegular9Dark())); .getDejavuRegular9Dark())); outputProductsTable.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_LEFT); outputProductsTable.addCell(new Phrase(trackingOperationProductOutComponent.getBelongsToField( TrackingOperationProductOutComponentFields.PRODUCT).getStringField(ProductFields.UNIT), FontUtils document.add(outputProductsTable);
private List<String> prepareProductsTableHeader(final Document document, final List<Entity> columnsForOrders, final Locale locale) throws DocumentException { document.add(new Paragraph(translationService.translate("deliveries.order.report.orderedProducts.title", locale), FontUtils.getDejavuBold10Dark())); List<String> productsHeader = Lists.newArrayList(); for (Entity columnForOrders : columnsForOrders) { String name = columnForOrders.getStringField(ColumnForOrdersFields.NAME); productsHeader.add(translationService.translate(name, locale)); } return productsHeader; }
private void addTableToDocument(Document document, Entity orderEntity, Locale locale, String headerKey, Map<String, String> values) throws DocumentException { document.add(new Paragraph(translationService.translate(headerKey, locale), FontUtils.getDejavuBold10Dark())); Map<String, HeaderAlignment> headerValues = Maps.newLinkedHashMap(); for (String key : values.keySet()) { headerValues.put(translationService.translate(String.format(L_TRANSLATION_PATH, key), locale), HeaderAlignment.LEFT); } PdfPTable table = pdfHelper.createTableWithHeader(values.size(), Lists.newArrayList(headerValues.keySet()), false, headerValues); table.getDefaultCell().disableBorderSide(PdfPCell.RIGHT); table.getDefaultCell().disableBorderSide(PdfPCell.LEFT); table.setHeaderRows(1); for (String value : values.values()) { table.addCell(createCell(value, Element.ALIGN_LEFT)); } table.setSpacingAfter(20); document.add(table); }
List<String> columnsName = Lists.newArrayList(); PdfPCell cell = productsTable.getRow(0).getCells()[ ((int) columnForOrders.getField(ColumnForDeliveriesFields.SUCCESSION)) - 1]; cell.setPhrase(new Phrase( translationService.translate("deliveries.order.report.columnHeader.number", locale) + "\n" + translationService prepareProductColumnAlignment(productsTable.getDefaultCell(), ColumnAlignment.parseString(alignment)); productsTable.addCell(new Phrase(value, FontUtils.getDejavuRegular7Dark())); document.add(productsTable);
private void addTechnologySeries(final Document document, final Entity materialRequirement, final Map<String, HeaderAlignment> headersWithAlignments) throws DocumentException { List<Entity> orders = materialRequirement.getManyToManyField(MaterialRequirementFields.ORDERS); MrpAlgorithm algorithm = MrpAlgorithm.parseString(materialRequirement .getStringField(MaterialRequirementFields.MRP_ALGORITHM)); Map<Long, BigDecimal> neededProductQuantities = basicProductionCountingService.getNeededProductQuantities(orders, algorithm); List<String> headers = Lists.newLinkedList(headersWithAlignments.keySet()); PdfPTable table = pdfHelper.createTableWithHeader(headersWithAlignments.size(), headers, true, defaultOrderHeaderColumnWidth, headersWithAlignments); for (Entry<Long, BigDecimal> neededProductQuantity : neededProductQuantities.entrySet()) { Entity product = productQuantitiesService.getProduct(neededProductQuantity.getKey()); table.addCell(new Phrase(product.getStringField(ProductFields.NUMBER), FontUtils.getDejavuRegular7Dark())); table.addCell(new Phrase(product.getStringField(ProductFields.NAME), FontUtils.getDejavuRegular7Dark())); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(new Phrase(numberService.format(neededProductQuantity.getValue()), FontUtils.getDejavuBold7Dark())); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); String unit = product.getStringField(ProductFields.UNIT); if (unit == null) { table.addCell(new Phrase("", FontUtils.getDejavuRegular7Dark())); } else { table.addCell(new Phrase(unit, FontUtils.getDejavuRegular7Dark())); } } document.add(table); }
Rectangle pageSize = frontPageDocument.getPageSize(); float positionX = pageSize.getWidth() / 2f - logoImage.getWidth() / 2f; logoImage.setAbsolutePosition(positionX, pageSize.getHeight() - logoImage.getHeight() - 100); frontPageDocument.add(logoImage); PdfPTable title = new PdfPTable(1); title.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_CENTER); title.getDefaultCell().setBorder(Rectangle.NO_BORDER); String descriptionRow = super.getProject().getDescription(); title.addCell(new Phrase(projectRow, Style.FRONTPAGE_FONT_1)); title.addCell(new Phrase(descriptionRow, Style.FRONTPAGE_FONT_2)); title.addCell(new Phrase(dateRow, Style.FRONTPAGE_FONT_3)); title.setTotalWidth(pageSize.getWidth() - frontPageDocument.leftMargin() - frontPageDocument.rightMargin()); title.writeSelectedRows(0, -1, frontPageDocument.leftMargin(), pageSize.getHeight() - logoImage.getHeight() - 150, frontPageWriter.getDirectContent());
/** * Methode qui ajoute le tableau de data dans le fichier pdf * @param _data tableau de donnes * @param _title titre du tableau * @param _document document pdf * @throws DocumentException * @author Adrien Hadoux */ public static void addDataToDocPdf(Object[][] _data,String _title,Document _document) throws DocumentException{ PdfPTable table = new PdfPTable(2); //-- titre --// PdfPCell cell = new PdfPCell(new Paragraph(_title)); cell.setColspan(2); table.addCell(cell); //-- remplissage --// for(int i=0;i<_data.length;i++) for(int j=0;j<_data.length;i++) table.addCell(_data[i][j].toString()); _document.add(table); }
private void addPlaceForSignature(final Document document, final Locale locale) throws DocumentException { PdfPTable table = new PdfPTable(1); table.setWidthPercentage(15); table.setHorizontalAlignment(Element.ALIGN_RIGHT); Paragraph signParagraph = new Paragraph(new Phrase(translationService.translate( "materialFlowResources.dispositionOrder.sign", locale), FontUtils.getDejavuBold7Dark())); signParagraph.setAlignment(Element.ALIGN_CENTER); PdfPCell cell1 = new PdfPCell(signParagraph); cell1.setBorder(Rectangle.TOP); cell1.setVerticalAlignment(Rectangle.ALIGN_CENTER); cell1.setHorizontalAlignment(Rectangle.ALIGN_CENTER); table.addCell(cell1); document.add(table); }
public void createOptionsTable(final Document document, final Entity materialRequirementCoverage, final Locale locale) throws DocumentException { PdfPTable optionsTable = new PdfPTable(2); optionsTable.setSpacingBefore(7); optionsTable.setWidthPercentage(100f); optionsTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); optionsTable.getDefaultCell().setPadding(2f); PdfPTable leftPanel = createOptionsLeftTable(materialRequirementCoverage, locale); PdfPTable rightPanel = createOptionsRightTable(materialRequirementCoverage, locale); optionsTable.addCell(leftPanel); optionsTable.addCell(rightPanel); document.add(optionsTable); document.add(Chunk.NEWLINE); }
private void addWorkPlanTitle(Document document, Entity workPlan, String title, Locale locale) throws DocumentException { PdfPTable headerTable = pdfHelper.createPanelTable(2); PdfPCell titleCell = new PdfPCell(); titleCell.setBorder(Rectangle.NO_BORDER); Paragraph workPlanTitle = new Paragraph(new Phrase(getWorkPlanTitle(locale), FontUtils.getDejavuBold11Light())); workPlanTitle.add(new Phrase(" " + getWorkPlanName(workPlan), FontUtils.getDejavuBold11Dark())); titleCell.addElement(workPlanTitle); PdfPCell divisionCell = new PdfPCell(); divisionCell.setBorder(Rectangle.NO_BORDER); Paragraph divisionTitle = new Paragraph(new Phrase(getDivisionTitle(locale), FontUtils.getDejavuBold11Light())); divisionTitle.add(new Phrase(" " + getDivisionFromTitle(title, locale), FontUtils.getDejavuBold11Dark())); divisionTitle.setAlignment(Element.ALIGN_RIGHT); divisionCell.addElement(divisionTitle); headerTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); headerTable.setTableEvent(null); headerTable.setSpacingAfter(4.0f); headerTable.addCell(titleCell); headerTable.addCell(divisionCell); document.add(headerTable); }
private void addPlaceForComments(Document document, Locale locale) throws DocumentException { PdfPTable table = new PdfPTable(1); table.setWidthPercentage(100f); Paragraph paragraph = new Paragraph(new Phrase(translationService.translate( "materialFlowResources.dispositionOrder.comments", locale), FontUtils.getDejavuBold7Dark())); paragraph.setAlignment(Element.ALIGN_LEFT); paragraph.setSpacingAfter(6f); document.add(paragraph); PdfPCell cell1 = new PdfPCell(new Paragraph("")); cell1.setBorder(Rectangle.BOX); cell1.setFixedHeight(60f); table.addCell(cell1); document.add(table); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); }
/** * @see org.displaytag.export.BinaryExportView#doExport(OutputStream) */ public void doExport(OutputStream out) throws JspException { try { // Initialize the table with the appropriate number of columns initTable(); // Initialize the Document and register it with PdfWriter listener and the OutputStream Document document = new Document(PageSize.A4.rotate(), 60, 60, 40, 40); document.addCreationDate(); HeaderFooter footer = new HeaderFooter(new Phrase(TagConstants.EMPTY_STRING, smallFont), true); footer.setBorder(Rectangle.NO_BORDER); footer.setAlignment(Element.ALIGN_CENTER); PdfWriter.getInstance(document, out); // Fill the virtual PDF table with the necessary data generatePDFTable(); document.open(); document.setFooter(footer); document.add(this.tablePDF); document.close(); } catch (Exception e) { throw new PdfGenerationException(e); } }
public void print(PdfWriter pdfWriter, Entity order, Entity operationComponent, Document document) throws DocumentException { PdfContentByte cb = pdfWriter.getDirectContent(); Barcode128 code128 = new Barcode128(); code128.setCode(barcodeOperationComponentService.getCodeFromBarcode(order, operationComponent)); PdfPTable barcodeTable = new PdfPTable(1); barcodeTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); barcodeTable.getDefaultCell().setVerticalAlignment(Element.ALIGN_TOP); barcodeTable.getDefaultCell().setBorder(0); barcodeTable.setWidthPercentage(10f); barcodeTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); Image barcodeImage = code128.createImageWithBarcode(cb, null, null); barcodeTable.addCell(barcodeImage); document.add(barcodeTable); }
document.add(Chunk.NEWLINE); document.add(new Paragraph(header.toString(), FontUtils.getDejavuBold11Dark())); document.add(Chunk.NEWLINE); productName.append(L_SPACER).append(product.getField(L_NAME)); panel.getDefaultCell().setBorder(PdfCell.NO_BORDER); panel.addCell(new Phrase(productNumber.toString(), FontUtils.getDejavuBold9Dark())); panel.addCell(new Phrase(company.toString(), FontUtils.getDejavuBold9Dark())); panel.addCell(new Phrase(productName.toString(), FontUtils.getDejavuBold9Dark())); panel.addCell(new Phrase()); Paragraph typeOfReport = new Paragraph(footer.toString(), FontUtils.getDejavuBold9Dark()); typeOfReport.setAlignment(Chunk.ALIGN_CENTER); document.add(typeOfReport);