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

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

Introduction

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

Prototype

String CP1252

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

Click Source Link

Document

A possible encoding.

Usage

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

License:Apache License

/************************************************************************************
 * render paragraph into title page/*  w  w w .ja  v  a  2  s  . 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:domain.reports.menu.PDFReportMenu.java

License:LGPL

@Override
protected void createPDF(GenericTransaction data, ByteArrayOutputStream buf) throws Throwable {

    //inicializar documento: tamano de pagina, orientacion, margenes
    Document doc = new Document();
    PdfWriter docWriter = PdfWriter.getInstance(doc, buf);
    doc.setPageSize(PageSize.LETTER.rotate());
    doc.setMargins(30, 30, 30, 40);/*from ww  w  . ja  v  a2 s. c om*/

    doc.open();

    //crear fonts por defecto
    tblHeaderFont = new Font(Font.HELVETICA, 10f, Font.BOLD);
    tblBodyFont = new Font(Font.HELVETICA, 10f, Font.NORMAL);

    //definir pie de pagina del lado izquierdo
    String footerText = this.getFooter(); //read it from config.xml or web.xml
    String reportDate = StringUtil.formatDate(new java.util.Date(), "dd-MM-yyyy HH:mm");

    //crear template (objeto interno de IText) y manejador de evento 
    //para imprimir el pie de pagina
    bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
    cb = docWriter.getDirectContent();
    tpl = cb.createTemplate(20, 14);
    docWriter.setPageEvent(new PDFPageEvents(footerText, pageXofY, tpl, bf, cb, reportDate));

    //titulo - lo lee de config.xml por defecto
    reportTitle = getReportTitle();
    Paragraph t = new Paragraph(reportTitle, new Font(Font.HELVETICA, 14f, Font.BOLD));
    t.setAlignment(Rectangle.ALIGN_RIGHT);
    doc.add(t);

    //logo
    img = Image.getInstance(getImage(this.getServerBaseURL() + logoPath, false));
    img.scalePercent(100);
    float imgY = doc.top() - img.getHeight();
    float imgX = doc.left();
    img.setAbsolutePosition(imgX, imgY);
    doc.add(img);

    //blank line
    doc.add(new Paragraph(" "));
    //blank line
    doc.add(new Paragraph(" "));
    //blank line
    doc.add(new Paragraph(" "));

    //for each master record print a master/detail section
    MasterDetailReader dataobj = (MasterDetailReader) data;
    Recordset master = dataobj.getRecordset("master");
    master.top();
    while (master.next()) {
        //blank line
        doc.add(new Paragraph(" "));

        //print master section
        doc.add(getGroupMaster(master));

        //print detail section
        doc.add(getGroupDetail(master, dataobj.getDetail(master)));

    }

    //print grand total
    doc.add(new Paragraph(" "));

    doc.close();
    docWriter.close();

}

From source file:edtscol.client.Imprime.java

License:CeCILL license

