Paragraph preface = new Paragraph(); preface.add(new Paragraph("Title of the document", catFont)); 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); table.addCell("Date:"); table.addCell("1.1"); table.addCell(""); table.addCell("Labor Rate:"); table.addCell("2.2"); table.addCell(""); table.addCell("Labor Cost:"); table.addCell("3.2"); table.addCell("3.3");
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 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; }
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);
public void createPdf(String dest) throws IOException, DocumentException { Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(dest)); document.open(); PdfPTable table = new PdfPTable(2); table.setWidthPercentage(100); table.setWidths(new int[]{1, 2}); table.addCell(createImageCell(IMG1)); table.addCell(createTextCell("This picture was taken at Java One.\nIt shows the iText crew at Java One in 2013.")); document.add(table); document.close(); }
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); table.setWidths(columnWidths); document.add(table);
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 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 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 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 static final String FONT = "resources/fonts/NotoNaskhArabic-Regular.ttf"; public static final String ARABIC = "\u0627\u0644\u0633\u0639\u0631 \u0627\u0644\u0627\u062c\u0645\u0627\u0644\u064a"; public void createPdf(String dest) throws IOException, DocumentException { Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(dest)); document.open(); Font f = FontFactory.getFont(FONT, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); PdfPTable table = new PdfPTable(1); Phrase phrase = new Phrase(); Chunk chunk = new Chunk("test value"); phrase.add(chunk); phrase.add(new Chunk(ARABIC, f)); PdfPCell cell = new PdfPCell(phrase); cell.setUseDescender(true); cell.setRunDirection(PdfWriter.RUN_DIRECTION_RTL); 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(); }
@Command @NotifyChange("savePDF") public void savePDF() throws IOException, Exception { File f = new File("PDF_test.pdf"); OutputStream file = new FileOutputStream(f); Document document = new Document(); PdfWriter.getInstance(document, file); Filedownload.save(f, "application/pdf"); PdfPTable table=new PdfPTable(3); PdfPCell cell ..... }
/** * Generates the end page for this transaction report * * @see com.lowagie.text.pdf.PdfPageEventHelper#onEndPage(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Document) */ public void onEndPage(PdfWriter writer, Document document) { try { Rectangle page = document.getPageSize(); PdfPTable head = new PdfPTable(3); SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); PdfPCell cell = new PdfPCell(new Phrase(sdf.format(runDate), headerFont)); cell.setBorder(Rectangle.NO_BORDER); head.addCell(cell); cell = new PdfPCell(new Phrase(title, headerFont)); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); head.addCell(cell); cell = new PdfPCell(new Phrase("Page: " + new Integer(writer.getPageNumber()), headerFont)); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); head.addCell(cell); head.setTotalWidth(page.width() - document.leftMargin() - document.rightMargin()); head.writeSelectedRows(0, -1, document.leftMargin(), page.height() - document.topMargin() + head.getTotalHeight(), writer.getDirectContent()); } catch (Exception e) { throw new ExceptionConverter(e); } } }
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); }