Example usage for com.lowagie.text.pdf BaseFont EMBEDDED

List of usage examples for com.lowagie.text.pdf BaseFont EMBEDDED

Introduction

In this page you can find the example usage for com.lowagie.text.pdf BaseFont EMBEDDED.

Prototype

boolean EMBEDDED

To view the source code for com.lowagie.text.pdf BaseFont EMBEDDED.

Click Source Link

Document

if the font has to be embedded

Usage

From source file:de.unigoettingen.sub.commons.contentlib.pdflib.PDFTitlePage.java

License:Apache License

/************************************************************************************
 * render paragraph into title page/*from w ww.j a v a 2s  .  c om*/
 * 
 * @param pdftpp given {@link PDFTitlePageParagraph} to render
 * @param pdfdoc given {@link com.lowagie.text.Document} where to render
 * @throws DocumentException
 ************************************************************************************/
private void renderParagraph(PDFTitlePageParagraph pdftpp, com.lowagie.text.Document pdfdoc)
        throws DocumentException {
    String text = pdftpp.getContent();
    if (text == null) {
        text = "";
    }
    int fontstyle = Font.NORMAL;
    if (pdftpp.getFonttype().equals("bold")) {
        fontstyle = Font.BOLD;
    }
    if (pdftpp.getFonttype().equals("italic")) {
        fontstyle = Font.ITALIC;
    }
    if (pdftpp.getFonttype().equals("bolditalic")) {
        fontstyle = Font.BOLDITALIC;
    }
    if (pdftpp.getFonttype().equals("underline")) {
        fontstyle = Font.UNDERLINE;
    }
    if (pdftpp.getFonttype().equals("strikethru")) {
        fontstyle = Font.STRIKETHRU;
    }
    // create BaseFont for embedding
    try {
        Font font = FontFactory.getFont("Arial", BaseFont.CP1252, BaseFont.EMBEDDED, pdftpp.getFontsize(),
                fontstyle);
        Paragraph p2 = new Paragraph(new Chunk(text, font));
        // Paragraph p2=new Paragraph(text,
        // FontFactory.getFont(FontFactory.TIMES_ROMAN, 12));
        pdfdoc.add(p2);
    } catch (Exception e) {
        LOGGER.error("error occured while generating paragraph for titlepage", e);
    }
}

From source file:gov.anl.aps.cdb.portal.plugins.support.icmsLink.IcmsWatermarkUtility.java

License:Open Source License

/**
 * Adds a stamp of some metadata to ICMS documents.
 *
 * Function Credit: Thomas Fors/*  w w  w  . j  a va 2 s.c  o m*/
 *     
 * @return byte array ologgerf the stamped PDF file
 * @throws DocumentException - Error loading pdfstamper or creating font
 * @throws IOException - Error performing IO operation 
 * @throws Base64DecodingException - Error converting downloadContent string to byte[]
 */
private byte[] addWatermarkToPDFFile() throws Base64DecodingException, DocumentException, IOException {
    byte[] pdfBytes = Base64.decode(downloadContentBase64Encoded);

    DateTimeFormatter dtf = DateTimeFormatter.ofPattern("MM/dd/yy hh:mm:ss a");
    LocalDateTime now = LocalDateTime.now();
    String downloadTime = dtf.format(now);

    UserInfo user = (UserInfo) SessionUtility.getUser();
    String username = null;
    if (user != null) {
        username = user.getUsername();
    } else {
        username = "unknown user";
    }
    String bottomMessage = "Downloaded via APS CDB by: " + username + " at " + downloadTime;

    controlledRev = updateOptionalValue(controlledRev);
    dnsCollectionId = updateOptionalValue(dnsCollectionId);
    dnsDocNumber = updateOptionalValue(dnsDocNumber);

    String watermarkContents = "Content ID: " + docName;
    watermarkContents += "      Rev: " + controlledRev;
    watermarkContents += "      Released: " + date;
    watermarkContents += "      DNS Collection ID: " + dnsCollectionId;
    watermarkContents += "      DNS Document ID: " + dnsDocNumber;

    PdfReader pdfReader = new PdfReader(pdfBytes);
    int n = pdfReader.getNumberOfPages();

    ByteArrayOutputStream out = new ByteArrayOutputStream();

    PdfStamper stamp = new PdfStamper(pdfReader, out);

    PdfContentByte over;
    BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED);

    for (int i = 0; i < n; i++) {
        over = stamp.getOverContent(i + 1);
        over.beginText();
        over.setTextMatrix(30, 30);
        over.setFontAndSize(bf, 10);
        over.setColorFill(new Color(0x80, 0x80, 0x80));
        over.showTextAligned(Element.ALIGN_LEFT, watermarkContents, 25, 25, 90);
        over.showTextAligned(Element.ALIGN_LEFT, bottomMessage, 50, 10, 0);
        if (status.equals(ICMS_UNDER_REV_STATUS)) {
            over.setColorFill(new Color(0xFF, 0x00, 0x00));
        }
        //over.showTextAligned(Element.ALIGN_LEFT, status, 25, 25 + bf.getWidthPoint(watermarkContents + " - ", 10), 90);

        over.endText();
    }
    stamp.close();

    return out.toByteArray();
}

