List of usage examples for com.itextpdf.text Document leftMargin
public float leftMargin()
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//w w w.j a v a 2s . 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 w w. java 2s . co m*/ * @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:com.vectorprint.report.itext.style.stylers.SimpleColumns.java
License:Open Source License
@Override public void setDocument(Document document, com.itextpdf.text.pdf.PdfWriter writer) { super.setDocument(document, writer); setValue(LEFT, document.leftMargin()); setValue(RIGHT, document.right() - document.rightMargin()); setValue(BOTTOM, getDocument().bottomMargin()); setValue(TOP, getDocument().top() - getDocument().topMargin()); }
From source file:com.vimbox.hr.LicensePDFGenerator.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.// w ww .j a v a 2 s. c om * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/pdf"); String fileName = request.getParameter("license_name"); String ext = fileName.substring(fileName.lastIndexOf(".") + 1); String path = System.getProperty("user.dir") + "/documents/licenses/" + fileName; path = path.replaceAll("%20", " "); if (ext.equalsIgnoreCase("pdf")) { FileInputStream baos = new FileInputStream(path); OutputStream os = response.getOutputStream(); byte buffer[] = new byte[8192]; int bytesRead; while ((bytesRead = baos.read(buffer)) != -1) { os.write(buffer, 0, bytesRead); } os.flush(); os.close(); } else { try { // Document Settings // Document document = new Document(); PdfWriter.getInstance(document, response.getOutputStream()); document.open(); // Loading MC // PdfPTable table = new PdfPTable(1); table.setWidthPercentage(100); // the cell object PdfPCell cell; Image img = Image.getInstance(path); int indentation = 0; float scaler = ((document.getPageSize().getWidth() - document.leftMargin() - document.rightMargin() - indentation) / img.getWidth()) * 100; img.scalePercent(scaler); //img.scaleAbsolute(80f, 80f); cell = new PdfPCell(img); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); document.add(table); //-----------------------------------// document.close(); } catch (DocumentException de) { throw new IOException(de.getMessage()); } } }
From source file:de.jost_net.JVerein.io.HeaderFooter.java
License:Open Source License
/** * Adds the header and the footer./* w ww . j ava 2 s . com*/ * */ @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:edu.cornell.mannlib.vitro.webapp.visualization.visutils.PDFDocument.java
License:Open Source License
private void createTransparencyShapes(Document document, PdfWriter writer) throws Exception { PdfContentByte cb = writer.getDirectContent(); pictureBackdrop(document.leftMargin(), 350, cb); cb.saveState();/*from w w w . j a va2 s . co m*/ PdfGState gs1 = new PdfGState(); gs1.setFillOpacity(0.5f); cb.setGState(gs1); pictureCircles(document.leftMargin(), 350, cb); cb.restoreState(); cb.resetRGBColorFill(); }
From source file:eu.aniketos.wp1.ststool.report.pdfgenerator.ReportContentFactory.java
License:Open Source License
private void buildSectionSocialDiagram(Section section, Document document) { Image i = rsp.generateScrenshot(ViewsManager.SOCIAL_VIEW); float reductionScale = fitImageInArea(i, document.getPageSize().getWidth() - document.rightMargin() - document.leftMargin(), 310, false); if (reductionScale <= getMaximumReductionScale()) { setAppendixASocialDiagram(true); }/*from w ww . j a v a2s. c om*/ StringBuilder sectionIntro = new StringBuilder(); sectionIntro.append(ftc.getFigure(FigureConstant.SOCIAL_DIAGRAM) + " presents the graphical representation of the social view"); if (needSocialDiagramInAppendixA()) { sectionIntro.append(" (a larger picture is shown in appendix A)"); } sectionIntro.append("."); section.add(createParagraph(sectionIntro.toString())); section.add(decorateImage(i, ftc.getFigure(FigureConstant.SOCIAL_DIAGRAM) + " - Social View for the " + getProjectName() + " project")); section.setComplete(true); }
From source file:eu.aniketos.wp1.ststool.report.pdfgenerator.ReportContentFactory.java
License:Open Source License
private void buildSectionInformationViewDiagram(Section section, Document document) { Image i = rsp.generateScrenshot(ViewsManager.RESOURCE_VIEW); float reductionScale = fitImageInArea(i, document.getPageSize().getWidth() - document.rightMargin() - document.leftMargin(), 310, false); if (reductionScale <= getMaximumReductionScale()) { setAppendixAInformationDiagram(true); }/*from w w w .ja v a2s.c o m*/ StringBuilder sectionIntro = new StringBuilder(); sectionIntro.append(ftc.getFigure(FigureConstant.INFORMATION_DIAGRAM) + " presents the graphical representation of the information view"); if (needInformationDiagramInAppendixA()) { sectionIntro.append(" (a larger picture is shown in appendix A)"); } sectionIntro.append("."); section.add(createParagraph(sectionIntro.toString())); section.add(decorateImage(i, ftc.getFigure(FigureConstant.INFORMATION_DIAGRAM) + " - Information View for the " + getProjectName() + " project")); section.setComplete(true); }
From source file:eu.aniketos.wp1.ststool.report.pdfgenerator.ReportContentFactory.java
License:Open Source License
private void buildSectionAuthorisationDiagram(Section section, Document document) { Image i = rsp.generateScrenshot(ViewsManager.AUTHORIZATION_VIEW); float reductionScale = fitImageInArea(i, document.getPageSize().getWidth() - document.rightMargin() - document.leftMargin(), 310, false); if (reductionScale <= getMaximumReductionScale()) { setAppendixASocialDiagram(true); }/*from w w w . j a va 2s . c om*/ StringBuilder sectionIntro = new StringBuilder(); sectionIntro.append(ftc.getFigure(FigureConstant.AUTH_DIAGRAM) + " presents the graphical representation of the Authorisation view"); if (needAuthorisationDiagramInAppendixA()) { sectionIntro.append(" (a larger picture is rappresented in appendix A)"); } sectionIntro.append("."); section.add(createParagraph(sectionIntro.toString())); section.add(decorateImage(i, ftc.getFigure(FigureConstant.AUTH_DIAGRAM) + " - Authorisation View for the " + getProjectName() + " project")); section.setComplete(true); }
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);/*from w w w . j a va 2 s. c o m*/ 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); }