private void ecrireTexteHor(String texte, float x, float y, float l, float h, float ph, float pv, int szf) {
    float x1, y1;
    try {/*  www .  jav a  2s . co  m*/
        BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        cb.setFontAndSize(bf, szf);
        x1 = x + ph;
        y1 = y - pv;
        if (bf.getWidthPoint(texte, szf) > l) {
            cesure(bf, szf, texte, x1, y1, l, h);
        } else {
            cb.beginText();
            cb.setTextMatrix(x1, y1);
            cb.showText(texte);
            cb.endText();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:edtscol.client.Imprime.java

License:CeCILL license

private void graduationEdt(float x, float y, float l, float h, int nb) {
    float taille = l / (nb - 1);
    float x1, y1;
    y1 = y;/*from   w w  w.j a  v a2 s  .com*/
    x1 = x;
    for (int i = 0; i < nb; i++) {
        try {
            if (i > 0) {
                x1 = x1 + taille;
            }
            BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);

            if (i == 0 || i == nb - 1) {
                cb.setLineWidth(1.0f);
            } else {
                cb.setLineWidth(0.1f);
            }

            cb.moveTo(x1, y1);
            cb.lineTo(x1, y1 - (h * 7.0f));
            cb.stroke();

            cb.setLineWidth(0.2f);
            if (i < nb - 1) {
                for (int j = 1; j < 4; j++) {
                    float tq = (taille / 04.f) * j;
                    cb.moveTo(x1 + tq, y1);
                    cb.lineTo(x1 + tq, y1 - (h * 7.0f));
                    cb.stroke();
                }
            }
            cb.setLineWidth(1.0f);
            cb.beginText();
            bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
            cb.setFontAndSize(bf, 12);
            cb.setTextMatrix(x1 - 5.0f, y1 + 1.0f);
            int heure = i * 2 + 8;
            String texte = new Integer(heure).toString() + "h";
            cb.showText(texte);
            cb.endText();
        } catch (Exception e) {
        }
    }
    // ligne de fin de journe
    y1 = y1 - taille;
    x1 = x + l;
    cb.moveTo(x1, y1);
    cb.lineTo(x1 + lgs, y1);
    cb.stroke();
}

From source file:io.vertigo.dynamo.plugins.export.pdf.PDFAdvancedPageNumberEvents.java

License:Apache License

/** {@inheritDoc} */
@Override/*from ww w .j av  a2s  .  com*/
public void onOpenDocument(final PdfWriter writer, final Document document) {
    try {
        bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        cb = writer.getDirectContent();
        template = cb.createTemplate(50, 50);
    } catch (final DocumentException | IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:io.vertigo.quarto.plugins.export.pdf.PDFAdvancedPageNumberEvents.java

License:Apache License

/** {@inheritDoc} */
@Override/*from   w  w  w .ja  va 2s . co  m*/
public void onOpenDocument(final PdfWriter writer, final Document document) {
    try {
        bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        cb = writer.getDirectContent();
        template = cb.createTemplate(50, 50);
    } catch (final DocumentException | IOException e) {
        throw WrappedException.wrap(e);
    }
}

From source file:is.idega.idegaweb.egov.printing.business.DocumentBusinessBean.java

License:Open Source License

private PdfTemplate createPasswordLetterTemplate(PdfWriter writer) throws Exception {
    IWBundle iwb = getIWApplicationContext().getIWMainApplication()
            .getBundle(is.idega.idegaweb.egov.message.business.MessageConstants.IW_BUNDLE_IDENTIFIER);
    PdfContentByte cb = writer.getDirectContent();

    float tempLength = 511f;
    float tempHeight = getPointsFromMM(40);
    PdfTemplate template = cb.createTemplate(tempLength, tempHeight);

    if (addTemplateHeader()) {
        BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        String mail_zip = iwb.getProperty("commune.mail_zip");
        String mail_name = iwb.getProperty("commune.mail_name");

        float convLengt = 100f;
        float convHeight = 60f;
        template.rectangle(0f, 0f, convLengt, convHeight);
        template.moveTo(0f, 0f);/*from w w  w .j  a v a  2s  .c o m*/
        template.lineTo(convLengt, convHeight);
        template.moveTo(convLengt, 0f);
        template.lineTo(0f, convHeight);
        template.stroke();
        template.beginText();
        template.setFontAndSize(bf, 11f);
        template.setTextMatrix(5f, 40f);
        template.showText(mail_name);

        template.endText();
        template.beginText();
        template.setFontAndSize(bf, 11f);
        template.setTextMatrix(5f, 25f);
        template.showText(mail_zip);
        template.endText();

        Image porto = Image.getInstance(iwb.getResourcesRealPath() + "/shared/porto_betalt.jpg");
        porto.scaleAbsolute(60f, 60f);

        // Image portoA =Image.getInstance(iwb.getResourcesRealPath()+
        // "/shared/porto_a_logo.jpg");
        // float Awidth = 2.3f*60f;
        // portoA.scaleToFit(Awidth,60f);

        float portoXPos = tempLength - 90f;
        // float portoAXPos = portoXPos-Awidth-5f;
        template.addImage(porto, 60f, 0f, 0f, 60f, portoXPos, 0);
        // template.addImage(portoA,Awidth,0f,0f,60f,portoAXPos,0);
    }

    return template;
}

From source file:is.idega.idegaweb.egov.printing.business.DocumentBusinessBean.java

License:Open Source License

public void createHeaderDate(Document document, PdfWriter writer, String dateString) throws DocumentException {
    /*//w ww  . jav a  2s  . c o m
     * final PdfPTable header = new PdfPTable(new float[]{1}); header.setWidthPercentage(100f); final PdfPCell defaultCell = header.getDefaultCell();
     * defaultCell.setBorder(0); //defaultCell.setFixedHeight(getPointsFromMM(40)); defaultCell.setPadding(0); defaultCell.setNoWrap(true);
     * defaultCell.setVerticalAlignment(align); header.addCell(new Phrase(new Chunk(dateString, getDefaultParagraphFont()))); document.add(header);
     */
    PdfContentByte cb = writer.getDirectContent();
    cb.beginText();
    Font font = getDefaultParagraphFont();

    try {
        BaseFont bf = BaseFont.createFont(font.getFamilyname(), BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        cb.setFontAndSize(bf, font.size());
        // we show some text starting on some absolute position with a given
        // alignment
        cb.showTextAligned(PdfContentByte.ALIGN_RIGHT, dateString, getPointsFromMM(210 - 20),
                getPointsFromMM(297 - 20), 0);
        cb.endText();
    }

    catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:jgnash.ui.report.FontRegistry.java

License:Open Source License

private void registerFont(final String path) {
    try {/* www  .j av  a 2s  .c om*/
        if (path.toLowerCase().endsWith(".ttf") || path.toLowerCase().endsWith(".otf")
                || path.toLowerCase().indexOf(".ttc,") > 0) {
            Object allNames[] = BaseFont.getAllFontNames(path, BaseFont.WINANSI, null);

            String[][] names = (String[][]) allNames[2]; //full name
            for (String[] name : names) {
                registeredFontMap.put(name[3].toLowerCase(), path);
            }

        } else if (path.toLowerCase().endsWith(".ttc")) {
            String[] names = BaseFont.enumerateTTCNames(path);
            for (int i = 0; i < names.length; i++) {
                registerFont(path + "," + i);
            }
        } else if (path.toLowerCase().endsWith(".afm") || path.toLowerCase().endsWith(".pfm")) {
            BaseFont bf = BaseFont.createFont(path, BaseFont.CP1252, false);
            String fullName = bf.getFullFontName()[0][3].toLowerCase();
            registeredFontMap.put(fullName, path);
        }
    } catch (DocumentException | IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:joelib2.io.types.PDF.java

License:Open Source License

/**
 *  Writes a molecule with his <tt>PairData</tt> .
 *
 * @param  mol              the molecule with additional data
 * @param  title            the molecule title or <tt>null</tt> if the title
 *      from the molecule should be used
 * @param  writePairData    if <tt>true</tt> then the additional molecule data
 *      is written//from   ww w.j a v  a 2s. c  o  m
 * @param  attribs2write    Description of the Parameter
 * @return                  <tt>true</tt> if the molecule and the data has
 *      been succesfully written.
 * @exception  IOException  Description of the Exception
 */
public boolean write(Molecule mol, String title, boolean writePairData, List attribs2write,
        SMARTSPatternMatcher smarts) throws IOException {
    if (firstMoleculeWritten == false) {
        document.open();
        firstMoleculeWritten = true;
    }

    Dimension d = new Dimension(Mol2Image.instance().getDefaultWidth(),
            Mol2Image.instance().getDefaultHeight());
    RenderingAtoms container = new RenderingAtoms();
    container.add(mol);

    RenderHelper.translateAllPositive(container);
    RenderHelper.scaleMolecule(container, d, 0.8);
    RenderHelper.center(container, d);

    Renderer2D renderer = new Renderer2D();

    //BaseFont helvetica = null;
    try {
        BaseFont.createFont("Helvetica", BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
    } catch (DocumentException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    int w = d.width;
    int h = d.height;
    PdfContentByte cb = writer.getDirectContent();
    PdfTemplate tp = cb.createTemplate(w, h);
    Graphics2D g2 = tp.createGraphics(w, h);
    g2.setStroke(new BasicStroke(0.1f));
    tp.setWidth(w);
    tp.setHeight(h);

    g2.setColor(renderer.getRenderer2DModel().getBackColor());
    g2.fillRect(0, 0, d.width, d.height);

    if (smarts != null) {
        renderer.selectSMARTSPatterns(container, smarts);
    }

    renderer.paintMolecule(container, g2);

    g2.dispose();

    ////cb.addTemplate(tp, 72, 720 - h);
    //cb.addTemplate(tp, 12, 720 - h);
    cb.addTemplate(tp, 0, document.getPageSize().height() - h);

    //     Mol2Image.instance().mol2image(mol);
    BaseFont bf = null;

    try {
        bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
    } catch (DocumentException e2) {
        // TODO Auto-generated catch block
        e2.printStackTrace();
    }

    String string = "";

    //float myBorder = DEFAULT_BORDER;
    //float fontSize = 10;
    //float fontSizeDelta = DEFAULT_FONT_OFFSET;
    float hpos;

    if (writePairData) {
        PairData pairData;
        PairDataIterator gdit = mol.genericDataIterator();
        int index = 0;
        boolean firstPageWritten = false;

        List attributesV;

        if (attribs2write == null) {
            // write all descriptors
            attributesV = new Vector();

            //DescResult tmpPropResult;
            while (gdit.hasNext()) {
                pairData = gdit.nextPairData();

                attributesV.add(pairData.getKey());
            }
        } else {
            attributesV = attribs2write;
        }

        // sort descriptors by attribute name
        String[] attributes = new String[attributesV.size()];

        for (int i = 0; i < attributesV.size(); i++) {
            attributes[i] = (String) attributesV.get(i);
        }

        Arrays.sort(attributes);

        // write them
        for (int i = 0; i < attributes.length; i++) {
            pairData = mol.getData(attributes[i]);
            string = pairData.getKey() + " = " + pairData.toString();

            // reduce too complex data
            string = string.replace('\n', ' ');
            string = string.substring(0, Math.min(string.length(), WRITE_MAX_CHARACTERS));

            tp = cb.createTemplate(document.getPageSize().width() - pageBorder, fontSize + fontSizeDelta);
            tp.setFontAndSize(bf, fontSize);
            tp.beginText();
            tp.setTextMatrix(0, fontSizeDelta);
            tp.showText(string);
            tp.endText();
            cb.setLineWidth(1f);
            tp.moveTo(0, 0);
            tp.lineTo(document.getPageSize().width() - (2 * pageBorder), 0);
            tp.stroke();

            if (firstPageWritten) {
                hpos = document.getPageSize().height() - ((fontSize + fontSizeDelta) * (index + 1));
            } else {
                hpos = document.getPageSize().height() - h - ((fontSize + fontSizeDelta) * (index + 1));
            }

            if (hpos < pageBorder) {
                index = 1;
                firstPageWritten = true;
                hpos = document.getPageSize().height() - ((fontSize + fontSizeDelta) * (index + 1));

                try {
                    document.newPage();
                } catch (DocumentException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }

            cb.addTemplate(tp, pageBorder, hpos);

            index++;
        }
    }

    try {
        document.newPage();
    } catch (DocumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return (true);
}