From source file:gr.abiss.calipso.util.PdfUtils.java

License:Open Source License

public static void writePdf(String fontDir, String resourcesBasePath, OutputStream os, String html) {
    try {//from   w  ww  .j  a  v  a 2 s .  com
        // Create a buffer to hold the cleaned up HTML
        // Note: you can safely ignore both flush() and close(),
        // as they do nothing in ByteArrayOutputStream's implementation.
        // ByteArrayOutputStream out = new ByteArrayOutputStream();

        // Clean up the HTML to be well formed
        HtmlCleaner cleaner = new HtmlCleaner();
        CleanerProperties props = cleaner.getProperties();
        props.setAdvancedXmlEscape(true);
        props.setRecognizeUnicodeChars(true);
        props.setTranslateSpecialEntities(true);
        props.setUseCdataForScriptAndStyle(false);
        props.setOmitXmlDeclaration(false);
        props.setOmitDoctypeDeclaration(false);
        TagNode node = cleaner.clean(html);
        // write to the ByteArray buffer
        html = new PrettyXmlSerializer(props).getAsString(node);
        // logger.info("CLEANED HTML: " + html);
        // update the html string using the cleaned-up version
        // html = new String(out.toByteArray());

        ITextRenderer renderer = new ITextRenderer();
        renderer.getFontResolver().addFont(fontDir + File.separator + "ARIALUNI.TTF", BaseFont.IDENTITY_H,
                BaseFont.EMBEDDED);
        if (StringUtils.isNotBlank(resourcesBasePath)) {
            try {
                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

                factory.setValidating(false);
                factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);

                DocumentBuilder builder = factory.newDocumentBuilder();
                InputSource is = new InputSource(new StringReader(html));
                Document doc = builder.parse(is);
                String rsPath = new File(resourcesBasePath + File.separator).toURI().toURL().toString();
                renderer.setDocument(doc, rsPath);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        } else {
            renderer.setDocumentFromString(html);
        }
        renderer.layout();
        renderer.createPDF(os);
    } catch (Exception e) {
        logger.error("Failed to creare PDF for item, html: \n" + html, e);
    }
}

From source file:ilarkesto.integration.itext.Paragraph.java

License:Open Source License

private Font createFont(String name, FontStyle fontStyle) {
    Font font;// w  w w . ja  va2  s  .c  o  m
    try {
        font = new Font(BaseFont.createFont(name, BaseFont.IDENTITY_H, BaseFont.EMBEDDED));
    } catch (Exception ex) {
        throw new RuntimeException("Loading font failed: " + name, ex);
    }

    if (fontStyle != null) {
        font.setStyle(createStyle(fontStyle));
        font.setSize(PdfBuilder.mmToPoints(fontStyle.getSize()));
        font.setColor(fontStyle.getColor());
    }

    return font;
}

From source file:ispyb.client.biosaxs.pdf.DataAcquisitionPDFReport.java

License:Open Source License

