List of usage examples for com.itextpdf.text Document left
public float left()
From source file:bouttime.report.boutsheet.BoutSheetReport.java
License:Open Source License
/** * Add the header string to the document. * @param writer PdfWriter object to use. * @param document Document object to add the header to. *///from w w w.j a v a 2 s.co m private void addHeader(PdfWriter writer, Document document) { if (this.headerString == null) { return; } PdfContentByte cb = writer.getDirectContent(); float textBase = document.top() + 5; cb.beginText(); cb.setFontAndSize(this.baseFont, 12); cb.setTextMatrix(document.left(), textBase); cb.showText(this.headerString); cb.endText(); }
From source file:com.afrisoftech.lib.HeaderFooterHelper.java
public void onEndPage(PdfWriter writer, Document document) { PdfContentByte cb = writer.getDirectContent(); // Phrase header = new Phrase("this is a header", ffont); // Phrase footer = new Phrase("this is a footer", ffont); ColumnText.showTextAligned(cb, Element.ALIGN_CENTER, header, (document.right() - document.left()) / 2 + document.leftMargin(), document.top() + 10, 0); ColumnText.showTextAligned(cb, Element.ALIGN_CENTER, new Phrase(footer.getContent() + " " + String.valueOf(writer.getPageNumber())), (document.right() - document.left()) / 2 + document.leftMargin(), document.bottom() - 10, 0); }
From source file:com.athena.chameleon.engine.core.PDFCommonEventHelper.java
License:Apache License
/** * chapter write /* w w w .j a v a2 s .com*/ */ public void onChapter(PdfWriter writer, Document document, float position, Paragraph title) { titles.add( getTocParagraph(title.getContent(), writer.getPageNumber(), 0, document.left(), document.right())); }
From source file:com.athena.chameleon.engine.core.PDFCommonEventHelper.java
License:Apache License
/** * Section write //from w w w . java 2 s. co m */ public void onSection(PdfWriter writer, Document document, float position, int depth, Paragraph title) { title = getTocParagraph(title.getContent(), writer.getPageNumber(), depth, document.left(), document.right()); title.setIndentationLeft(12 * depth); titles.add(title); }
From source file:com.bdaum.zoom.ui.internal.dialogs.ExhibitionEditDialog.java
License:Open Source License
private void writeDocument(Document document, File targetFile) { boolean frame = detailTabfolder.getSelectionIndex() == 1; try (FileOutputStream out = new FileOutputStream(targetFile)) { PdfWriter writer = PdfWriter.getInstance(document, out); document.open();//from w ww. j a v a 2s . c o m writer.setPageEvent(new PdfPageEventHelper() { int pageNo = 0; com.itextpdf.text.Font ffont = new com.itextpdf.text.Font( com.itextpdf.text.Font.FontFamily.HELVETICA, 9, com.itextpdf.text.Font.NORMAL, BaseColor.DARK_GRAY); @Override public void onEndPage(PdfWriter w, Document d) { PdfContentByte cb = w.getDirectContent(); Phrase footer = new Phrase(String.valueOf(++pageNo), ffont); ColumnText.showTextAligned(cb, Element.ALIGN_CENTER, footer, (document.right() - document.left()) / 2 + document.leftMargin(), document.bottom(), 0); } }); String tit = NLS.bind(Messages.ExhibitionEditDialog_exhibition_name, nameField.getText()); Paragraph p = new Paragraph(tit, FontFactory.getFont(FontFactory.HELVETICA, 14, com.itextpdf.text.Font.BOLD, BaseColor.BLACK)); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingAfter(8); document.add(p); String subtitle = NLS.bind(Messages.ExhibitionEditDialog_image_list, Constants.DFDT.format(new Date()), frame ? Messages.ExhibitionEditDialog_image_sizes : Messages.ExhibitionEditDialog_frame_sizes); p = new Paragraph(subtitle, FontFactory.getFont(FontFactory.HELVETICA, 10, com.itextpdf.text.Font.NORMAL, BaseColor.BLACK)); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingAfter(14); document.add(p); p = new Paragraph(descriptionField.getText(), FontFactory.getFont(FontFactory.HELVETICA, 10, com.itextpdf.text.Font.NORMAL, BaseColor.BLACK)); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingAfter(10); document.add(p); p = new Paragraph(infoField.getText(), FontFactory.getFont(FontFactory.HELVETICA, 10, com.itextpdf.text.Font.NORMAL, BaseColor.BLACK)); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingAfter(10); document.add(p); IDbManager db = Core.getCore().getDbManager(); List<Wall> walls = current.getWall(); Wall[] sortedWalls = walls.toArray(new Wall[walls.size()]); Arrays.sort(sortedWalls, new Comparator<Wall>() { public int compare(Wall o1, Wall o2) { return o1.getLocation().compareToIgnoreCase(o2.getLocation()); } }); for (Wall wall : sortedWalls) { p = new Paragraph(wall.getLocation(), FontFactory.getFont(FontFactory.HELVETICA, 12, com.itextpdf.text.Font.BOLD, BaseColor.BLACK)); p.setAlignment(Element.ALIGN_LEFT); p.setSpacingAfter(12); document.add(p); PdfPTable table = new PdfPTable(7); // table.setBorderWidth(1); // table.setBorderColor(new Color(224, 224, 224)); // table.setPadding(5); // table.setSpacing(0); table.setWidths(new int[] { 8, 33, 13, 13, 20, 13, 20 }); table.addCell(createTableHeader(Messages.ExhibitionEditDialog_No, Element.ALIGN_RIGHT)); table.addCell(createTableHeader(Messages.ExhibitionEditDialog_title, Element.ALIGN_LEFT)); table.addCell(createTableHeader(Messages.ExhibitionEditDialog_xpos, Element.ALIGN_RIGHT)); table.addCell(createTableHeader(Messages.ExhibitionEditDialog_height, Element.ALIGN_RIGHT)); table.addCell(createTableHeader(Messages.ExhibitionEditDialog_size, Element.ALIGN_RIGHT)); table.addCell(createTableHeader(Messages.ExhibitionEditDialog_dpi, Element.ALIGN_RIGHT)); table.addCell(createTableHeader("", Element.ALIGN_LEFT)); //$NON-NLS-1$ // table.endHeaders(); List<ExhibitImpl> exhibits = new ArrayList<ExhibitImpl>(); for (String exhibitId : wall.getExhibit()) { ExhibitImpl exhibit = db.obtainById(ExhibitImpl.class, exhibitId); if (exhibit != null) exhibits.add(exhibit); } Collections.sort(exhibits, new Comparator<ExhibitImpl>() { public int compare(ExhibitImpl e1, ExhibitImpl e2) { return ((Exhibit) e1).getX() - ((Exhibit) e2).getX(); } }); int no = 1; for (ExhibitImpl exhibit : exhibits) { int tara = computeTara(frame, exhibit); table.addCell(createTableCell(String.valueOf(no++), Element.ALIGN_RIGHT)); table.addCell(createTableCell(exhibit.getTitle(), Element.ALIGN_LEFT)); af.setMaximumFractionDigits(2); af.setMinimumFractionDigits(2); String x = af.format((exhibit.getX() - tara) / 1000d); table.addCell(createTableCell(NLS.bind("{0} m", x), Element.ALIGN_RIGHT)); //$NON-NLS-1$ String y = af.format((exhibit.getY() + tara) / 1000d); table.addCell(createTableCell(NLS.bind("{0} m", y), Element.ALIGN_RIGHT)); //$NON-NLS-1$ af.setMaximumFractionDigits(1); af.setMinimumFractionDigits(1); String h = af.format((exhibit.getHeight() + 2 * tara) / 10d); int width = exhibit.getWidth(); String w = af.format((width + 2 * tara) / 10d); table.addCell(createTableCell(NLS.bind("{0} x {1} cm", w, h), Element.ALIGN_RIGHT)); //$NON-NLS-1$ AssetImpl asset = dbManager.obtainAsset(exhibit.getAsset()); if (asset != null) { int pixels = asset.getWidth(); double dpi = pixels * 25.4d / width; table.addCell(createTableCell(String.valueOf((int) dpi), Element.ALIGN_RIGHT)); } else table.addCell(""); //$NON-NLS-1$ table.addCell(createTableCell(exhibit.getSold() ? Messages.ExhibitionEditDialog_sold : "", //$NON-NLS-1$ Element.ALIGN_LEFT)); } document.add(table); } document.close(); } catch (DocumentException e) { UiActivator.getDefault().logError(Messages.ExhibitionEditDialog_internal_error_writing_pdf, e); } catch (IOException e) { UiActivator.getDefault().logError(Messages.ExhibitionEditDialog_io_error_writing_pdf, e); } }
From source file:com.softwaremagico.tm.pdf.complete.events.FooterEvent.java
License:Open Source License
/** * Adds a footer to every page//from w w w .java2 s .c o m * * @see com.itextpdf.text.pdf.PdfPageEventHelper#onEndPage(com.itextpdf.text.pdf.PdfWriter, * com.itextpdf.text.Document) */ @Override public void onEndPage(PdfWriter writer, Document document) { if (writer.getPageNumber() % 2 == 0) { PdfContentByte cb = writer.getDirectContent(); Phrase footer = new Phrase( "Created using 'Think Machine'" + (Version.getVersion() != null ? " v" + Version.getVersion() : ""), new Font(FadingSunsTheme.getFooterFont(), FadingSunsTheme.FOOTER_FONT_SIZE)); ColumnText.showTextAligned(cb, Element.ALIGN_CENTER, footer, (document.right() - document.left()) / 2 + document.leftMargin(), document.bottom() + 20, 0); } }
From source file:com.softwaremagico.tm.pdf.complete.events.PartyFooterEvent.java
License:Open Source License
/** * Adds a footer to every page// w w w .j av a 2 s . c om * * @see com.itextpdf.text.pdf.PdfPageEventHelper#onEndPage(com.itextpdf.text.pdf.PdfWriter, * com.itextpdf.text.Document) */ @Override public void onEndPage(PdfWriter writer, Document document) { PdfContentByte cb = writer.getDirectContent(); Phrase footer = new Phrase( party.getPartyName() + " - Created using 'Think Machine'" + (Version.getVersion() != null ? " v" + Version.getVersion() : ""), new Font(FadingSunsTheme.getFooterFont(), FadingSunsTheme.FOOTER_FONT_SIZE)); ColumnText.showTextAligned(cb, Element.ALIGN_CENTER, footer, (document.right() - document.left()) / 2 + document.leftMargin(), document.bottom() + bottomMargin, 0); }
From source file:com.tomasz.drag.triballocommanderro.controller.MakerPDF.java
public static void printToPDF(ArrayList<Person> workers, EventGig event) throws IOException, DocumentException { String filename = event.getName() + ".pdf"; String path = event.getData() + " " + event.getName() + "//"; Document document = new Document(); // step 2// w w w . j a v a2 s .co m PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(path + filename)); // step 3 document.open(); // step 4 ColumnText column = new ColumnText(writer.getDirectContent()); float[][] x = { { document.left(), document.left() + 230 }, { document.right() - 230, document.right() } }; for (Person person : workers) { column.addElement(MakerPDF.createTable(person, event)); } int count = 0; float height = 0; int status = ColumnText.START_COLUMN; while (ColumnText.hasMoreText(status)) { column.setSimpleColumn(x[count][0], document.bottom(), x[count][1], document.top() - height - 10); // render as much content as possible status = column.go(); // go to a new page if you've reached the last column if (++count > 1) { count = 0; document.newPage(); } } document.newPage(); document.close(); }
From source file:eyeofthetiger.utils.PDFDossardGenerator.java
public void createPdf(List<Participant> participants, OutputStream out) throws IOException, DocumentException { sortParticipants(participants);//from w ww.j a va 2 s . c o m Document document = new Document(PageSize.A4.rotate()); float margin = CentimeterToUserSpace(marginCm); document.setMargins(margin, margin, margin, margin); PdfWriter writer = PdfWriter.getInstance(document, out); document.open(); PdfContentByte cb = writer.getDirectContent(); PdfReader pdfBackgroundReader = null; PdfImportedPage backgroundPage = null; if (pdfBackground != null && (new File(pdfBackground)).exists() && (new File(pdfBackground)).isFile()) { pdfBackgroundReader = new PdfReader(pdfBackground); backgroundPage = writer.getImportedPage(pdfBackgroundReader, 1); } float documentTop = document.top(); float documentBottom = document.bottom(); float documentHeight = documentTop - documentBottom; float left = document.left(); float right = document.right(); float width = right - left; float height = documentTop - documentBottom; //cb.rectangle(left, documentBottom, width, documentHeight); //cb.stroke(); boolean logoLeftExist = (new File(logoLeft)).exists() && (new File(logoLeft)).isFile(); boolean logoRightExist = (new File(logoRight)).exists() && (new File(logoRight)).isFile(); float imgLeftRight = left; float imgLeftBottom = documentTop; float imgRightLeft = right; float imgRighBottom = documentTop; Image imgLeft = null; Image imgRight = null; if (exportLogos) { if (logoLeftExist) { imgLeft = Image.getInstance(logoLeft); float h = imgLeft.getHeight(); float w = imgLeft.getWidth(); float nw = width * logoLeftWidth; float nh = (h / w) * nw; imgLeft.scaleAbsolute(nw, nh); //img.scaleAbsoluteHeight(img.getScaledWidth() / xyRatio); imgLeft.setAbsolutePosition(left, documentTop - imgLeft.getScaledHeight()); //cb.addImage(img); imgLeftRight = imgLeft.getAbsoluteX() + imgLeft.getScaledWidth(); imgLeftBottom = imgLeft.getAbsoluteY(); } if (logoRightExist) { imgRight = Image.getInstance(logoRight); float h = imgRight.getHeight(); float w = imgRight.getWidth(); float nw = width * logoRightWidth; float nh = (h / w) * nw; imgRight.scaleAbsolute(nw, nh); imgRight.setAbsolutePosition(right - imgRight.getScaledWidth(), documentTop - imgRight.getScaledHeight()); //cb.addImage(imgRight); imgRightLeft = imgRight.getAbsoluteX(); imgRighBottom = imgRight.getAbsoluteY(); } } float nameHeightPercent = 0.35f; float groupHeightPercent = 0.25f; float nameTop = documentTop; float nameBottom = nameTop; if (exportName) { nameBottom = nameTop - (documentHeight * nameHeightPercent); } float groupeTop = nameBottom; float groupeBottom = nameBottom; if (exportGroup) { groupeBottom = groupeTop - (documentHeight * groupHeightPercent); } float barcodeTop = groupeBottom; float barcodeBottom = documentBottom; ColumnText columnText; for (Participant participant : participants) { if (backgroundPage != null) { //cb.addTemplate(backgroundPage, 1f, 0, 0, 1, 0, 0); //TODO cb.addTemplate(backgroundPage, 0, 0); } float nameFontSize = 65f; float groupFontSize = 45f; float renseignementFontSize = 35f; if (imgLeft != null) { cb.addImage(imgLeft); } if (imgRight != null) { cb.addImage(imgRight); } if (exportName) { columnText = new ColumnText(cb); columnText.setAlignment(Rectangle.ALIGN_CENTER); if (imgLeftRight != -1 && imgLeftBottom != -1) { float[] leftBorder = null; if (imgLeftBottom < nameBottom) { leftBorder = new float[] { imgLeftRight, nameTop, imgLeftRight, nameBottom, left, nameBottom }; } else { leftBorder = new float[] { imgLeftRight, nameTop, imgLeftRight, imgLeftBottom, left, imgLeftBottom, left, nameBottom }; } float[] rightBorder = null; if (imgRighBottom < nameBottom) { rightBorder = new float[] { imgRightLeft, nameTop, imgRightLeft, nameBottom, right, nameBottom }; } else { rightBorder = new float[] { imgRightLeft, nameTop, imgRightLeft, imgRighBottom, right, imgRighBottom, right, nameBottom }; } columnText.setColumns(leftBorder, rightBorder); } else { columnText.setSimpleColumn(left, nameTop, right, nameBottom); } //cb.rectangle(left, nameBottom, width, (nameTop - nameBottom)); //cb.stroke(); columnText.setExtraParagraphSpace(0f); columnText.setAdjustFirstLine(false); columnText.setIndent(0); String txt = participant.getNom().toUpperCase() + " " + participant.getPrenom(); float previousPos = columnText.getYLine(); columnText.setLeading(nameFontSize); columnText.setText(createCleanPhrase(txt, nameFontSize, true)); while (nameFontSize > 1 && ColumnText.hasMoreText(columnText.go(true))) { nameFontSize = nameFontSize - 0.5f; columnText.setLeading(nameFontSize); columnText.setText(createCleanPhrase(txt, nameFontSize, true)); columnText.setYLine(previousPos); } columnText.setLeading(nameFontSize); columnText.setText(createCleanPhrase(txt, nameFontSize, true)); columnText.setYLine(previousPos); columnText.go(false); } if (exportGroup) { columnText = new ColumnText(cb); columnText.setAlignment(Rectangle.ALIGN_CENTER); columnText.setSimpleColumn(document.left(), groupeTop, document.right(), groupeBottom); float groupeHeight = groupeTop - groupeBottom; //cb.rectangle(document.left(), groupeTop - groupeHeight, document.right() - document.left(), groupeHeight); //cb.stroke(); columnText.setExtraParagraphSpace(0f); columnText.setAdjustFirstLine(false); columnText.setIndent(0); columnText.setFollowingIndent(0); String txt1 = participant.getGroupe(); String txt2 = exportRenseignement ? "\n" + participant.getRenseignements() : null; float previousPos = columnText.getYLine(); columnText.setText(null); columnText.setLeading(groupFontSize); columnText.addText(createCleanPhrase(txt1, groupFontSize, true)); columnText.addText(createCleanPhrase(txt2, renseignementFontSize, false)); while (groupFontSize > 1 && ColumnText.hasMoreText(columnText.go(true))) { groupFontSize = groupFontSize - 0.5f; renseignementFontSize = renseignementFontSize - 0.5f; columnText.setText(null); columnText.setLeading(groupFontSize); columnText.addText(createCleanPhrase(txt1, groupFontSize, true)); columnText.addText(createCleanPhrase(txt2, renseignementFontSize, false)); columnText.setYLine(previousPos); } columnText.setText(null); columnText.setLeading(groupFontSize); columnText.addText(createCleanPhrase(txt1, groupFontSize, true)); columnText.addText(createCleanPhrase(txt2, renseignementFontSize, false)); columnText.setYLine(previousPos); columnText.go(false); } { columnText = new ColumnText(cb); float topMargin = 12f; columnText.setSimpleColumn(left, barcodeTop - topMargin, right, barcodeBottom); float barcodeHeight = (barcodeTop - topMargin) - barcodeBottom; //cb.rectangle(left, barcodeTop - barcodeHeight, width, barcodeHeight); //cb.stroke(); columnText.setExtraParagraphSpace(0f); columnText.setAdjustFirstLine(false); columnText.setIndent(0); float previousPos = columnText.getYLine(); columnText.setText(null); columnText.addElement(createCleanBarcode(cb, participant.getNumero(), width, barcodeHeight)); columnText.go(false); } document.newPage(); } document.close(); if (pdfBackgroundReader != null) { pdfBackgroundReader.close(); } }
From source file:fll.web.report.ReportPageEventHandler.java
License:Open Source License
@Override // initialization of the header table public void onEndPage(final PdfWriter writer, final Document document) { final PdfPTable header = new PdfPTable(2); final Phrase p = new Phrase(); final Chunk ck = new Chunk(_challengeTitle + "\n" + _reportTitle, _font); p.add(ck);//w w w . jav a 2 s . c om header.getDefaultCell().setBorderWidth(0); header.addCell(p); header.getDefaultCell().setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_RIGHT); header.addCell(new Phrase(new Chunk("Tournament: " + _tournament + "\nDate: " + _formattedDate, _font))); final PdfPCell blankCell = new PdfPCell(); blankCell.setBorder(0); blankCell.setBorderWidthTop(1.0f); blankCell.setColspan(2); header.addCell(blankCell); final PdfContentByte cb = writer.getDirectContent(); cb.saveState(); header.setTotalWidth(document.right() - document.left()); header.writeSelectedRows(0, -1, document.left(), document.getPageSize().getHeight() - 10, cb); cb.restoreState(); }