List of usage examples for com.lowagie.text Document open
boolean open
To view the source code for com.lowagie.text Document open.
Click Source Link
From source file:com.qcadoo.report.api.pdf.PdfDocumentService.java
License:Open Source License
private void generate(final Entity entity, final Locale locale, final String filename, final Rectangle pageSize) throws IOException, DocumentException { Document document = new Document(pageSize); try {/*from w w w. j av a 2s .com*/ FileOutputStream fileOutputStream = new FileOutputStream( fileService.createReportFile(filename + "." + ReportService.ReportType.PDF.getExtension())); PdfWriter writer = PdfWriter.getInstance(document, fileOutputStream); writer.setPageEvent(new PdfPageNumbering(footerResolver.resolveFooter(locale))); document.setMargins(40, 40, 60, 60); buildPdfMetadata(document, locale); writer.createXmpMetadata(); document.open(); buildPdfContent(document, entity, locale); document.close(); } catch (DocumentException e) { LOG.error("Problem with generating document - " + e.getMessage()); document.close(); throw e; } }
From source file:com.qcadoo.report.api.pdf.PdfDocumentWithWriterService.java
License:Open Source License
private void generate(final Entity entity, final Locale locale, final String filename, final Rectangle pageSize) throws IOException, DocumentException { Document document = new Document(pageSize); try {/*from ww w .j a v a2 s. c om*/ FileOutputStream fileOutputStream = new FileOutputStream( fileService.createReportFile(filename + "." + ReportService.ReportType.PDF.getExtension())); PdfWriter writer = PdfWriter.getInstance(document, fileOutputStream); writer.setPageEvent(new PdfPageNumbering(footerResolver.resolveFooter(locale))); document.setMargins(40, 40, 60, 60); buildPdfMetadata(document, locale); writer.createXmpMetadata(); document.open(); buildPdfContent(writer, document, entity, locale); document.close(); } catch (DocumentException e) { LOG.error("Problem with generating document - " + e.getMessage()); document.close(); throw e; } }
From source file:com.rapidminer.gui.actions.export.ImageExporter.java
License:Open Source License
private void exportVectorGraphics(String formatName, File outputFile) throws ImageExportException { Component component = printableComponent.getExportComponent(); int width = component.getWidth(); int height = component.getHeight(); try (FileOutputStream fs = new FileOutputStream(outputFile)) { switch (formatName) { case PDF: // create pdf document with slightly increased width and height // (otherwise the image gets cut off) Document document = new Document(new Rectangle(width + 5, height + 5)); PdfWriter writer = PdfWriter.getInstance(document, fs); document.open(); PdfContentByte cb = writer.getDirectContent(); PdfTemplate tp = cb.createTemplate(width, height); Graphics2D g2 = tp.createGraphics(width, height, new DefaultFontMapper()); component.print(g2);/*from www .j a v a 2s . c o m*/ g2.dispose(); cb.addTemplate(tp, 0, 0); document.close(); break; case SVG: exportFreeHep(component, fs, new SVGGraphics2D(fs, new Dimension(width, height))); break; case EPS: exportFreeHep(component, fs, new PSGraphics2D(fs, new Dimension(width, height))); break; default: // cannot happen break; } } catch (Exception e) { throw new ImageExportException( I18N.getMessage(I18N.getUserErrorMessagesBundle(), "error.image_export.export_failed"), e); } }
From source file:com.safetys.framework.jmesa.view.pdfp.PdfPViewExporter.java
License:Apache License
public void export() throws Exception { com.lowagie.text.Document document = new com.lowagie.text.Document(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); document.open(); PdfPView pdfView = (PdfPView) getView(); document.add(pdfView.getTableCaption()); document.add(pdfView.render());/* ww w .ja v a2s . co m*/ document.close(); HttpServletResponse response = getResponse(); responseHeaders(response); ServletOutputStream out = response.getOutputStream(); baos.writeTo(out); out.flush(); }
From source file:com.safire.bean.Ingreso_recibosBean.java
public void preProcessPDF(Object document) { Document pdf = (Document) document; pdf.setPageSize(PageSize.A4.rotate()); pdf.open(); }
From source file:com.sapienter.jbilling.server.invoice.PaperInvoiceBatchBL.java
License:Open Source License
/** * Takes a list of invoices and replaces the individual PDF files for one * single PDF in the destination directory. * @param destination//from w ww. j a v a 2 s. c o m * @param prefix * @param entityId * @param invoices * @throws PdfFormatException * @throws IOException */ public void compileInvoiceFiles(String destination, String prefix, Integer entityId, Integer[] invoices) throws DocumentException, IOException { String filePrefix = Util.getSysProp("base_dir") + "invoices/" + entityId + "-"; String outFile = destination + prefix + "-batch.pdf"; int pageOffset = 0; ArrayList master = new ArrayList(); Document document = null; PdfCopy writer = null; for (int f = 0; f < invoices.length; f++) { // we create a reader for a certain document PdfReader reader = new PdfReader(filePrefix + invoices[f] + "-invoice.pdf"); reader.consolidateNamedDestinations(); // we retrieve the total number of pages int numberOfPages = reader.getNumberOfPages(); List bookmarks = SimpleBookmark.getBookmark(reader); if (bookmarks != null) { if (pageOffset != 0) SimpleBookmark.shiftPageNumbers(bookmarks, pageOffset, null); master.addAll(bookmarks); } pageOffset += numberOfPages; if (f == 0) { // step 1: creation of a document-object document = new Document(reader.getPageSizeWithRotation(1)); // step 2: we create a writer that listens to the document writer = new PdfCopy(document, new FileOutputStream(outFile)); // step 3: we open the document document.open(); } // step 4: we add content PdfImportedPage page; for (int i = 0; i < numberOfPages;) { ++i; page = writer.getImportedPage(reader, i); writer.addPage(page); } PRAcroForm form = reader.getAcroForm(); if (form != null) writer.copyAcroForm(reader); //release and delete writer.freeReader(reader); reader.close(); File file = new File(filePrefix + invoices[f] + "-invoice.pdf"); file.delete(); } if (!master.isEmpty()) writer.setOutlines(master); // step 5: we close the document if (document != null) { document.close(); } else { LOG.warn("document == null"); } LOG.debug("PDF batch file is ready " + outFile); }
From source file:com.senacor.wbs.web.project.ProjectListPanel.java
License:Apache License
public ProjectListPanel(final String id, final List<Project> projects) { super(id);/*w w w.ja v a 2 s .c om*/ this.locale = getLocale(); SortableListDataProvider<Project> projectProvider = new SortableListDataProvider<Project>(projects) { @Override protected Locale getLocale() { return ProjectListPanel.this.getLocale(); } public IModel model(final Object object) { return new CompoundPropertyModel(object); } }; projectProvider.setSort("name", true); dataView = new DataView("projects", projectProvider, 4) { @Override protected void populateItem(final Item item) { Project project = (Project) item.getModelObject(); PageParameters pageParameters = new PageParameters(); pageParameters.put("projectId", project.getId()); item.add(new BookmarkablePageLink("tasks", ProjectDetailsPage.class, pageParameters) .add(new Label("id"))); item.add(new Label("kuerzel")); item.add(new Label("titel", project.getName())); item.add(new Label("budget")); item.add(new Label("costPerHour")); item.add(new Label("start")); item.add(new Label("ende")); item.add(new Label("state")); // Alternieren der Farbe zwischen geraden und // ungeraden Zeilen item.add(new AttributeModifier("class", true, new AbstractReadOnlyModel() { @Override public Object getObject() { return (item.getIndex() % 2 == 1) ? "even" : "odd"; } })); } }; add(dataView); Form localeForm = new Form("localeForm"); ImageButton deButton = new ImageButton("langde", new ResourceReference(BaseWBSPage.class, "de.png")) { @Override public void onSubmit() { ProjectListPanel.this.locale = Locale.GERMANY; } }; localeForm.add(deButton); ImageButton usButton = new ImageButton("langus", new ResourceReference(BaseWBSPage.class, "us.png")) { @Override public void onSubmit() { ProjectListPanel.this.locale = Locale.US; } }; localeForm.add(usButton); add(localeForm); final IResourceStream pdfResourceStream = new AbstractResourceStreamWriter() { public void write(final OutputStream output) { Document document = new Document(); try { PdfWriter.getInstance(document, output); document.open(); // document.add(new // Paragraph("WBS-Projektliste")); // document.add(new Paragraph("")); PdfPTable table = new PdfPTable(new float[] { 1f, 1f, 2f, 1f }); PdfPCell cell = new PdfPCell(new Paragraph("WBS-Projektliste")); cell.setColspan(4); cell.setGrayFill(0.8f); table.addCell(cell); table.addCell("ID"); table.addCell("Krzel"); table.addCell("Titel"); table.addCell("Budget in PT"); for (Project project : projects) { table.addCell("" + project.getId()); table.addCell(project.getKuerzel()); table.addCell(project.getName()); table.addCell("" + project.getBudget()); } document.add(table); document.close(); } catch (DocumentException e) { throw new RuntimeException(e); } } public String getContentType() { return "application/pdf"; } }; WebResource projectsResource = new WebResource() { { setCacheable(false); } @Override public IResourceStream getResourceStream() { return pdfResourceStream; } @Override protected void setHeaders(final WebResponse response) { super.setHeaders(response); // response.setAttachmentHeader("projekte.pdf"); } }; WebResource projectsResourceDL = new WebResource() { { setCacheable(false); } @Override public IResourceStream getResourceStream() { return pdfResourceStream; } @Override protected void setHeaders(final WebResponse response) { super.setHeaders(response); response.setAttachmentHeader("projekte.pdf"); } }; ResourceLink pdfDownload = new ResourceLink("pdfDownload", projectsResourceDL); ResourceLink pdfPopup = new ResourceLink("pdfPopup", projectsResource); PopupSettings popupSettings = new PopupSettings(PopupSettings.STATUS_BAR); popupSettings.setWidth(500); popupSettings.setHeight(700); pdfPopup.setPopupSettings(popupSettings); Link pdfReqTarget = new Link("pdfReqTarget") { @Override public void onClick() { RequestCycle.get() .setRequestTarget(new ResourceStreamRequestTarget(pdfResourceStream, "projekte.pdf")); } }; add(pdfReqTarget); add(pdfDownload); add(pdfPopup); add(new OrderByBorder("orderByKuerzel", "kuerzel", projectProvider)); add(new OrderByBorder("orderByName", "name", projectProvider)); add(new OrderByBorder("orderByBudget", "budget", projectProvider)); add(new OrderByBorder("orderByCostPerHour", "costPerHour", projectProvider)); add(new OrderByBorder("orderByStart", "start", projectProvider)); add(new OrderByBorder("orderByEnde", "ende", projectProvider)); add(new OrderByBorder("orderByState", "state", projectProvider)); add(new PagingNavigator("projectsNavigator", dataView)); }
From source file:com.servoy.extensions.plugins.pdf_output.PDFProvider.java
License:Open Source License
/** * Combine multiple protected PDF docs into one. * Note: this function may fail when creating large PDF files due to lack of available heap memory. To compensate, please configure the application server with more heap memory via -Xmx parameter. * * @sample/*from w w w .ja v a 2 s . co m*/ * pdf_blob_column = combineProtectedPDFDocuments(new Array(pdf_blob1,pdf_blob2,pdf_blob3), new Array(pdf_blob1_pass,pdf_blob2_pass,pdf_blob3_pass)); * * @param pdf_docs_bytearrays the array of documents to combine * @param pdf_docs_passwords an array of passwords to use */ public byte[] js_combineProtectedPDFDocuments(Object[] pdf_docs_bytearrays, Object[] pdf_docs_passwords) { if (pdf_docs_bytearrays == null || pdf_docs_bytearrays.length == 0) return null; ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { int pageOffset = 0; List master = new ArrayList(); Document document = null; PdfCopy writer = null; for (int f = 0; f < pdf_docs_bytearrays.length; f++) { if (!(pdf_docs_bytearrays[f] instanceof byte[])) continue; byte[] pdf_file = (byte[]) pdf_docs_bytearrays[f]; // we create a reader for a certain document byte[] password = null; if (pdf_docs_passwords != null && pdf_docs_passwords.length > f && pdf_docs_passwords[f] != null) { if (pdf_docs_passwords[f] instanceof String) password = pdf_docs_passwords[f].toString().getBytes(); } PdfReader reader = new PdfReader(pdf_file, password); reader.consolidateNamedDestinations(); // we retrieve the total number of pages int n = reader.getNumberOfPages(); List bookmarks = SimpleBookmark.getBookmark(reader); if (bookmarks != null) { if (pageOffset != 0) { SimpleBookmark.shiftPageNumbers(bookmarks, pageOffset, null); } master.addAll(bookmarks); } pageOffset += n; if (writer == null) { // step 1: creation of a document-object document = new Document(reader.getPageSizeWithRotation(1)); // step 2: we create a writer that listens to the document writer = new PdfCopy(document, baos); // step 3: we open the document document.open(); } // step 4: we add content PdfImportedPage page; for (int i = 0; i < n;) { ++i; page = writer.getImportedPage(reader, i); writer.addPage(page); } PRAcroForm form = reader.getAcroForm(); if (form != null) writer.copyAcroForm(reader); } if (writer != null && document != null) { if (master.size() > 0) writer.setOutlines(master); // step 5: we close the document document.close(); } return baos.toByteArray(); } catch (Throwable e) { Debug.error(e); throw new RuntimeException("Error combinding pdf documents: " + e.getMessage(), e); //$NON-NLS-1$ } }
From source file:com.shmsoft.dmass.print.Html2Pdf.java
License:Apache License
/** * Bad rendering, perhaps used only for Windows *//* ww w .jav a 2 s. c o m*/ @SuppressWarnings({ "rawtypes", "unchecked" }) private static void convertHtml2Pdf(Reader htmlReader, String outputFile) throws Exception { Document pdfDocument = new Document(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(pdfDocument, baos); pdfDocument.open(); StyleSheet styles = new StyleSheet(); styles.loadTagStyle("body", "font", "Times New Roman"); ImageProvider imageProvider = new ImageProvider() { @Override public Image getImage(String src, HashMap arg1, ChainedProperties arg2, DocListener arg3) { try { Image image = Image.getInstance(IOUtils.toByteArray( getClass().getClassLoader().getResourceAsStream(ParameterProcessing.NO_IMAGE_FILE))); return image; } catch (Exception e) { System.out.println("Problem with html->pdf imaging, image provider fault"); } return null; } }; HashMap interfaceProps = new HashMap(); interfaceProps.put("img_provider", imageProvider); ArrayList arrayElementList = HTMLWorker.parseToList(htmlReader, styles, interfaceProps); for (int i = 0; i < arrayElementList.size(); ++i) { Element e = (Element) arrayElementList.get(i); pdfDocument.add(e); } pdfDocument.close(); byte[] bs = baos.toByteArray(); File pdfFile = new File(outputFile); FileOutputStream out = new FileOutputStream(pdfFile); out.write(bs); out.close(); }
From source file:com.siacra.beans.ExporterBean.java
public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException { Document pdf = (Document) document; HeaderFooter header = new HeaderFooter(new Phrase(this.getTitle()), false); pdf.setHeader(header);// w w w . jav a 2 s. c om HeaderFooter footer = new HeaderFooter(new Phrase("Pagina"), new Phrase("")); pdf.setFooter(footer); pdf.open(); pdf.setPageSize(PageSize.LETTER); ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext() .getContext(); String logo = servletContext.getRealPath("") + File.separator + "resources" + File.separator + "img" + File.separator + "minerva.png"; pdf.add(Image.getInstance(logo)); }