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:edu.eci.pdsw.g4.bean.control.web.SystemManageBean.java
public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException { Document pdf = (Document) document; pdf.open(); pdf.setPageSize(PageSize.A4);/* w ww .java 2 s.co m*/ pdf.addTitle("Ficha del Equipo : " + loadTipoEquipo.getNombre_equipo()); ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext(); String logo = externalContext.getRealPath("") + File.separator + "resource" + File.separator + "ecijulio.png"; pdf.add(Image.getInstance(logo)); pdf.bottom(30); pdf.add(new Chunk( "Datos del Equipo : " + loadTipoEquipo.getNombre_equipo() + " con Placa No : " + getPlacaficha())); }
From source file:edu.gmu.cs.sim.util.media.PDFEncoder.java
License:Academic Free License
public static void generatePDF(Component component, File file) { int width = component.getWidth(); int height = component.getHeight(); try {/* ww w . j a va 2 s. c om*/ Document document = new Document(new com.lowagie.text.Rectangle(width, height)); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file)); document.addAuthor("MASON"); document.open(); PdfContentByte cb = writer.getDirectContent(); PdfTemplate tp = cb.createTemplate(width, height); Graphics g2 = tp.createGraphics(width, height, new DefaultFontMapper()); component.paint(g2); g2.dispose(); cb.addTemplate(tp, 0, 0); document.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:edu.gmu.cs.sim.util.media.PDFEncoder.java
License:Academic Free License
public static void generatePDF(JFreeChart chart, int width, int height, File file) { try {//from w w w. java 2 s.co m Document document = new Document(new com.lowagie.text.Rectangle(width, height)); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file)); document.addAuthor("MASON"); document.open(); PdfContentByte cb = writer.getDirectContent(); PdfTemplate tp = cb.createTemplate(width, height); Graphics2D g2 = tp.createGraphics(width, height, new DefaultFontMapper()); Rectangle2D rectangle2D = new Rectangle2D.Double(0, 0, width, height); chart.draw(g2, rectangle2D); g2.dispose(); cb.addTemplate(tp, 0, 0); document.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:edu.harvard.mcz.imagecapture.encoder.LabelEncoder.java
License:Open Source License
@SuppressWarnings("hiding") public static boolean printList(List<UnitTrayLabel> taxa) throws PrintFailedException { boolean result = false; UnitTrayLabel label = new UnitTrayLabel(); LabelEncoder encoder = new LabelEncoder(label); Image image = encoder.getImage(); int counter = 0; try {/*from w ww . j ava 2 s . c om*/ Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream("labels.pdf")); document.setPageSize(PageSize.LETTER); document.open(); PdfPTable table = new PdfPTable(4); table.setWidthPercentage(100f); //table.setHorizontalAlignment(PdfPTable.ALIGN_LEFT); float[] cellWidths = { 30f, 20f, 30f, 20f }; table.setWidths(cellWidths); UnitTrayLabelLifeCycle uls = new UnitTrayLabelLifeCycle(); if (taxa == null) { taxa = uls.findAll(); } Iterator<UnitTrayLabel> i = taxa.iterator(); PdfPCell cell = null; PdfPCell cell_barcode = null; // Create two lists of 12 cells, the first 6 of each representing // the left hand column of 6 labels, the second 6 of each // representing the right hand column. // cells holds the text for each label, cells_barcode the barcode. ArrayList<PdfPCell> cells = new ArrayList<PdfPCell>(12); ArrayList<PdfPCell> cells_barcode = new ArrayList<PdfPCell>(12); for (int x = 0; x < 12; x++) { cells.add(null); cells_barcode.add(null); } int cellCounter = 0; while (i.hasNext()) { // Loop through all of the taxa (unit tray labels) found to print label = i.next(); for (int toPrint = 0; toPrint < label.getNumberToPrint(); toPrint++) { // For each taxon, loop through the number of requested copies // Generate a text and a barcode cell for each, and add to array for page log.debug("Label " + toPrint + " of " + label.getNumberToPrint()); cell = new PdfPCell(); cell.setBorderColor(Color.LIGHT_GRAY); cell.setVerticalAlignment(PdfPCell.ALIGN_TOP); cell.disableBorderSide(PdfPCell.RIGHT); cell.setPaddingLeft(3); String higherNames = ""; if (label.getTribe().trim().length() > 0) { higherNames = label.getFamily() + ": " + label.getSubfamily() + ": " + label.getTribe(); } else { higherNames = label.getFamily() + ": " + label.getSubfamily(); } Paragraph higher = new Paragraph(); higher.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL)); higher.add(new Chunk(higherNames)); cell.addElement(higher); Paragraph name = new Paragraph(); Chunk genus = new Chunk(label.getGenus().trim() + " "); genus.setFont(new Font(Font.TIMES_ROMAN, 11, Font.ITALIC)); Chunk species = new Chunk(label.getSpecificEpithet().trim()); Chunk normal = null; // normal font prefix to preceed specific epithet (nr. <i>epithet</i>) if (label.getSpecificEpithet().contains(".") || label.getSpecificEpithet().contains("[")) { if (label.getSpecificEpithet().startsWith("nr. ")) { normal = new Chunk("nr. "); normal.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL)); species = new Chunk(label.getSpecificEpithet().trim().substring(4)); species.setFont(new Font(Font.TIMES_ROMAN, 11, Font.ITALIC)); } else { species.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL)); } } else { species.setFont(new Font(Font.TIMES_ROMAN, 11, Font.ITALIC)); } String s = ""; if (label.getSubspecificEpithet().trim().length() > 0) { s = " "; } else { s = ""; } Chunk subspecies = new Chunk(s + label.getSubspecificEpithet().trim()); if (label.getSubspecificEpithet().contains(".") || label.getSubspecificEpithet().contains("[")) { subspecies.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL)); } else { subspecies.setFont(new Font(Font.TIMES_ROMAN, 11, Font.ITALIC)); } if (label.getInfraspecificRank().trim().length() > 0) { s = " "; } else { s = ""; } Chunk infraRank = new Chunk(s + label.getInfraspecificRank().trim()); infraRank.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL)); if (label.getInfraspecificEpithet().trim().length() > 0) { s = " "; } else { s = ""; } Chunk infra = new Chunk(s + label.getInfraspecificEpithet().trim()); infra.setFont(new Font(Font.TIMES_ROMAN, 11, Font.ITALIC)); if (label.getUnNamedForm().trim().length() > 0) { s = " "; } else { s = ""; } Chunk unNamed = new Chunk(s + label.getUnNamedForm().trim()); unNamed.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL)); name.add(genus); if (normal != null) { name.add(normal); } name.add(species); name.add(subspecies); name.add(infraRank); name.add(infra); name.add(unNamed); cell.addElement(name); Paragraph authorship = new Paragraph(); authorship.setFont(new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)); if (label.getAuthorship() != null && label.getAuthorship().length() > 0) { Chunk c_authorship = new Chunk(label.getAuthorship()); authorship.add(c_authorship); } cell.addElement(authorship); //cell.addElement(new Paragraph(" ")); if (label.getDrawerNumber() != null && label.getDrawerNumber().length() > 0) { Paragraph drawerNumber = new Paragraph(); drawerNumber.setFont(new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)); Chunk c_drawerNumber = new Chunk(label.getDrawerNumber()); drawerNumber.add(c_drawerNumber); cell.addElement(drawerNumber); } else { if (label.getCollection() != null && label.getCollection().length() > 0) { Paragraph collection = new Paragraph(); collection.setFont(new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)); Chunk c_collection = new Chunk(label.getCollection()); collection.add(c_collection); cell.addElement(collection); } } cell_barcode = new PdfPCell(); cell_barcode.setBorderColor(Color.LIGHT_GRAY); cell_barcode.disableBorderSide(PdfPCell.LEFT); cell_barcode.setVerticalAlignment(PdfPCell.ALIGN_TOP); encoder = new LabelEncoder(label); image = encoder.getImage(); image.setAlignment(Image.ALIGN_TOP); cell_barcode.addElement(image); cells.add(cellCounter, cell); cells_barcode.add(cellCounter, cell_barcode); cellCounter++; // If we have hit a full set of 12 labels, add them to the document // in two columns, filling left column first, then right if (cellCounter == 12) { // add a page of 12 cells in columns of two. for (int x = 0; x < 6; x++) { if (cells.get(x) == null) { PdfPCell c = new PdfPCell(); c.setBorder(0); table.addCell(c); table.addCell(c); } else { table.addCell(cells.get(x)); table.addCell(cells_barcode.get(x)); } if (cells.get(x + 6) == null) { PdfPCell c = new PdfPCell(); c.setBorder(0); table.addCell(c); table.addCell(c); } else { table.addCell(cells.get(x + 6)); table.addCell(cells_barcode.get(x + 6)); } } // Reset to begin next page cellCounter = 0; document.add(table); table = new PdfPTable(4); table.setWidthPercentage(100f); table.setWidths(cellWidths); for (int x = 0; x < 12; x++) { cells.set(x, null); cells_barcode.set(x, null); } } } // end loop through toPrint (for a taxon) counter++; } // end while results has next (for all taxa requested) // get any remaining cells in pairs for (int x = 0; x < 6; x++) { if (cells.get(x) == null) { PdfPCell c = new PdfPCell(); c.setBorder(0); table.addCell(c); table.addCell(c); } else { table.addCell(cells.get(x)); table.addCell(cells_barcode.get(x)); } if (cells.get(x + 6) == null) { PdfPCell c = new PdfPCell(); c.setBorder(0); table.addCell(c); table.addCell(c); } else { table.addCell(cells.get(x + 6)); table.addCell(cells_barcode.get(x + 6)); } } // add any remaining cells document.add(table); try { document.close(); } catch (Exception e) { throw new PrintFailedException("No labels to print." + e.getMessage()); } // Check to see if there was content in the document. if (counter == 0) { result = false; } else { // Printed to pdf ok. result = true; // Increment number printed. i = taxa.iterator(); while (i.hasNext()) { label = i.next(); for (int toPrint = 0; toPrint < label.getNumberToPrint(); toPrint++) { label.setPrinted(label.getPrinted() + 1); } label.setNumberToPrint(0); try { uls.attachDirty(label); } catch (SaveFailedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); throw new PrintFailedException("File not found."); } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); throw new PrintFailedException("Error buiding PDF document."); } catch (OutOfMemoryError e) { System.out.println("Out of memory error. " + e.getMessage()); System.out.println("Failed. Too many labels."); throw new PrintFailedException("Ran out of memory, too many labels at once."); } return result; }
From source file:edu.jhu.jmontan.hw5.CostAsPdf.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./* w w w.j a v a 2 s .c o m*/ * * @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"); HttpSession session = request.getSession(); LineItemReceipt receipt = (LineItemReceipt) session.getAttribute("receipt"); User user = (User) session.getAttribute("user"); try { Document document = new Document(); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); PdfWriter.getInstance(document, buffer); document.open(); document.add(new Paragraph("JOHN HOPKINS ANNUAL SOFTWARE DEVELOPMENT SEMINAR")); document.add(new Paragraph(user.getName())); document.add(new Paragraph("You are registered for the following courses as a " + user.getFormattedEmploymentStatus() + ":")); PdfPTable table = new PdfPTable(2); table.addCell("Course"); table.addCell("Cost"); for (LineItem lineItem : receipt.getLineItems()) { table.addCell(lineItem.getName()); table.addCell("$" + lineItem.getCost()); } table.addCell("Total"); table.addCell("$" + receipt.getTotal()); document.add(table); document.close(); DataOutput output = new DataOutputStream(response.getOutputStream()); byte[] bytes = buffer.toByteArray(); response.setContentLength(bytes.length); for (int i = 0; i < bytes.length; i++) { output.writeByte(bytes[i]); } } catch (DocumentException ex) { Logger.getLogger(CostAsPdf.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:edu.psu.citeseerx.web.ViewPDFPageController.java
License:Apache License
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException { String errorTitle = "Document Not Found"; String doi = request.getParameter("doi"); String rep = request.getParameter("rep"); String page = request.getParameter("page"); Map<String, Object> model = new HashMap<String, Object>(); if (doi == null || rep == null) { model.put("pagetitle", errorTitle); return new ModelAndView("viewDocError", model); }/*from w ww .j a va 2 s. c o m*/ int iPage; try { iPage = Integer.parseInt(page); } catch (NumberFormatException e) { e.printStackTrace(); model.put("pagetitle", errorTitle); return new ModelAndView("viewDocError", model); } try { PdfReader reader = csxdao.getPdfReader(doi, rep); Document document = new Document(reader.getPageSizeWithRotation(iPage)); ByteArrayOutputStream baos = new ByteArrayOutputStream(OUTPUT_BYTE_ARRAY_INITIAL_SIZE); PdfCopy copy = new PdfCopy(document, baos); document.open(); PdfImportedPage docPage = copy.getImportedPage(reader, iPage); copy.addPage(docPage); document.close(); response.setContentType("application/pdf"); response.setContentLength(baos.size()); ServletOutputStream out = response.getOutputStream(); baos.writeTo(out); out.flush(); } catch (IOException e) { e.printStackTrace(); model.put("pagetitle", errorTitle); return new ModelAndView("viewDocError", model); } catch (DocumentException e) { e.printStackTrace(); model.put("pagetitle", errorTitle); return new ModelAndView("viewDocError", model); } return null; }
From source file:edu.ucsf.rbvi.clusterMaker2.internal.treeview.dendroview.GraphicsExportPanel.java
License:Open Source License
private void pdfSave(String format) { com.lowagie.text.Rectangle pageSize = PageSize.LETTER; Document document = new Document(pageSize); try {/*w w w . j a v a 2s .c om*/ OutputStream output = new BufferedOutputStream(new FileOutputStream(getFile())); PdfWriter writer = PdfWriter.getInstance(document, output); document.open(); PdfContentByte cb = writer.getDirectContent(); Graphics2D g = cb.createGraphics(pageSize.getWidth(), pageSize.getHeight(), new DefaultFontMapper()); double imageScale = Math.min(pageSize.getWidth() / ((double) estimateWidth() + getBorderPixels()), pageSize.getHeight() / ((double) estimateHeight() + getBorderPixels())); g.scale(imageScale, imageScale); drawAll(g, 1.0); g.dispose(); } catch (Exception e) { JOptionPane.showMessageDialog(this, new JTextArea("Dendrogram export had problem " + e)); // logger.error("Exception " + e); // e.printStackTrace(); } document.close(); }
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 w w . ja v a2 s . c o 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 va 2 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 ww w . j av a 2 s. co 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); } }