List of usage examples for com.lowagie.text Document Document
public Document()
Document
-object. From source file:EplanPrinter.RTFWrite.java
License:Open Source License
public String openDoc(String name, String title) throws FileNotFoundException, DocumentException { document = new Document(); RtfWriter2.getInstance(document, new FileOutputStream(name + ".rtf")); document.open();//ww w . j a v a 2s . c om Paragraph p = new Paragraph("Permit " + title); p.setAlignment(Element.ALIGN_CENTER); document.add(p); return ""; }
From source file:es.uniovi.asw.personalletter.PDFTextWritter.java
@Override public void createDocument(String documentName, String content) throws CitizenException { String realPath = FILE_PATH + documentName + ".pdf"; Document doc = new Document(); try {// w ww .j a v a 2 s.co m PdfWriter.getInstance(doc, new FileOutputStream(realPath)); doc.open(); addMetaData(doc); addTitlePage(doc); addContent(doc, content); } catch (DocumentException | FileNotFoundException e) { throw new CitizenException("Error al generar documento pdf" + " [" + FILE_PATH + documentName + ".pdf] | [" + this.getClass().getName() + "]"); } finally { if (doc != null) { doc.close(); } } }
From source file:etc.Exporter.java
License:Open Source License
public static void saveAsPDF(File file, Task task) { try {/*from ww w . j a va2 s.co m*/ Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(file)); document.open(); Paragraph taskid = new Paragraph("ID e Detyres: " + task.getIdentifier(), FontFactory.getFont(FontFactory.COURIER, 10, Font.ITALIC)); document.add(taskid); Paragraph creator = new Paragraph("Krijuar nga " + task.getCreator().toString() + "[" + task.getCreationTime().format(DateTimeFormatter.ofPattern("dd.MM.yyyy - HH.mm")) + "]", FontFactory.getFont(FontFactory.COURIER, 10, Font.ITALIC)); document.add(creator); Paragraph executor = new Paragraph("Per zbatim prej: " + task.getExecutor().toString(), FontFactory.getFont(FontFactory.COURIER, 10, Font.ITALIC)); document.add(executor); Paragraph title = new Paragraph(task.getTitle().toUpperCase(), FontFactory.getFont(FontFactory.COURIER, 14, Font.BOLD)); document.add(title); Paragraph description = new Paragraph(task.getDescription(), FontFactory.getFont(FontFactory.COURIER, 12, Font.NORMAL)); document.add(description); PdfPCell cell = new PdfPCell(); cell.setBorder(Rectangle.BOTTOM); PdfPTable table = new PdfPTable(1); table.addCell(cell); table.setWidthPercentage(100f); document.add(table); if (task instanceof dc.CompletedTask) { document.add(new Paragraph( "Gjendja: Perfunduar [" + ((dc.CompletedTask) task).getCompletitionTime() .format(DateTimeFormatter.ofPattern("dd.MM.yyyy HH.mm")) + "]", FontFactory.getFont(FontFactory.COURIER, 10, Font.ITALIC))); document.add(new Paragraph("Shenimet e Zbatuesit".toUpperCase(), FontFactory.getFont(FontFactory.COURIER, 14, Font.BOLD))); document.add(new Paragraph(((dc.CompletedTask) task).getAnnotations(), FontFactory.getFont(FontFactory.COURIER, 12, Font.NORMAL))); } else if (task instanceof dc.RejectedTask) { document.add(new Paragraph( "Gjendja: Refuzuar [" + ((dc.RejectedTask) task).getRejectionTime() .format(DateTimeFormatter.ofPattern("dd.MM.yyyy HH.mm")) + "]", FontFactory.getFont(FontFactory.COURIER, 10, Font.ITALIC))); document.add(new Paragraph("Shenimet e Zbatuesit".toUpperCase(), FontFactory.getFont(FontFactory.COURIER, 14, Font.BOLD))); document.add(new Paragraph(((dc.RejectedTask) task).getAnnotations(), FontFactory.getFont(FontFactory.COURIER, 12, Font.NORMAL))); } else { document.add(new Paragraph("Gjendja: Ne Pritje", FontFactory.getFont(FontFactory.COURIER, 10, Font.ITALIC))); } document.close(); Process p = Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + file.getAbsolutePath()); p.waitFor(); } catch (DocumentException | InterruptedException | IOException ex) { Logger.getLogger(Exporter.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:eu.europa.ec.markt.dss.report.Tsl2PdfExporter.java
License:Open Source License
/** * Produce a human readable export of the given tsl to the given file. * /*from w w w .j a v a2s .c o m*/ * @param tsl * the TrustServiceList to export * @param pdfFile * the file to generate * @return * @throws IOException */ public void humanReadableExport(final TrustServiceList tsl, final File pdfFile) { Document document = new Document(); OutputStream outputStream; try { outputStream = new FileOutputStream(pdfFile); } catch (FileNotFoundException e) { throw new RuntimeException("file not found: " + pdfFile.getAbsolutePath(), e); } try { final PdfWriter pdfWriter = PdfWriter.getInstance(document, outputStream); pdfWriter.setPDFXConformance(PdfWriter.PDFA1B); // title final EUCountry country = EUCountry.valueOf(tsl.getSchemeTerritory()); final String title = country.getShortSrcLangName() + " (" + country.getShortEnglishName() + "): Trusted List"; Phrase footerPhrase = new Phrase("PDF document generated on " + new Date().toString() + ", page ", headerFooterFont); HeaderFooter footer = new HeaderFooter(footerPhrase, true); document.setFooter(footer); Phrase headerPhrase = new Phrase(title, headerFooterFont); HeaderFooter header = new HeaderFooter(headerPhrase, false); document.setHeader(header); document.open(); addTitle(title, title0Font, Paragraph.ALIGN_CENTER, 0, 20, document); addLongItem("Scheme name", tsl.getSchemeName(), document); addLongItem("Legal Notice", tsl.getLegalNotice(), document); // information table PdfPTable informationTable = createInfoTable(); addItemRow("Scheme territory", tsl.getSchemeTerritory(), informationTable); addItemRow("Scheme status determination approach", substringAfter(tsl.getStatusDeterminationApproach(), "StatusDetn/"), informationTable); final List<String> schemeTypes = new ArrayList<String>(); for (final String schemeType : tsl.getSchemeTypes()) { schemeTypes.add(schemeType); } addItemRow("Scheme type community rules", schemeTypes, informationTable); addItemRow("Issue date", tsl.getListIssueDateTime().toString(), informationTable); addItemRow("Next update", tsl.getNextUpdate().toString(), informationTable); addItemRow("Historical information period", tsl.getHistoricalInformationPeriod().toString() + " days", informationTable); addItemRow("Sequence number", tsl.getSequenceNumber().toString(), informationTable); addItemRow("Scheme information URIs", tsl.getSchemeInformationUris(), informationTable); document.add(informationTable); addTitle("Scheme Operator", title1Font, Paragraph.ALIGN_CENTER, 0, 10, document); informationTable = createInfoTable(); addItemRow("Scheme operator name", tsl.getSchemeOperatorName(), informationTable); PostalAddressType schemeOperatorPostalAddress = tsl.getSchemeOperatorPostalAddress(Locale.ENGLISH); addItemRow("Scheme operator street address", schemeOperatorPostalAddress.getStreetAddress(), informationTable); addItemRow("Scheme operator postal code", schemeOperatorPostalAddress.getPostalCode(), informationTable); addItemRow("Scheme operator locality", schemeOperatorPostalAddress.getLocality(), informationTable); addItemRow("Scheme operator state", schemeOperatorPostalAddress.getStateOrProvince(), informationTable); addItemRow("Scheme operator country", schemeOperatorPostalAddress.getCountryName(), informationTable); List<String> schemeOperatorElectronicAddressess = tsl.getSchemeOperatorElectronicAddresses(); addItemRow("Scheme operator contact", schemeOperatorElectronicAddressess, informationTable); document.add(informationTable); addTitle("Trust Service Providers", title1Font, Paragraph.ALIGN_CENTER, 10, 2, document); List<TrustServiceProvider> trustServiceProviders = tsl.getTrustServiceProviders(); for (TrustServiceProvider trustServiceProvider : trustServiceProviders) { addTitle(trustServiceProvider.getName(), title1Font, Paragraph.ALIGN_LEFT, 10, 2, document); PdfPTable providerTable = createInfoTable(); addItemRow("Service provider trade name", trustServiceProvider.getTradeName(), providerTable); addItemRow("Information URI", trustServiceProvider.getInformationUris(), providerTable); PostalAddressType postalAddress = trustServiceProvider.getPostalAddress(); addItemRow("Service provider street address", postalAddress.getStreetAddress(), providerTable); addItemRow("Service provider postal code", postalAddress.getPostalCode(), providerTable); addItemRow("Service provider locality", postalAddress.getLocality(), providerTable); addItemRow("Service provider state", postalAddress.getStateOrProvince(), providerTable); addItemRow("Service provider country", postalAddress.getCountryName(), providerTable); document.add(providerTable); List<TrustService> trustServices = trustServiceProvider.getTrustServices(); for (TrustService trustService : trustServices) { addTitle(trustService.getName(), title2Font, Paragraph.ALIGN_LEFT, 10, 2, document); PdfPTable serviceTable = createInfoTable(); addItemRow("Type", substringAfter(trustService.getType(), "Svctype/"), serviceTable); addItemRow("Status", substringAfter(trustService.getStatus(), "Svcstatus/"), serviceTable); addItemRow("Status starting time", trustService.getStatusStartingTime().toString(), serviceTable); document.add(serviceTable); addTitle("Service digital identity (X509)", title3Font, Paragraph.ALIGN_LEFT, 2, 0, document); final X509Certificate certificate = trustService.getServiceDigitalIdentity(); final PdfPTable serviceIdentityTable = createInfoTable(); addItemRow("Version", Integer.toString(certificate.getVersion()), serviceIdentityTable); addItemRow("Serial number", certificate.getSerialNumber().toString(), serviceIdentityTable); addItemRow("Signature algorithm", certificate.getSigAlgName(), serviceIdentityTable); addItemRow("Issuer", certificate.getIssuerX500Principal().toString(), serviceIdentityTable); addItemRow("Valid from", certificate.getNotBefore().toString(), serviceIdentityTable); addItemRow("Valid to", certificate.getNotAfter().toString(), serviceIdentityTable); addItemRow("Subject", certificate.getSubjectX500Principal().toString(), serviceIdentityTable); addItemRow("Public key", certificate.getPublicKey().toString(), serviceIdentityTable); // TODO certificate policies addItemRow("Subject key identifier", toHex(getSKId(certificate)), serviceIdentityTable); addItemRow("CRL distribution points", getCrlDistributionPoints(certificate), serviceIdentityTable); addItemRow("Authority key identifier", toHex(getAKId(certificate)), serviceIdentityTable); addItemRow("Key usage", getKeyUsage(certificate), serviceIdentityTable); addItemRow("Basic constraints", getBasicConstraints(certificate), serviceIdentityTable); byte[] encodedCertificate; try { encodedCertificate = certificate.getEncoded(); } catch (CertificateEncodingException e) { throw new RuntimeException("cert: " + e.getMessage(), e); } addItemRow("SHA1 Thumbprint", DigestUtils.shaHex(encodedCertificate), serviceIdentityTable); addItemRow("SHA256 Thumbprint", DigestUtils.sha256Hex(encodedCertificate), serviceIdentityTable); document.add(serviceIdentityTable); List<ExtensionType> extensions = trustService.getExtensions(); for (ExtensionType extension : extensions) { printExtension(extension, document); } addLongMonoItem("The decoded certificate:", certificate.toString(), document); addLongMonoItem("The certificate in PEM format:", toPem(certificate), document); } } X509Certificate signerCertificate = tsl.verifySignature(); if (null != signerCertificate) { Paragraph tslSignerTitle = new Paragraph("Trusted List Signer", title1Font); tslSignerTitle.setAlignment(Paragraph.ALIGN_CENTER); document.add(tslSignerTitle); final PdfPTable signerTable = createInfoTable(); addItemRow("Subject", signerCertificate.getSubjectX500Principal().toString(), signerTable); addItemRow("Issuer", signerCertificate.getIssuerX500Principal().toString(), signerTable); addItemRow("Not before", signerCertificate.getNotBefore().toString(), signerTable); addItemRow("Not after", signerCertificate.getNotAfter().toString(), signerTable); addItemRow("Serial number", signerCertificate.getSerialNumber().toString(), signerTable); addItemRow("Version", Integer.toString(signerCertificate.getVersion()), signerTable); byte[] encodedPublicKey = signerCertificate.getPublicKey().getEncoded(); addItemRow("Public key SHA1 Thumbprint", DigestUtils.shaHex(encodedPublicKey), signerTable); addItemRow("Public key SHA256 Thumbprint", DigestUtils.sha256Hex(encodedPublicKey), signerTable); document.add(signerTable); addLongMonoItem("The decoded certificate:", signerCertificate.toString(), document); addLongMonoItem("The certificate in PEM format:", toPem(signerCertificate), document); addLongMonoItem("The public key in PEM format:", toPem(signerCertificate.getPublicKey()), document); } document.close(); } catch (DocumentException e) { throw new RuntimeException("PDF document error: " + e.getMessage(), e); } catch (Exception e) { throw new RuntimeException("Exception: " + e.getMessage(), e); } }
From source file:fr.univlorraine.mondossierweb.controllers.CalendrierController.java
License:Apache License
/** * configure le document pdf.//from ww w . j av a 2s . com * @param width * @param height * @param margin * @return doc */ private Document configureDocument(final float margin) { Document document = new Document(); document.setPageSize(PageSize.A4.rotate()); float marginPage = (margin / 2.54f) * 72f; document.setMargins(marginPage, marginPage, marginPage, marginPage); return document; }
From source file:fr.univlorraine.mondossierweb.controllers.InscriptionController.java
License:Apache License
/** * configure le document pdf./*from w ww.j a v a2 s.co m*/ * @param width * @param height * @param margin * @return doc */ private Document configureDocument() { Document document = new Document(); document.setPageSize(PageSize.A4); float marginTop = (MARGIN_TOP / 2.54f) * 72f; float marginRight = (MARGIN_RIGHT / 2.54f) * 72f; float marginBottom = (MARGIN_BOTTOM / 2.54f) * 72f; float marginLeft = (MARGIN_LEFT / 2.54f) * 72f; document.setMargins(marginLeft, marginRight, marginTop, marginBottom); return document; }
From source file:geoportal.presentacion.beans.ReportesControlador.java
public void imprimirReporte() { //DateFormat dfDateFull = DateFormat.getDateInstance(DateFormat.FULL); try {/*from w ww .j ava2s .co m*/ //Generamos el archivo PDF String directorioArchivos; ServletContext ctx = (ServletContext) FacesContext.getCurrentInstance().getExternalContext() .getContext(); directorioArchivos = ctx.getRealPath("/") + "reportes"; String name = directorioArchivos + "/document-reporte.pdf"; Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(name)); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(name)); //PdfWriter writer = PdfWriter.getInstance(document, //new FileOutputStream("C:")); Paragraph paragraph = new Paragraph(); Paragraph paragraph1 = new Paragraph(); Paragraph paragraph2 = new Paragraph(); //PdfPTable table = new PdfPTable(4); PdfPTable table1 = new PdfPTable(1); PdfPTable table2 = new PdfPTable(4); PdfPTable table3 = new PdfPTable(4); PdfPTable table5 = new PdfPTable(1); paragraph.add("\n\n\n\n\n\n\n"); paragraph.setAlignment(Paragraph.ALIGN_CENTER); paragraph1.add("\n"); paragraph1.setAlignment(Paragraph.ALIGN_CENTER); paragraph2.add("Total Denuncias:" + totalDenuncias); paragraph2.setAlignment(Paragraph.ALIGN_LEFT); // Obtenemos una instancia de nuestro manejador de eventos MembreteHeaderiText header = new MembreteHeaderiText(); //Asignamos el manejador de eventos al escritor. writer.setPageEvent(header); document.open(); // Chunk titulo = new Chunk(CHUNK, FontFactory.getFont(FontFactory.COURIER, 20, Font.UNDERLINE, BaseColor.BLACK)); // // titulo = new Chunk(IMAGE, FontFactory.getFont(FontFactory.COURIER, 20, Font.UNDERLINE, BaseColor.BLACK)); // document.add(titulo); // Image foto = Image.getInstance(resources / ferrari.jpg?); //foto.scaleToFit(100, 100); foto.setAlignment(Chunk.ALIGN_MIDDLE); //primera linea PdfPCell cell5 = new PdfPCell(new Paragraph("VIOLENCIA INTRAFAMILIAR ")); //segunda linea PdfPCell cell12 = new PdfPCell(new Paragraph("AO")); PdfPCell cell6 = new PdfPCell(new Paragraph("2010")); PdfPCell cell7 = new PdfPCell(new Paragraph("2011")); PdfPCell cell8 = new PdfPCell(new Paragraph("2012")); //tercera fila PdfPCell cell13 = new PdfPCell(new Paragraph("# DENUNCIAS")); PdfPCell cell9 = new PdfPCell(new Paragraph("" + lstVif2010.size())); PdfPCell cell10 = new PdfPCell(new Paragraph("" + lstVif2011.size())); PdfPCell cell11 = new PdfPCell(new Paragraph("" + lstVif_2012.size())); PdfPCell cell15 = new PdfPCell(new Paragraph("TOTAL DENUNCIAS:" + totalDenuncias)); cell5.setHorizontalAlignment(Element.ALIGN_CENTER); cell6.setHorizontalAlignment(Element.ALIGN_CENTER); cell7.setHorizontalAlignment(Element.ALIGN_CENTER); cell8.setHorizontalAlignment(Element.ALIGN_CENTER); cell9.setHorizontalAlignment(Element.ALIGN_CENTER); cell10.setHorizontalAlignment(Element.ALIGN_CENTER); cell11.setHorizontalAlignment(Element.ALIGN_CENTER); cell12.setHorizontalAlignment(Element.ALIGN_CENTER); cell13.setHorizontalAlignment(Element.ALIGN_CENTER); cell15.setHorizontalAlignment(Element.ALIGN_LEFT); cell12.setBackgroundColor(Color.cyan); cell13.setBackgroundColor(Color.cyan); cell5.setBorder(Rectangle.NO_BORDER); cell15.setBorder(Rectangle.NO_BORDER); table1.addCell(cell5); //aadir segunda fila table2.addCell(cell12); table2.addCell(cell6); table2.addCell(cell7); table2.addCell(cell8); //aadir tercera fila table3.addCell(cell13); table3.addCell(cell9); table3.addCell(cell10); table3.addCell(cell11); //aadir cuarta fila table5.addCell(cell15); document.add(paragraph); document.add(table1); document.add(paragraph1); document.add(table2); document.add(table3); document.add(table5); //document.add(paragraph2); //document.add(table); //document.setFooter(event); document.close(); //---------------------------- //Abrimos el archivo PDF FacesContext context = FacesContext.getCurrentInstance(); HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse(); response.setContentType("application/pdf"); response.setHeader("Content-disposition", "inline=filename=" + name); try { response.getOutputStream().write(Util.getBytesFromFile(new File(name))); response.getOutputStream().flush(); response.getOutputStream().close(); context.responseComplete(); } catch (IOException e) { e.printStackTrace(); } } catch (Exception e) { e.printStackTrace(); } }
From source file:gerarpdf.GerarPdf.java
private void btnGeraActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGeraActionPerformed // Instanciando o document Document documento = new Document(); try {//from www . j a v a2s .c o m PdfWriter.getInstance(documento, new FileOutputStream("documento.pdf")); if (jtxt_area == null || jtxt_area.getText().toString().isEmpty()) { } documento.open(); //documento.add(new Paragraph("aLO ALOA AMOANOANIANINO")); documento.add(new Paragraph(jtxt_area.getText())); } catch (DocumentException | FileNotFoundException ex) { System.err.println("Erro ao carregar arquivo"); } finally { documento.close(); } try { Desktop.getDesktop().open(new File("documento.pdf")); } catch (IOException ex) { Logger.getLogger(GerarPdf.class.getName()).log(Level.SEVERE, null, ex); System.err.println("Erro ao carregar arquivo " + ex); } }
From source file:gov.medicaid.services.impl.ExportServiceBean.java
License:Apache License
/** * Exports the search results into PDF.//from w w w .ja va 2 s . c om * * @param requests * the list to be exported * @param status * the status filter * @param outputStream * the stream to export to * @throws PortalServiceException * for any errors encountered */ public void export(List<UserRequest> requests, String status, OutputStream outputStream) throws PortalServiceException { PdfPTable resultTable; try { Document document = new Document(); PdfWriter.getInstance(document, outputStream); document.open(); resultTable = new PdfPTable(new float[] { 3, 8, 8, 8, 10, 25, 8, 8, 8 }); resultTable.getDefaultCell().setBorder(0); resultTable.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_CENTER); resultTable.setTotalWidth(72 * 7); resultTable.setLockedWidth(true); resultTable.addCell(createHeaderCell("Enrollments", 9)); resultTable.completeRow(); addCenterCell(resultTable, "#"); addCenterCell(resultTable, "NPI/UMPI"); addCenterCell(resultTable, "Date Created"); addCenterCell(resultTable, "Request Type"); addCenterCell(resultTable, "Provider Type"); addCenterCell(resultTable, "Provider Name"); addCenterCell(resultTable, "Risk Level"); addCenterCell(resultTable, "Status"); addCenterCell(resultTable, "Status Date"); resultTable.completeRow(); int i = 0; for (UserRequest userRequest : requests) { addCenterCell(resultTable, String.valueOf(++i)); addCenterCell(resultTable, userRequest.getNpi()); addCenterCell(resultTable, BinderUtils.formatCalendar(BinderUtils.toCalendar(userRequest.getCreateDate()))); addCenterCell(resultTable, userRequest.getRequestType()); addCenterCell(resultTable, userRequest.getProviderType()); addCenterCell(resultTable, userRequest.getProviderName()); addCenterCell(resultTable, userRequest.getRiskLevel()); addCenterCell(resultTable, userRequest.getStatus()); addCenterCell(resultTable, BinderUtils.formatCalendar(BinderUtils.toCalendar(userRequest.getStatusDate()))); } resultTable.setSpacingAfter(20); document.add(resultTable); document.close(); } catch (DocumentException e) { throw new PortalServiceException("Export failed, see log for additional details.", e); } }
From source file:gov.medicaid.services.impl.ExportServiceBean.java
License:Apache License
/** * Exports the profile into PDF.//from w w w . j a v a2 s . co m * * @param currentUser * the current user * @param enrollment * the enrollment model * @param model * the view model * @param outputStream * the stream to export to * @throws IOException * for read/write errors * @throws PortalServiceException * for any other errors encountered */ public void export(CMSUser currentUser, EnrollmentType enrollment, Map<String, Object> model, OutputStream outputStream) throws PortalServiceException, IOException { try { Document document = new Document(); PdfWriter.getInstance(document, outputStream); document.open(); renderTicket(enrollment, document, model); document.close(); } catch (DocumentException e) { throw new PortalServiceException("Export failed, see log for additional details.", e); } }