List of usage examples for com.itextpdf.text Document bottomMargin
public float bottomMargin()
From source file:com.masscustsoft.service.ToPdf.java
License:Open Source License
private Image getImage(Map row) throws Exception { Image image = null;//from w ww. jav a2 s . com String url = (String) row.get("url"); if (url != null) { image = Image.getInstance(url); } String externalId = (String) row.get("externalId"); if (externalId != null) { File tmp = File.createTempFile("tmp", ".image"); InputStream is = getFs().getResource(externalId); FileOutputStream os = new FileOutputStream(tmp); StreamUtil.copyStream(is, os, 0); is.close(); os.close(); image = Image.getInstance(tmp.toURL()); ThreadHelper.postponeDelete(tmp); } String img = (String) row.get("image"); if (img != null) { byte[] bytes = LightStr.getHexContent(img); image = Image.getInstance(bytes); } if (image != null) { MapUtil.setIfFloat(row, "spacingAfter", image); MapUtil.setIfFloat(row, "spacingBefore", image); MapUtil.setIfFloat(row, "scalePercent", image); MapUtil.setIfFloat(row, "scaleDegree", image); Float fitPer = MapUtil.getFloat(row, "fitPercent", null); if (fitPer != null) { Document doc = this.getDoc(); image.scaleToFit( (doc.getPageSize().getWidth() - doc.leftMargin() - doc.rightMargin()) * fitPer / 100f, (doc.getPageSize().getHeight() - doc.topMargin() - doc.bottomMargin()) * fitPer / 100f); } Float fitWidth = MapUtil.getFloat(row, "fitWidth", null); if (fitWidth != null) { Float fitHeight = MapUtil.getFloat(row, "fitHeight", fitWidth); image.scaleToFit(fitWidth, fitHeight); } image.setAlignment(getAlignment(row, "alignment")); } return image; }
From source file:com.skatettoo.reportes.Generador.java
public String generarPDF() throws Exception { try {/* w ww . j a v a 2s . c om*/ String path = FacesContext.getCurrentInstance().getExternalContext().getRealPath("img"); path = path.substring(0, path.indexOf("\\build")); path = path + "\\web\\img\\"; Document doc = new Document(PageSize.A4, 36, 36, 10, 10); PdfPTable tabla = new PdfPTable(4); PdfWriter.getInstance(doc, new FileOutputStream(path + "\\archivo\\reporte.pdf\\")); doc.open(); Image img = Image.getInstance(path + "Skatetoo4.png"); img.scaleAbsolute(40, 40); img.setAlignment(Element.ALIGN_LEFT); doc.add(img); doc.addTitle(this.titulo); doc.addAuthor("\n "); doc.addAuthor("\n "); doc.addAuthor("\n "); doc.addAuthor("\n "); tabla.setWidthPercentage(100); tabla.setWidths(new float[] { 1.4f, 0.8f, 0.8f, 0.8f }); Object font = new Font(Font.FontFamily.HELVETICA, 14, Font.BOLD, BaseColor.WHITE); PdfPCell cell = new PdfPCell(new Phrase("Reporte de tatuadores", (Font) font)); cell.setColspan(4); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setPaddingTop(0f); cell.setPaddingBottom(7f); cell.setBackgroundColor(new BaseColor(0, 0, 0)); cell.setBorder(0); cell.setBorderWidthBottom(2f); tabla.addCell(cell); tabla.addCell("Tatuador"); tabla.addCell("Cantidad de diseos"); tabla.addCell("Citas realizadas"); tabla.addCell("Noticias publicadas"); for (Usuario u : this.getUsu()) { tabla.addCell(u.getNombre() + " " + u.getApellido()); tabla.addCell(String.valueOf(u.getDisenioList().size())); tabla.addCell(String.valueOf(u.getCitaList1().size())); tabla.addCell(String.valueOf(u.getNoticiaList().size())); } doc.add(tabla); doc.bottomMargin(); /* doc.add(new Paragraph("Tatuador mas solicitado")); for(Usuario u : this.getUs()){ doc.add(new Paragraph(u.getNombre() + " " + u.getApellido())); }*/ doc.close(); FacesContext context = FacesContext.getCurrentInstance(); ExternalContext externalContext = context.getExternalContext(); externalContext.responseReset(); externalContext.setResponseContentType("application/pdf"); externalContext.setResponseHeader("Content-Disposition", "attachment;filename=\"reporte.pdf\""); FileInputStream inputStream = new FileInputStream(new File(path + "\\archivo\\reporte.pdf\\")); OutputStream outputStream = externalContext.getResponseOutputStream(); byte[] buffer = new byte[1024]; int length; while ((length = inputStream.read(buffer)) > 0) { outputStream.write(buffer, 0, length); } inputStream.close(); context.responseComplete(); } catch (Exception e) { throw e; } return ""; }
From source file:com.vectorprint.report.itext.EventHelper.java
License:Open Source License
/** * prints debug info when property debug is true, calls renderHeader and renderFooter and * {@link Advanced#draw(com.itextpdf.text.Rectangle, java.lang.String) } with {@link Document#getPageSize() } * and null for {@link DefaultStylerFactory#PAGESTYLERS}. * * @param writer/*from w ww. j a va 2 s .c o m*/ * @param document */ @Override public final void onEndPage(PdfWriter writer, Document document) { super.onEndPage(writer, document); sanitize(writer); try { if (failuresHereAfter || debugHereAfter) { PdfContentByte bg = writer.getDirectContentUnder(); Rectangle rect = writer.getPageSize(); rect.setBackgroundColor(itextHelper .fromColor(getSettings().getColorProperty(new Color(240, 240, 240), "legendbackground"))); bg.rectangle(rect); bg.closePathFillStroke(); } else { for (Advanced a : doForAllPages) { try { if (a.shouldDraw(null)) { a.draw(document.getPageSize(), null); } } catch (VectorPrintException ex) { throw new VectorPrintRuntimeException(ex); } } } if (!debugHereAfter && getSettings().getBooleanProperty(false, DEBUG)) { PdfContentByte canvas = writer.getDirectContent(); Rectangle rect = new Rectangle(document.leftMargin(), document.bottomMargin(), document.right() - document.rightMargin(), document.top() - document.topMargin()); DebugHelper.debugRect(canvas, rect, new float[] { 10, 2 }, 0.3f, getSettings(), stylerFactory.getLayerManager()); } renderHeader(writer, document); maxTagForGenericTagOnPage = ((DefaultElementProducer) elementProducer).getAdvancedTag(); if (getSettings().getBooleanProperty(Boolean.FALSE, ReportConstants.PRINTFOOTER)) { renderFooter(writer, document); } else { log.warning("not printing footer, if you want page footers set " + ReportConstants.PRINTFOOTER + " to true"); } maxTagForGenericTagOnPage = Integer.MAX_VALUE; } catch (VectorPrintException | DocumentException | InstantiationException | IllegalAccessException e) { throw new VectorPrintRuntimeException("failed to create the report header or footer: ", e); } }
From source file:com.vectorprint.report.itext.EventHelper.java
License:Open Source License
/** * prints a footer table with a line at the top, a date and page numbering, second cell will be right aligned * * @see #PAGEFOOTERTABLEKEY//from w ww . java 2s . com * @see #PAGEFOOTERSTYLEKEY * * @param writer * @param document * @throws DocumentException * @throws VectorPrintException */ protected void renderFooter(PdfWriter writer, Document document) throws DocumentException, VectorPrintException, InstantiationException, IllegalAccessException { if (!debugHereAfter && !failuresHereAfter) { PdfPTable footerTable = elementProducer.createElement(null, PdfPTable.class, getStylers(PAGEFOOTERTABLEKEY)); footerTable.addCell(createFooterCell(ValueHelper.createDate(new Date()))); String pageText = writer.getPageNumber() + getSettings().getProperty(" of ", UPTO); PdfPCell c = createFooterCell(pageText); c.setHorizontalAlignment(Element.ALIGN_RIGHT); footerTable.addCell(c); footerTable.addCell(createFooterCell(new Chunk())); footerTable.writeSelectedRows(0, -1, document.getPageSize().getLeft() + document.leftMargin(), document.getPageSize().getBottom(document.bottomMargin()), writer.getDirectContentUnder()); footerBottom = document.bottom() - footerTable.getTotalHeight(); } }
From source file:de.jost_net.JVerein.io.HeaderFooter.java
License:Open Source License
/** * Adds the header and the footer.// w w w.j a v a 2 s . c o m * */ @Override public void onEndPage(PdfWriter writer, Document document) { Rectangle rect = document.getPageSize(); switch (writer.getPageNumber() % 2) { case 0: // ColumnText.showTextAligned(writer.getDirectContent(), // Element.ALIGN_RIGHT, header[0], rect.getRight(), rect.getTop(), 0); break; case 1: // ColumnText.showTextAligned(writer.getDirectContent(), // Element.ALIGN_LEFT, // header[1], rect.getLeft(), rect.getTop(), 0); break; } float left = rect.getLeft() + document.leftMargin(); float right = rect.getRight() - document.rightMargin(); float bottom = rect.getBottom() + document.bottomMargin(); PdfContentByte pc = writer.getDirectContent(); pc.setColorStroke(BaseColor.BLACK); pc.setLineWidth(0.5f); pc.moveTo(left, bottom - 5); pc.lineTo(right, bottom - 5); pc.stroke(); pc.moveTo(left, bottom - 25); pc.lineTo(right, bottom - 25); pc.stroke(); ColumnText.showTextAligned(pc, Element.ALIGN_CENTER, new Phrase(footer + " " + pagenumber, Reporter.getFreeSans(7)), (left + right) / 2, bottom - 18, 0); }
From source file:eu.aniketos.wp1.ststool.report.pdfgenerator.ReportContentFactory.java
License:Open Source License
/******************************************************************************************/ private void buildAppendixAChapter(Chapter c, Document d) { c.setTitle(getChapterTitleParagraph("Appendix A")); c.setNumberDepth(0);/*w w w. j av a2 s. c om*/ c.setTriggerNewPage(true); float width = d.getPageSize().getWidth() - d.leftMargin() - d.rightMargin(); float height = d.getPageSize().getHeight() - d.topMargin() - d.bottomMargin() - 70; if (needSocialDiagramInAppendixA()) { Image socialImage = rsp.generateScrenshot(ViewsManager.SOCIAL_VIEW); socialImage.setAlignment(Element.ALIGN_CENTER); if (socialImage.getPlainWidth() > socialImage.getPlainHeight()) { fitImageInArea(socialImage, height, width, true); socialImage.setRotationDegrees(90); } else { fitImageInArea(socialImage, width, height, true); } c.add(decorateImage(socialImage, ftc.getFigure(FigureConstant.SOCIAL_DIAGRAM) + " - Social View for the " + getProjectName() + " project")); } if (needInformationDiagramInAppendixA()) { Image informationImage = rsp.generateScrenshot(ViewsManager.RESOURCE_VIEW); informationImage.setAlignment(Element.ALIGN_CENTER); if (informationImage.getPlainWidth() > informationImage.getPlainHeight()) { fitImageInArea(informationImage, height, width, true); informationImage.setRotationDegrees(90); } else { fitImageInArea(informationImage, width, height, true); } // c.add(informationImage); c.add(decorateImage(informationImage, ftc.getFigure(FigureConstant.INFORMATION_DIAGRAM) + " - Information View for the " + getProjectName() + " project")); } if (needInformationDiagramInAppendixA()) { Image authorisationImage = rsp.generateScrenshot(ViewsManager.AUTHORIZATION_VIEW); authorisationImage.setAlignment(Element.ALIGN_CENTER); if (authorisationImage.getPlainWidth() > authorisationImage.getPlainHeight()) { fitImageInArea(authorisationImage, height, width, true); authorisationImage.setRotationDegrees(90); } else { fitImageInArea(authorisationImage, width, height, true); } // c.add(authorisationImage); c.add(decorateImage(authorisationImage, ftc.getFigure(FigureConstant.AUTH_DIAGRAM) + " - Authorisation View for the " + getProjectName() + " project")); } c.setComplete(true); }
From source file:generators.InvoiceEventListener.java
@Override public void onEndPage(PdfWriter writer, Document document) { Font defaultFont = new Font(Font.FontFamily.TIMES_ROMAN, 12); try {//from www.j a va 2 s .c o m PdfPTable footerTable = new PdfPTable(3); footerTable.setTotalWidth(document.right(document.leftMargin())); footerTable.getDefaultCell().setBorder(Rectangle.TOP); footerTable.addCell(new Paragraph("Lionsclub Oegstgeest/Warmond", defaultFont)); footerTable.completeRow(); footerTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); footerTable.addCell(new Paragraph("Betaalrekening", defaultFont)); footerTable.addCell(new Paragraph(": ************", defaultFont)); footerTable.completeRow(); footerTable.addCell(new Paragraph("Inschrijvnummer KvK Rijnland", defaultFont)); footerTable.addCell(new Paragraph(": ************ ", defaultFont)); footerTable.completeRow(); footerTable.writeSelectedRows(0, -1, document.leftMargin(), document.bottom(footerTable.getTotalHeight()) - document.bottomMargin() + 15, writer.getDirectContent()); ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_RIGHT, new Phrase(String.format("%d", writer.getPageNumber()), defaultFont), document.right(), document.bottom() - document.bottomMargin() + 18, 0); } catch (Exception e) { e.printStackTrace(); } }
From source file:net.digitstar.vanadio.AbstractReportBase.java
License:Apache License
protected Rect<Float> customizeMargins(Document document) { return new Rect<Float>(document.topMargin(), document.topMargin(), document.rightMargin(), document.bottomMargin()) { @Override//from ww w .jav a 2 s . c o m protected Float zero() { return 0.0f; } }; }
From source file:org.sharegov.cirm.utils.PDFViewReport.java
License:Apache License
public void generateReport(OutputStream out, List<Long> boids) { if (DBG)/* w w w .j a v a 2 s . c o m*/ System.out.println("Start: PDFgenerateReport: for nrOfBoids: " + boids.size()); Document doc = null; try { Date date = new Date(); setTime(formatDate(date, true, false)); doc = new Document(PageSize.A4); doc.setMargins(9, 9, doc.topMargin(), doc.bottomMargin()); PdfWriter writer = PdfWriter.getInstance(doc, out); writer.setPageEvent(new TableHeader()); doc.open(); //addMetaData(doc); LegacyEmulator le = new LegacyEmulator(); int i = 1; for (Long boid : boids) { ThreadLocalStopwatch.getWatch().time("PDFViewReport loading " + i + " of " + boids.size()); Json data = le.findServiceCaseOntology(boid).toJSON(); addContent(doc, data); i++; } } catch (DocumentException e) { e.printStackTrace(); throw new RuntimeException(e); } finally { doc.close(); } if (DBG) System.out.println("Done: PDFgenerateReport: for nrOfBoids: " + boids.size()); }
From source file:org.sharegov.cirm.utils.PDFViewReport.java
License:Apache License
/** * Generates the HET Rebate letter based on the given input parameters * @param out : OutputStream to which the letter is written to * @param applicant : ServiceCaseActor of type Applicant * @param hasCaseNumber : Service Request's Case Number * @param isEnglish : A Flag denoting the language of the letter *//*from ww w. j a v a 2s . co m*/ public void generateHETRebateLetter(OutputStream out, Json applicant, String hasCaseNumber, boolean isEnglish) { if (DBG) System.out.println("Start : generateHETRebateLetter"); Document doc = null; try { doc = new Document(PageSize.A4); doc.setMargins(9, 9, doc.topMargin(), doc.bottomMargin()); PdfWriter writer = PdfWriter.getInstance(doc, out); doc.open(); addWASDContent(doc, applicant, hasCaseNumber, isEnglish); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } finally { doc.close(); if (DBG) System.out.println("End : generateHETRebateLetter"); } }