List of usage examples for com.lowagie.text.pdf BaseFont IDENTITY_H
String IDENTITY_H
To view the source code for com.lowagie.text.pdf BaseFont IDENTITY_H.
Click Source Link
From source file:FontGlyphTableRender.java
License:Open Source License
private String getITextFontFamilyName(File selFile) { Set set = ITextFontResolver.getDistinctFontFamilyNames(selFile.getPath(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);// w w w . jav a 2s. c om System.out.println("All family names reported by iText for " + selFile.getPath() + ": " + set.toString()); return (String) set.iterator().next(); }
From source file:FontGlyphTableRender.java
License:Open Source License
private void renderPDF(Document doc) { String msgToUser = ""; File f;//from www .j av a 2 s.com try { f = File.createTempFile("flying-saucer-glyph-test", ".pdf"); } catch (IOException e) { // JOptionPane.showMessageDialog(frame, "Can't create temp file for PDF output, err: " + e.getMessage()); return; } final ITextRenderer renderer = new ITextRenderer(); FileOutputStream fos = null; try { fos = new FileOutputStream(f); BufferedOutputStream bos = new BufferedOutputStream(fos); renderer.setDocument(doc, null, new XhtmlNamespaceHandler()); ITextFontResolver resolver = renderer.getFontResolver(); // TODO: encoding is hard-coded as IDENTITY_H; maybe give user option to override resolver.addFont(fontPathTF.getText(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED); renderer.layout(); renderer.createPDF(bos); msgToUser = "Rendered PDF: " + f.getCanonicalPath(); } catch (FileNotFoundException e) { msgToUser = "Can't create PDF, err: " + e.getMessage(); } catch (DocumentException e) { msgToUser = "Can't create PDF, err: " + e.getMessage(); } catch (IOException e) { msgToUser = "Can't create PDF, err: " + e.getMessage(); } finally { if (fos != null) { try { fos.close(); } catch (IOException e) { // swallow } } } if (msgToUser.length() != 0) { final String finalMsg = msgToUser; SwingUtilities.invokeLater(new Runnable() { public void run() { JOptionPane.showMessageDialog(frame, finalMsg); } }); } }
From source file:alfio.controller.support.TemplateProcessor.java
License:Open Source License
public static PDFTemplateGenerator buildPDFTicket(Locale language, Event event, TicketReservation ticketReservation, Ticket ticket, TicketCategory ticketCategory, Organization organization, TemplateManager templateManager) { return () -> { String qrCodeText = ticket.ticketCode(event.getPrivateKey()); ///*from w w w .j av a 2 s . c o m*/ Map<String, Object> model = new HashMap<>(); model.put("ticket", ticket); model.put("reservation", ticketReservation); model.put("ticketCategory", ticketCategory); model.put("event", event); model.put("organization", organization); model.put("qrCodeDataUri", "data:image/png;base64," + Base64.getEncoder().encodeToString(createQRCode(qrCodeText))); model.put("deskPaymentRequired", Optional.ofNullable(ticketReservation.getPaymentMethod()) .orElse(PaymentProxy.STRIPE).isDeskPaymentRequired()); String page = templateManager.renderClassPathResource("/alfio/templates/ticket.ms", model, language, TemplateOutput.HTML); ITextRenderer renderer = new ITextRenderer(); renderer.setDocumentFromString(page); try { renderer.getFontResolver().addFont("/alfio/font/DejaVuSansMono.ttf", BaseFont.IDENTITY_H, true); } catch (IOException | DocumentException e) { log.warn("error while loading DejaVuSansMono.ttf font", e); } renderer.layout(); return renderer; }; }
From source file:ambit.data.qmrf.Qmrf_Xml_Pdf.java
License:Open Source License
public Qmrf_Xml_Pdf(String ttffont) { super();/*from www.ja v a 2 s . co m*/ try { this.ttffont = ttffont; docBuilder = docBuilderFactory.newDocumentBuilder(); nodeBuilder = docBuilderFactory.newDocumentBuilder(); nodeBuilder.setErrorHandler(new ErrorHandler() { public void error(SAXParseException arg0) throws SAXException { throw new SAXException(arg0); } public void fatalError(SAXParseException arg0) throws SAXException { throw new SAXException(arg0); } public void warning(SAXParseException arg0) throws SAXException { } }); //PRIndirectReference pri; //pri. try { baseFont = BaseFont.createFont(ttffont, //"c:\\windows\\fonts\\times.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); System.out.println(ttffont); } catch (Exception x) { x.printStackTrace(); baseFont = BaseFont.createFont("c:\\windows\\fonts\\times.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); System.out.println("Default font c:\\windows\\fonts\\times.ttf"); } font = new Font(baseFont, 12); bfont = new Font(baseFont, 12, Font.BOLD); } catch (Exception x) { docBuilder = null; } }
From source file:ariba.ui.aribaweb.util.AWUtil.java
License:Apache License
/** * Utility method to convert HTML input to PDF * @param htmlInputStream - HTML input stream * @param outputStream - PDF output stream *//* w w w. j av a2 s . co m*/ public static void convertHTMLToPDF(InputStream htmlInputStream, OutputStream outputStream, String fontFileLocation) { try { Tidy tidy = new Tidy(); tidy.setXHTML(true); tidy.setShowWarnings(false); File dir = SystemUtil.getLocalTempDirectory(); File tempFile = File.createTempFile("pdf", "pdf", dir); FileOutputStream temp = new FileOutputStream(tempFile); tidy.parse(htmlInputStream, temp); temp.close(); ITextRenderer renderer = new ITextRenderer(); if (!StringUtil.nullOrEmptyOrBlankString(fontFileLocation)) { renderer.getFontResolver().addFont(fontFileLocation, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); } renderer.setDocument(tempFile); renderer.layout(); renderer.createPDF(outputStream); if (tempFile.exists()) { tempFile.delete(); } } catch (IOException exception) { throw new AWGenericException( Fmt.S("Exception when using temp file : %s", SystemUtil.stackTrace(exception))); } catch (DocumentException e) { throw new AWGenericException(Fmt.S("Failed to generate pdf content : %s", SystemUtil.stackTrace(e))); } }
From source file:be.fedict.eid.tsl.Tsl2PdfExporter.java
License:Open Source License
public Tsl2PdfExporter() { initializeFontResources();/* w w w. j a v a 2s. co m*/ title0Font = FontFactory.getFont("DejaVuSerifCondensed-Bold", BaseFont.IDENTITY_H, true, 30, Font.BOLD); title1Font = FontFactory.getFont("DejaVuSerifCondensed-BoldItalic", BaseFont.IDENTITY_H, true, 16, Font.BOLD | Font.ITALIC); title2Font = FontFactory.getFont("DejaVuSerifCondensed-BoldItalic", BaseFont.IDENTITY_H, true, 16, Font.BOLD | Font.ITALIC); title3Font = FontFactory.getFont("DejaVuSerifCondensed-Italic", BaseFont.IDENTITY_H, true, 16, Font.ITALIC); title4Font = FontFactory.getFont("DejaVuSerifCondensed-Italic", BaseFont.IDENTITY_H, true, 12, Font.BOLD); labelFont = FontFactory.getFont("DejaVuSerifCondensed-Italic", BaseFont.IDENTITY_H, true, 11, Font.ITALIC); valueFont = FontFactory.getFont("DejaVuSerifCondensed", BaseFont.IDENTITY_H, true, 11, Font.NORMAL); monoFont = FontFactory.getFont("DejaVuSansMono", BaseFont.IDENTITY_H, true, 5, Font.NORMAL); headerFooterFont = FontFactory.getFont("DejaVuSerifCondensed", BaseFont.IDENTITY_H, true, 10, Font.NORMAL); }
From source file:com.amashchenko.struts2.pdfstream.PdfStreamResult.java
License:Apache License
private void createPdfStream(final String content, final String baseUrl, final OutputStream outputStream) throws DocumentException, IOException, URISyntaxException { ITextRenderer renderer = new ITextRenderer(); // for unicode renderer.getFontResolver().addFont(FONT_FILE_PATH, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); renderer.setDocumentFromString(content, baseUrl); renderer.layout();/*from ww w . ja v a 2 s . c o m*/ renderer.createPDF(outputStream); }
From source file:com.amphisoft.epub2pdf.content.TextFactory.java
License:Open Source License
public static boolean setDefaultFontByName(String fontName) { fontName = fontName.toLowerCase().trim(); if (TextFactory.fontFamilyRegistered(fontName)) { Font newDefaultFont = null; try {/* www . j a v a2s . co m*/ newDefaultFont = FontFactory.getFont(fontName, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); } catch (ExceptionConverter eC) { if (eC.getException() instanceof UnsupportedEncodingException) { newDefaultFont = FontFactory.getFont(fontName, FontFactory.defaultEncoding, BaseFont.EMBEDDED); } else { throw new RuntimeException(eC); } } newDefaultFont.setSize(_defaultFontSize); _defaultFont = newDefaultFont; return true; } else { return false; } }
From source file:com.aripd.clms.service.ContractServiceBean.java
@Override public void generatePdf(ContractEntity contract) { String baseFontUrl = "/fonts/Quivira.otf"; FontFactory.register(baseFontUrl);//from w ww . java 2 s .c o m ByteArrayOutputStream output = new ByteArrayOutputStream(); try { BaseFont bf = BaseFont.createFont(baseFontUrl, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); Font font18n = new Font(bf, 18, Font.NORMAL); Font font12n = new Font(bf, 12, Font.NORMAL); Font font8n = new Font(bf, 8, Font.NORMAL); Font font8nbu = new Font(bf, 8, Font.BOLD | Font.UNDERLINE); Font font8ng = new Font(bf, 8, Font.NORMAL, Color.DARK_GRAY); Font font6n = new Font(bf, 6, Font.NORMAL); Document document = new Document(PageSize.A4); PdfWriter writer = PdfWriter.getInstance(document, output); document.open(); addMetaData(document); addTitlePage(document, contract); Image imgBlue = Image.getInstance(1, 1, 3, 8, new byte[] { (byte) 0, (byte) 0, (byte) 255, }); imgBlue.scaleAbsolute(document.getPageSize().getWidth(), 10); imgBlue.setAbsolutePosition(0, document.getPageSize().getHeight() - imgBlue.getScaledHeight()); PdfImage stream = new PdfImage(imgBlue, "", null); stream.put(new PdfName("ITXT_SpecialId"), new PdfName("123456789")); PdfIndirectObject ref = writer.addToBody(stream); imgBlue.setDirectReference(ref.getIndirectReference()); document.add(imgBlue); PdfPTable table = new PdfPTable(2); table.setWidthPercentage(100); PdfPCell cell = new PdfPCell(new Paragraph(contract.getName(), font18n)); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); cell.setPadding(5); table.addCell(cell); cell = new PdfPCell(new Paragraph("Version: " + contract.getVersion(), font8n)); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); cell.setPadding(5); table.addCell(cell); cell = new PdfPCell(new Paragraph("Review: " + contract.getReview(), font8n)); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); cell.setPadding(5); table.addCell(cell); cell = new PdfPCell(new Paragraph(contract.getRemark(), font12n)); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); cell.setPadding(5); table.addCell(cell); document.add(table); // Start a new page document.newPage(); HTMLWorker htmlWorker = new HTMLWorker(document); htmlWorker.parse(new StringReader(contract.getRemark())); // Start a new page document.newPage(); document.add(new Paragraph("Review Board", font18n)); document.add(new LineSeparator(0.5f, 100, null, 0, -5)); table = new PdfPTable(3); table.setWidthPercentage(100); cell = new PdfPCell(new Paragraph("Review Board", font18n)); cell.setColspan(3); table.addCell(cell); cell = new PdfPCell(new Paragraph("Version", font12n)); table.addCell(cell); cell = new PdfPCell(new Paragraph("Date", font12n)); table.addCell(cell); cell = new PdfPCell(new Paragraph("Review", font12n)); table.addCell(cell); for (HistoryContractEntity history : historyContractService.listing(contract)) { cell = new PdfPCell(new Paragraph(history.getVersion().toString(), font8n)); table.addCell(cell); cell = new PdfPCell(new Paragraph(history.getStartdate().toString(), font8n)); table.addCell(cell); cell = new PdfPCell(new Paragraph(history.getReview(), font8n)); table.addCell(cell); } document.add(table); document.close(); FacesContext context = FacesContext.getCurrentInstance(); HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse(); response.reset(); response.addHeader("Content-Type", "application/force-download"); String filename = URLEncoder.encode(contract.getName() + ".pdf", "UTF-8"); // response.addHeader("Content-Disposition", "attachment; filename=\"" + filename + "\""); response.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + filename); response.getOutputStream().write(output.toByteArray()); response.getOutputStream().flush(); context.responseComplete(); context.renderResponse(); } catch (BadPdfFormatException | IOException ex) { Logger.getLogger(ContractServiceBean.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ex) { Logger.getLogger(ContractServiceBean.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.fcore.base.fileSystem.utils.FileUtil.java
/** * convert txt file to pdf /*from w w w .j a v a 2 s . co m*/ * @param originalPath * @param dirPath */ public static void txt2pdf(String originalPath, String dirPath) { com.lowagie.text.Document document = null; BufferedReader read = null; long old = System.currentTimeMillis(); try { document = new com.lowagie.text.Document(PageSize.A4, 80, 80, 60, 30); PdfWriter.getInstance(document, new FileOutputStream(dirPath)); document.open(); BaseFont bfChinese = BaseFont.createFont(ReadCreatePdf.class.getResource("/") + "/simsun.ttc,1", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); Font FontChinese = new Font(bfChinese, 18, Font.NORMAL); FileInputStream fstream = new FileInputStream(originalPath); DataInputStream in = new DataInputStream(fstream); read = new BufferedReader(new InputStreamReader(in, "gb2312")); String line = null; while ((line = read.readLine()) != null) { Paragraph t = new Paragraph(line, FontChinese); t.setAlignment(Element.ALIGN_LEFT); t.setLeading(20.0f); document.add(t); } } catch (Exception e) { e.printStackTrace(); } finally { try { read.close(); document.close(); } catch (IOException e) { e.printStackTrace(); } } long now = System.currentTimeMillis(); System.out.println("" + ((now - old) / 1000.0) + "\n\n" + "?:" + dirPath); }