private Font getFont(String baseFont) {
    BaseFont bf = null;//  ww  w.j  a  v a 2 s  .  c om
    Font font;
    try {
        bf = BaseFont.createFont(baseFont.toString(), FONTS[0][1], BaseFont.EMBEDDED);
    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    font = new Font(bf, 6);

    return font;

}

From source file:ispyb.client.biosaxs.pdf.DataAcquisitionPDFReport.java

License:Open Source License

private Font getFont() {
    BaseFont bf = null;//from   w  ww .j  av a 2s  .  co  m
    Font font;
    try {
        bf = BaseFont.createFont(FONTS[0][0], FONTS[0][1], BaseFont.EMBEDDED);
    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    font = new Font(bf, 6);

    return font;
}

From source file:ispyb.client.biosaxs.pdf.DataAcquisitionPDFReport.java

License:Open Source License

private ByteArrayOutputStream exportAsPdf(Experiment3VO experiment, List<Buffer3VO> buffers,
        Proposal3VO proposal) throws Exception {
    Document document = new Document(PageSize.A4.rotate(), 10, 10, 20, 20);

    document.addTitle("exportSamplesView");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PdfWriter.getInstance(document, baos);
    HeaderFooter header = new HeaderFooter(
            new Phrase(proposal.getTitle() + " " + proposal.getCode() + proposal.getNumber()), false);

    header.setAlignment(Element.ALIGN_CENTER);
    header.getBefore().getFont().setSize(8);
    HeaderFooter footer = new HeaderFooter(new Phrase("Page n."), true);
    footer.setAlignment(Element.ALIGN_RIGHT);
    footer.setBorderWidth(1);/*  w  ww.  j  a  v  a 2  s. c  om*/
    footer.getBefore().getFont().setSize(6);

    document.setHeader(header);
    document.setFooter(footer);

    document.open();

    BaseFont bf = BaseFont.createFont(FONTS[0][0], FONTS[0][1], BaseFont.EMBEDDED);
    Font font = new Font(bf, 6);
    document.add(new Paragraph("Data Acquisition: " + experiment.getName(), font));
    document.add(new Paragraph("Type: " + experiment.getType(), font));
    document.add(new Paragraph("Date: " + experiment.getCreationDate(), font));
    document.add(new Paragraph("Proposal: " + proposal.getCode() + proposal.getNumber(), font));
    document.add(new Paragraph("Title: " + proposal.getTitle(), font));

    document.add(new Paragraph(" "));
    document.add(new Paragraph("Measurements", PdfRtfExporter.FONT_DOC_BOLD));
    document.add(new Paragraph(" "));
    document.add(this.getMeasurementTable(experiment, buffers));
    document.newPage();
    document.add(new Paragraph(" "));
    document.add(new Paragraph("Analysis", PdfRtfExporter.FONT_DOC_BOLD));
    document.add(new Paragraph(" "));
    document.add(this.getAnalysis(experiment, buffers));
    document.newPage();
    document.add(this.getImageTable(experiment, buffers));

    document.close();
    return baos;
}

From source file:jdbreport.model.io.pdf.itext2.ReportFontMapper.java

License:Apache License

private BaseFont getDefaultBaseFont() throws DocumentException, IOException {
    if (getDefaultFont() != null) {
        return BaseFont.createFont(getDefaultFont(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
    }// ww w . ja v  a2  s . c  om
    return null;
}

From source file:jmemorize.core.io.PdfRtfBuilder.java

License:Open Source License

private static void export(Lesson lesson, int mode, File file) throws IOException {
    logger = Main.getLogger();/*from  w  w  w .j  a va  2s.c  o  m*/

    FontFactory.registerDirectories();
    // set up the fonts we will use to write the front and back of cards
    String frontFontName = Settings.loadFont(FontType.CARD_FRONT).getFont().getFamily();
    frontFont = FontFactory.getFont(frontFontName, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);

    if (frontFont == null) {
        logger.warning("FontFactory returned null (front) font for: " + frontFontName);
    }

    String backFontName = Settings.loadFont(FontType.CARD_FLIP).getFont().getFamily();
    backFont = FontFactory.getFont(backFontName, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);

    if (backFont == null) {
        logger.warning("FontFactory returned null (back) font for: " + backFontName);
    }

    try {
        Document doc = new Document();
        OutputStream out = new FileOutputStream(file);

        switch (mode) {
        case PDF_MODE:
            PdfWriter.getInstance(doc, out);
            break;

        case RTF_MODE:
            RtfWriter2.getInstance(doc, out);
            break;
        }

        doc.setHeader(new HeaderFooter(new Phrase(file.getName()), false));
        doc.open();

        // add cards in subtrees
        List<Category> subtree = lesson.getRootCategory().getSubtreeList();
        for (Category category : subtree) {
            writeCategory(doc, category);
        }

        doc.close();

    } catch (Throwable t) {
        throw (IOException) new IOException("Could not export to PDF").initCause(t);
    }
}

From source file:lt.bsprendimai.ddesk.pdf.PDFTicket.java

License:Apache License

public byte[] writePage() throws Exception {
    ByteArrayOutputStream bout = new ByteArrayOutputStream();

    try {/*from  w  ww.j a v  a  2  s .  co  m*/
        logo = Image.getInstance(root.getAbsolutePath() + "/logo.gif");
        logo.setAlignment(Image.ALIGN_LEFT);
    } catch (Exception exc) {
        exc.printStackTrace();
    }

    baseArial = BaseFont.createFont(root.getAbsolutePath() + "/objects/arial.ttf", BaseFont.CP1257,
            BaseFont.EMBEDDED);

    Document doc = new Document(PageSize.A4, 56.5354331f, 22.6771654f, 28.3464567f, 25.0f);
    PdfWriter.getInstance(doc, bout);

    doc.open();

    logo.setAbsolutePosition(28.3464567f, doc.getPageSize().height() - logo.height() - 25.0f);
    doc.add(logo);
    Paragraph pg = new Paragraph(sdf.format(new Date()), new Font(baseArial, 10));
    pg.setAlignment(Element.ALIGN_RIGHT);
    doc.add(pg);
    doc.add(new Phrase("\n\n\n"));

    writeClientInfo(doc);
    writeTicketInfo(doc);
    writeJobInfo(doc);
    writeWorkerInfo(doc);

    doc.close();

    return bout.toByteArray();
}