Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(FILE)); document.open(); addMetaData(document); Paragraph preface = new Paragraph(); preface.add(new Paragraph("Title of the document", catFont)); preface.add(new Paragraph( "Report generated by: " + System.getProperty("user.name") + ", " + new Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ smallBold)); PdfPTable table = new PdfPTable(3); PdfPCell c1 = new PdfPCell(new Phrase("Job Name:")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Test 001")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1);
private void writeRequest(CounterRequest childRequest, float executionsByRequest, boolean allChildHitsDisplayed) throws IOException, DocumentException { final PdfPCell defaultCell = getDefaultCell(); defaultCell.setHorizontalAlignment(Element.ALIGN_LEFT); final Paragraph paragraph = new Paragraph(defaultCell.getLeading() + cellFont.getSize()); if (executionsByRequest != -1) { paragraph.setIndentationLeft(5); } final Counter parentCounter = getCounterByRequestId(childRequest); if (parentCounter != null && parentCounter.getIconName() != null) { paragraph.add(new Chunk(getSmallImage(parentCounter.getIconName()), 0, -1)); } paragraph.add(new Phrase(childRequest.getName(), cellFont)); final PdfPCell requestCell = new PdfPCell(); requestCell.addElement(paragraph); requestCell.setGrayFill(defaultCell.getGrayFill()); requestCell.setPaddingTop(defaultCell.getPaddingTop()); addCell(requestCell); defaultCell.setHorizontalAlignment(Element.ALIGN_RIGHT); if (executionsByRequest != -1) { addCell(nbExecutionsFormat.format(executionsByRequest)); } else { final boolean hasChildren = !request.getChildRequestsExecutionsByRequestId().isEmpty(); if (hasChildren) { addCell(""); } } writeRequestValues(childRequest, allChildHitsDisplayed); }
private void writeGraph() throws IOException, DocumentException { final JRobin jrobin = collector.getJRobin(graphName); if (jrobin != null) { final byte[] img = jrobin.graph(range, 960, 400); final Image image = Image.getInstance(img); image.scalePercent(50); final PdfPTable table = new PdfPTable(1); table.setHorizontalAlignment(Element.ALIGN_CENTER); table.setWidthPercentage(100); table.getDefaultCell().setBorder(0); table.addCell("\n"); table.addCell(image); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(new Phrase(getString("graph_units"), cellFont)); addToDocument(table); } else { // just in case request is null and collector.getJRobin(graphName) is null, we must write something in the document addToDocument(new Phrase("\n", cellFont)); } }
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; }
PdfPTable table = new PdfPTable(2); PdfPCell cellOne = new PdfPCell(new Phrase("Hello")); PdfPCell cellTwo = new PdfPCell(new Phrase("World")); cellOne.setBorder(Rectangle.NO_BORDER); cellOne.setBackgroundColor(new Color(255,255,45)); cellTwo.setBorder(Rectangle.BOX); table.addCell(cellOne); table.addCell(cellTwo);
protected void addColumnValue(PdfPTable pdfTable, String value) { PdfPCell cell = new PdfPCell(new Paragraph(value, facetFont)); if (facetBgColor != null) { cell.setBackgroundColor(facetBgColor); } pdfTable.addCell(cell); }
Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream("span-in-table.pdf")); document.open(); PdfPTable table = new PdfPTable(3); table.addCell("A"); PdfPCell cell = new PdfPCell(new Phrase("B")); cell.setColspan(2); cell.setRowspan(2); table.addCell(cell); table.addCell("C"); table.addCell("D"); table.addCell("E"); table.addCell("F"); document.add(table); document.close();
Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream("C:/SimplePDF.pdf")); document.open(); document.newPage(); PdfPTable table = new PdfPTable(3); PdfPCell fake = new PdfPCell(); fake.setBorder(Rectangle.NO_BORDER); // Hiding Border table.addCell(fake); PdfPCell c = new PdfPCell(); c.setHorizontalAlignment(Element.ALIGN_LEFT); c.setBorder(Rectangle.NO_BORDER); c.addElement(new Paragraph(string)); table.addCell(c); table.addCell(fake);
public void createPdf(String dest) throws IOException, DocumentException { Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(dest)); document.open(); Anchor target = new Anchor("top"); target.setName("page18"); document.add(target); PdfPTable table = new PdfPTable(1); table.setTotalWidth(500); PdfPCell cell = new PdfPCell(); Paragraph p = new Paragraph(); Anchor anchor = new Anchor("page18 link"); anchor.setReference("#page18"); p.add(anchor); cell.addElement(p); table.addCell(cell); table.writeSelectedRows(0, -1, 36, 700, writer.getDirectContent()); document.close(); }
public static void main(String[] args) throws DocumentException, FileNotFoundException, IOException { String TARGET = "temp.pdf"; Document document = new Document(PageSize.A4); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(TARGET)); document.open(); PdfPTable table = new PdfPTable(7); for (int i = 0; i < 700; i++) { Phrase p = new Phrase("some text"); PdfPCell cell = new PdfPCell(); cell.addElement(p); table.addCell(cell); } table.setTotalWidth(PageSize.A4.getWidth()); table.setLockedWidth(true); PdfContentByte canvas = writer.getDirectContent(); PdfTemplate template = canvas.createTemplate(table.getTotalWidth(), table.getTotalHeight()); table.writeSelectedRows(0, -1, 0, table.getTotalHeight(), template); Image img = Image.getInstance(template); img.scaleToFit(PageSize.A4.getWidth(), PageSize.A4.getHeight()); img.setAbsolutePosition(0, (PageSize.A4.getHeight() - table.getTotalHeight()) / 2); document.add(img); document.close(); }
public void createPdf(String dest) throws IOException, DocumentException { Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(dest)); document.open(); PdfPTable table = new PdfPTable(8); for (int i = 0; i < 8; i++) { PdfPCell cell = new PdfPCell(new Phrase(String.format("May %s, 2016", i + 15))); cell.setRotation(90); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); } for(int i = 0; i < 16; i++){ table.addCell("hi"); } document.add(table); document.close(); }
Document doc = new Document(); PdfWriter.getInstance(doc, new FileOutputStream(RESULT)); doc.open(); PdfPTable mainTable = new PdfPTable(3); PdfPCell cell; PdfPTable table = new PdfPTable(1); if (i < data.length) { cell = new PdfPCell(new Phrase(data[i])); table.addCell(cell); } else { cell = new PdfPCell(new Phrase("")); table.addCell(cell); doc.add(mainTable); doc.newPage(); mainTable = new PdfPTable(3);
Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream("datamatrix.pdf")); document.open(); PdfPTable table = new PdfPTable(2); table.setHorizontalAlignment(Element.ALIGN_LEFT); table.setTotalWidth(100); table.setLockedWidth(true); table.addCell("1"); BarcodeDatamatrix dm = new BarcodeDatamatrix(); dm.generate("1234567890"); Image img = dm.createImage(); PdfPCell cell = new PdfPCell(img, false); cell.setPadding(2); table.addCell(cell);; document.add(table); document.close();
public void createPdf(String dest) throws IOException, DocumentException { Rectangle pagesize = PageSize.LETTER; Document document = new Document(pagesize); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(dest)); document.open(); PdfPTable table = new PdfPTable(2); PdfPCell cell; //Add rows with selectors PdfFormField selectGroup = PdfFormField.createEmpty(writer); selectGroup.setFieldName("myCombos"); String[] options = {"Choose first option", "Choose second option", "Choose third option"}; String[] exports = {"option1", "option2", "option3"}; table.addCell("Combobox:"); cell = new PdfPCell(); cell.setCellEvent(new SelectCellEvent(selectGroup, "combo1", exports, options)); cell.setMinimumHeight(20); table.addCell(cell); document.add(table); writer.addAnnotation(selectGroup); document.close(); }
public void createPdf(String dest) throws IOException, DocumentException { Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(dest)); document.open(); PdfPTable table = new PdfPTable(3); table.setWidthPercentage(100); PdfReader reader = new PdfReader("resources/pdfs/header.pdf"); PdfImportedPage header = writer.getImportedPage(reader, 1); PdfPCell cell = new PdfPCell(Image.getInstance(header)); cell.setColspan(3); table.addCell(cell); for (int row = 1; row <= 50; row++) { for (int column = 1; column <= 3; column++) { table.addCell(String.format("row %s, column %s", row, column)); } } reader = new PdfReader("resources/pdfs/footer.pdf"); PdfImportedPage footer = writer.getImportedPage(reader, 1); cell = new PdfPCell(Image.getInstance(footer)); cell.setColspan(3); table.addCell(cell); document.add(table); document.close(); }
private static final Font headerFont = new Font(Font.FontFamily.TIMES_ROMAN, 9, Font.BOLD, BaseColor.BLACK); Document document = new Document(PageSize.A4, 20, 20, 120, 50); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(realPath + "/PdfTable.pdf")); writer.setBoxSize("art", new Rectangle(36, 54, 559, 788)); HeaderFooterOfPdf event = new HeaderFooterOfPdf(batchDate); writer.setPageEvent(event); document.open(); //to create table PdfPTable vppTable = new PdfPTable(new float[]{3, 7, 9, 3, 5, 3, 3, 3, 4}); vppTable.setWidthPercentage(100f); //pdf table header vppTable.addCell(new PdfPCell(new Phrase("Your column name", headerFont))); vppTable.addCell(new PdfPCell(new Phrase("Your column name", headerFont))); vppTable.setHeaderRows(1); //to add cell data PdfPCell slNoCell = new PdfPCell(new Phrase("your data", contentFont)); slNoCell.setVerticalAlignment(Element.ALIGN_MIDDLE); slNoCell.setPaddingLeft(15f); vppTable.addCell(slNoCell); document.add(vppTable); document.close();
void initTable(List<String> headers, int[] relativeWidths) throws DocumentException { assert headers.size() == relativeWidths.length; final PdfPTable mytable = new PdfPTable(headers.size()); mytable.setWidthPercentage(100); mytable.setWidths(relativeWidths); mytable.setHeaderRows(1); final PdfPCell defaultCell = mytable.getDefaultCell(); defaultCell.setGrayFill(0.9f); defaultCell.setHorizontalAlignment(Element.ALIGN_CENTER); defaultCell.setPaddingLeft(0); defaultCell.setPaddingRight(0); final Font tableHeaderFont = PdfFonts.TABLE_HEADER.getFont(); for (final String header : headers) { mytable.addCell(new Phrase(header, tableHeaderFont)); } defaultCell.setPaddingLeft(2); defaultCell.setPaddingRight(2); this.table = mytable; }
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); }