List of usage examples for com.lowagie.text Document leftMargin
public float leftMargin()
From source file:cz.incad.kramerius.rest.api.k5.client.pdf.PDFResource.java
License:Open Source License
private static StreamingOutput streamingOutput(final File file, final String format) { return new StreamingOutput() { public void write(OutputStream output) throws IOException, WebApplicationException { try { Rectangle formatRect = formatRect(format); Document document = new Document(formatRect); PdfWriter.getInstance(document, output); document.open();//w ww . ja va 2 s . co m Image image = Image.getInstance(file.toURI().toURL()); image.scaleToFit( document.getPageSize().getWidth() - document.leftMargin() - document.rightMargin(), document.getPageSize().getHeight() - document.topMargin() - document.bottomMargin()); document.add(image); document.close(); } catch (Exception e) { throw new WebApplicationException(e); } finally { if (file != null) file.delete(); } } }; }
From source file:jdbreport.model.io.pdf.itext2.PdfWriter.java
License:Apache License
private int saveSheet(Document document, int listCount, ReportModel model) throws DocumentException, IOException, SaveReportException { model.updatePages(0);// w w w . j a va2 s .c o m ReportPage pageFormat = model.getReportPage(); Paper paper = pageFormat.getPaper(); Rectangle pageSize = new Rectangle(Math.round((float) paper.getWidth()), Math.round((float) paper.getHeight())); if (pageFormat.getOrientation() == ReportPage.LANDSCAPE) { pageSize = pageSize.rotate(); } document.setPageSize(pageSize); document.setMargins(Math.round((float) pageFormat.getLeftMargin(Units.PT)), Math.round((float) pageFormat.getRightMargin(Units.PT)), Math.round((float) pageFormat.getTopMargin(Units.PT)), Math.round((float) pageFormat.getBottomMargin(Units.PT))); Rectangle viewPageSize = new Rectangle( document.getPageSize().getWidth() - document.leftMargin() - document.rightMargin(), document.getPageSize().getHeight() - document.topMargin() - document.bottomMargin()); if (listCount > 0) { document.newPage(); } listCount++; //float columnMargin = (float) Units.PT.setXPixels(model.getColumnModel().getColumnMargin()); ReportPrintable printable = new ReportPrintable(model); int pageCount = printable.calcCountPage(model.getReportPage()); Map<Integer, PageClip> clips = printable.getPageClips(); int leftCol; int topRow; int rightCol; int bottomRow; for (int pageIndex = 0; pageIndex < pageCount; pageIndex++) { PageClip pageClip = clips.get(pageIndex); if (pageClip == null) break; leftCol = pageClip.getLeftCol(); rightCol = pageClip.getRightCol(); topRow = pageClip.getTopRow(); bottomRow = pageClip.getBottomRow(); int columnCount = rightCol - leftCol; float[] widths = new float[columnCount + 1]; widths[0] = 1; for (int c = 0; c < columnCount; c++) { ReportColumn column = (ReportColumn) model.getColumnModel().getColumn(leftCol + c); widths[c + 1] = (float) Math.round(column.getNativeWidth()); } PdfPTable table = createPdfTable(columnCount + 1, widths, viewPageSize); fillTable(model, leftCol, topRow, rightCol, bottomRow, table); document.add(table); if (pageIndex < clips.size()) { document.newPage(); } } return listCount; }
From source file:nl.knaw.dans.common.lang.pdf.PdfPageLayouter.java
License:Apache License
private float getCenterX(final Document document) { return (document.right() - document.left()) / 2 + document.leftMargin(); }
From source file:org.activityinfo.server.report.renderer.itext.ItextChartRenderer.java
License:Open Source License
@Override public void render(DocWriter writer, Document doc, PivotChartReportElement element) throws DocumentException { doc.add(ThemeHelper.elementTitle(element.getTitle())); ItextRendererHelper.addFilterDescription(doc, element.getContent().getFilterDescriptions()); ItextRendererHelper.addDateFilterDescription(doc, element.getFilter().getDateRange()); if (element.getContent().getData().isEmpty()) { Paragraph para = new Paragraph(I18N.CONSTANTS.noData()); para.setFont(new Font(Font.HELVETICA, 12, Font.NORMAL, new Color(0, 0, 0))); doc.add(para);//from w ww .j a v a 2s .co m } else { float width = doc.getPageSize().getWidth() - doc.rightMargin() - doc.leftMargin(); float height = (doc.getPageSize().getHeight() - doc.topMargin() - doc.bottomMargin()) / 3f; renderImage(writer, doc, element, width, height); } }
From source file:org.activityinfo.server.report.renderer.itext.ItextPivotTableRenderer.java
License:Open Source License
private float[] calcColumnWidths(Document doc, PivotTableData data, List<PivotTableData.Axis> leafColumns) { float[] widths = new float[leafColumns.size() + 1]; float tableWidth = doc.getPageSize().getWidth() - doc.leftMargin() - doc.rightMargin(); float valueColumnWidth = 47f; widths[0] = tableWidth - (leafColumns.size() * valueColumnWidth); if (widths[0] < valueColumnWidth) { widths[0] = valueColumnWidth;/*from w w w . ja va2 s .c o m*/ } for (int i = 1; i != widths.length; ++i) { widths[i] = valueColumnWidth; } return widths; }
From source file:org.cyberoam.iview.charts.Chart.java
License:Open Source License
/** * This Event handler Method adds Header and Footer in PDF File *//* w ww. j av a 2s.c o m*/ public void onEndPage(PdfWriter writer, Document document) { try { if (document.getPageNumber() > 1) { String seperator = System.getProperty("file.separator"); //String path=System.getProperty("catalina.home") +seperator+"webapps" +seperator+"ROOT" + seperator + "images" + seperator; String path = InitServlet.contextPath + seperator + "images" + seperator; Image imgHead = Image.getInstance(path + "iViewPDFHeader.JPG"); Image imgFoot = Image.getInstance(path + "iViewPDFFooter.JPG"); Rectangle page = document.getPageSize(); PdfPTable head = new PdfPTable(1); head.addCell(imgHead); head.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin()); head.writeSelectedRows(0, -1, document.leftMargin() - 10, page.getHeight() - document.topMargin() + head.getTotalHeight(), writer.getDirectContent()); PdfPTable foot = new PdfPTable(1); foot.addCell(imgFoot); foot.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin()); foot.writeSelectedRows(0, -1, document.leftMargin() - 10, document.bottomMargin() + 24, writer.getDirectContent()); } } catch (Exception e) { throw new ExceptionConverter(e); } }
From source file:org.dgl.imgstopdf.Main.java
public static void main(String[] args) { Document document = new Document(); ArrayList<String> input; String output = ".\\out.pdf"; try {//from w w w . j a v a 2 s . com FileOutputStream fos = new FileOutputStream(output); PdfWriter pdfWriter = PdfWriter.getInstance(document, fos); Image image; JFileChooser fc = new JFileChooser(".\\"); fc.setMultiSelectionEnabled(true); FileNameExtensionFilter filter = new FileNameExtensionFilter("IMAGES", "jpg", "jpeg", "gif", "png", "bmp"); fc.setFileFilter(filter); int userOption = fc.showOpenDialog(null); if (userOption == JFileChooser.APPROVE_OPTION) { input = new ArrayList<String>(); for (File f : fc.getSelectedFiles()) { input.add(f.getAbsolutePath()); } if (fc.getSelectedFile() != null) { input.add(fc.getSelectedFile().getAbsolutePath()); } } else { return; } if (input.size() == 0) { return; } pdfWriter.open(); document.open(); for (Object fileName : input.toArray()) { image = Image.getInstance((String) fileName); float scaler = ((document.getPageSize().getWidth() - document.leftMargin() - document.rightMargin()) / image.getWidth()) * 100; image.scalePercent(scaler); document.add(image); } document.close(); pdfWriter.close(); JOptionPane.showMessageDialog(null, "OK", "", JOptionPane.INFORMATION_MESSAGE); } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(null, ex.toString(), "", JOptionPane.ERROR_MESSAGE); } }
From source file:org.drools.verifier.doc.DroolsDocsComponentFactory.java
License:Apache License
public void onEndPage(PdfWriter writer, Document document) { try {//from w w w.ja va 2s . c o m Image image = Image.getInstance(DroolsDocsBuilder.class.getResource("guvnor-webapp.png")); // TODO this image never existed image.setAlignment(Image.RIGHT); image.scaleAbsolute(100, 30); Rectangle page = document.getPageSize(); PdfPTable head = new PdfPTable(2); PdfPCell cell1 = new PdfPCell(image); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell1.setBorder(0); head.addCell(cell1); PdfPCell cell2 = new PdfPCell(new Phrase(currentDate, DroolsDocsComponentFactory.HEADER_FOOTER_TEXT)); cell2.setHorizontalAlignment(Element.ALIGN_RIGHT); cell2.setBorder(0); head.addCell(cell2); head.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin()); head.writeSelectedRows(0, -1, document.leftMargin(), page.getHeight() - document.topMargin() + head.getTotalHeight(), writer.getDirectContent()); } catch (Exception e) { throw new ExceptionConverter(e); } }
From source file:org.goodoldai.jeff.report.pdf.PDFImageChunkBuilder.java
License:Open Source License
/** * This method transforms an image explanation chunk into a PDF report * piece and writes this piece into the provided output stream which is, in * this case, an instance of com.lowagie.text.Document. The method first * collects all general chunk data (context, rule, group, tags) and inserts * them into the report, and then retrieves the chunk content. Since the * content is, in this case, an ImageData instance, the image it relates to * (caption and URL) gets inserted into the report. If the image caption is * missing, it doesn't get inserted into the report. * * @param echunk image explanation chunk that needs to be transformed * @param stream output stream to which the transformed chunk will be * written as output (in this case com.lowagie.text.Document) * @param insertHeaders denotes if chunk headers should be inserted into the * report (true) or not (false)/* www . j ava 2 s. co m*/ * * @throws org.goodoldai.jeff.explanation.ExplanationException if any of the arguments are * null, if the entered chunk is not an ImageExplanationChunk instance or * if the entered output stream type is not com.lowagie.text.Document */ public void buildReportChunk(ExplanationChunk echunk, Object stream, boolean insertHeaders) { if (echunk == null) { throw new ExplanationException("The entered chunk must not be null"); } if (stream == null) { throw new ExplanationException("The entered stream must not be null"); } if (!(echunk instanceof ImageExplanationChunk)) { throw new ExplanationException("The entered chunk must be an ImageExplanationChunk instance"); } if (!(stream instanceof com.lowagie.text.Document)) { throw new ExplanationException("The entered stream must be a com.lowagie.text.Document instance"); } com.lowagie.text.Document doc = ((com.lowagie.text.Document) stream); //Insert general chunk data if (insertHeaders) PDFChunkUtility.insertChunkHeader(echunk, doc); try { //Insert content - in this case an image ImageData imdata = (ImageData) (echunk.getContent()); //Get image data Image img = Image.getInstance(getClass().getResource(imdata.getURL())); //Scale the image in order to fit the page img.scaleToFit(doc.getPageSize().getRight(doc.leftMargin() + doc.rightMargin()), doc.getPageSize().getTop(doc.topMargin() + doc.bottomMargin())); //Add image doc.add(img); //If a caption is present, insert it below the image if ((imdata.getCaption() != null) && (!imdata.getCaption().equals(""))) { doc.add(new Paragraph("IMAGE: " + imdata.getCaption())); } } catch (NullPointerException e) { throw new ExplanationException( "The image '" + ((ImageData) (echunk.getContent())).getURL() + "' could not be found"); } catch (Exception e) { throw new ExplanationException(e.getMessage()); } }
From source file:org.goodoldai.jeff.report.pdf.RTFImageChunkBuilder.java
License:Open Source License
/** * This method transforms an image explanation chunk into a PDF report * piece and writes this piece into the provided output stream which is, in * this case, an instance of com.lowagie.text.Document. The method first * collects all general chunk data (context, rule, group, tags) and inserts * them into the report, and then retrieves the chunk content. Since the * content is, in this case, an ImageData instance, the image it relates to * (caption and URL) gets inserted into the report. If the image caption is * missing, it doesn't get inserted into the report. * * @param echunk image explanation chunk that needs to be transformed * @param stream output stream to which the transformed chunk will be * written as output (in this case com.lowagie.text.Document) * @param insertHeaders denotes if chunk headers should be inserted into the * report (true) or not (false)// w w w . ja va2 s . c om * * @throws org.goodoldai.jeff.explanation.ExplanationException if any of the arguments are * null, if the entered chunk is not an ImageExplanationChunk instance or * if the entered output stream type is not com.lowagie.text.Document */ public void buildReportChunk(ExplanationChunk echunk, Object stream, boolean insertHeaders) { if (echunk == null) { throw new ExplanationException("The entered chunk must not be null"); } if (stream == null) { throw new ExplanationException("The entered stream must not be null"); } if (!(echunk instanceof ImageExplanationChunk)) { throw new ExplanationException("The entered chunk must be an ImageExplanationChunk instance"); } if (!(stream instanceof com.lowagie.text.Document)) { throw new ExplanationException("The entered stream must be a com.lowagie.text.Document instance"); } com.lowagie.text.Document doc = ((com.lowagie.text.Document) stream); //Insert general chunk data if (insertHeaders) RTFChunkUtility.insertChunkHeader(echunk, doc); try { //Insert content - in this case an image ImageData imdata = (ImageData) (echunk.getContent()); //Get image data Image img = Image.getInstance(getClass().getResource(imdata.getURL())); //Scale the image in order to fit the page img.scaleToFit(doc.getPageSize().getRight(doc.leftMargin() + doc.rightMargin()), doc.getPageSize().getTop(doc.topMargin() + doc.bottomMargin())); //Add image doc.add(img); //If a caption is present, insert it below the image if ((imdata.getCaption() != null) && (!imdata.getCaption().equals(""))) { doc.add(new Paragraph("IMAGE: " + imdata.getCaption())); } } catch (NullPointerException e) { throw new ExplanationException( "The image '" + ((ImageData) (echunk.getContent())).getURL() + "' could not be found"); } catch (Exception e) { throw new ExplanationException(e.getMessage()); } }