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

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

Introduction

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

Prototype

boolean NOT_EMBEDDED

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

Click Source Link

Document

if the font doesn't have to be embedded

Usage

From source file:AppletViewer.java

License:Open Source License

/**
 * Metodo que agrega annotaciones (en texto) al nuevo PDF
 * @param stamper//  w  w  w. j a va 2  s.  c o  m
 * @param pageNumber
 * @param x
 * @param y
 * @param text
 * @param size
 */
public void addTextAnnotation(PdfStamper stamper, int pageNumber, float x, float y, String text, float size) {
    try {
        BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); // set font

        PdfContentByte over = stamper.getOverContent(pageNumber);

        float positionX = ((x * 2480) / 1654);
        float positionY = ((y * 3508) / 2339);

        // write text
        over.beginText();
        over.setFontAndSize(bf, size); // set font and size
        over.setTextMatrix(positionX, positionY); // set x,y position (0,0 is at the bottom left)
        over.showText(text); // set text
        over.endText();

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

From source file:br.org.archimedes.io.pdf.elements.TextExporter.java

License:Open Source License

public void exportElement(Text text, Object outputObject) throws IOException {

    PDFWriterHelper helper = (PDFWriterHelper) outputObject;
    PdfContentByte cb = helper.getPdfContentByte();

    Point lowerLeft = text.getLowerLeft();
    Point docPoint = helper.modelToDocument(lowerLeft);

    BaseFont font = null;//  w w w . j  ava  2s  . co m
    try {
        font = BaseFont.createFont(BaseFont.COURIER, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
    } catch (DocumentException e) {
        // Problems creating the font. This means the current
        // platform does not support this encoding or font.
        System.err.println(Messages.TextExporter_FontCreatingError);
        e.printStackTrace();
    }
    cb.setFontAndSize(font, (float) text.getSize());
    cb.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL);
    cb.beginText();
    cb.moveText((float) docPoint.getX(), (float) docPoint.getY());
    double angle = 0;
    try {
        angle = Geometrics.calculateAngle(new Point(0, 0), text.getDirection().getPoint());
    } catch (NullArgumentException e) {
        // Shouldn't happen since the text MUST have a direction to exists
        // and the point 0,0 is valid
        e.printStackTrace();
    }
    float degreeAngle = (float) (angle * 180 / Math.PI);
    cb.showTextAligned(PdfContentByte.ALIGN_LEFT, text.getText(), (float) docPoint.getX(),
            (float) docPoint.getY(), degreeAngle);
    cb.endText();
}

From source file:ca.sqlpower.architect.profile.output.ProfilePDFFormat.java

License:Open Source License

/**
 * Outputs a PDF file report of the data in drs to the given
 * output stream.//from www . j  a  v a  2s .c  o  m
 * @throws SQLObjectException
 * @throws IllegalAccessException
 * @throws InstantiationException
 */
public void format(OutputStream out, List<ProfileResult> profileResults)
        throws DocumentException, IOException, SQLException, SQLObjectException, InstantiationException,
        IllegalAccessException, ClassNotFoundException {

    final int minRowsTogether = 1; // counts smaller than this are considered orphan/widow
    final int mtop = 50; // margin at top of page (in points)
    final int mbot = 50; // margin at bottom of page (page numbers are below this)
    //        final int pbot = 20;  // padding between bottom margin and bottom of body text
    final int mlft = 50; // margin at left side of page
    final int mrgt = 50; // margin at right side of page
    final Rectangle pagesize = PageSize.LETTER.rotate();
    final Document document = new Document(pagesize, mlft, mrgt, mtop, mbot);
    final PdfWriter writer = PdfWriter.getInstance(document, out);

    final float fsize = 6f; // the font size to use in the table body
    final BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
    document.addTitle("Table Profiling Report");
    document.addSubject("Tables: " + profileResults);
    document.addAuthor(System.getProperty("user.name"));
    document.addCreator("Power*Architect version " + ArchitectVersion.APP_FULL_VERSION);

    document.open();

    // vertical position where next element should start
    //   (bottom is 0; top is pagesize.height())
    float pos = pagesize.height() - mtop;

    final PdfContentByte cb = writer.getDirectContent();
    final PdfTemplate nptemplate = cb.createTemplate(50, 50);
    writer.setPageEvent(new PdfPageEventHelper() {
        // prints the "page N of <template>" footer
        public void onEndPage(PdfWriter writer, Document document) {
            int pageN = writer.getPageNumber();
            String text = "Page " + pageN + " of ";
            float len = bf.getWidthPoint(text, fsize - 2);
            cb.beginText();
            cb.setFontAndSize(bf, fsize - 2);
            cb.setTextMatrix(pagesize.width() / 2 - len / 2, mbot / 2);
            cb.showText(text);
            cb.endText();
            cb.addTemplate(nptemplate, pagesize.width() / 2 - len / 2 + len, mbot / 2);
        }

        public void onCloseDocument(PdfWriter writer, Document document) {
            nptemplate.beginText();
            nptemplate.setFontAndSize(bf, fsize - 2);
            nptemplate.showText(String.valueOf(writer.getPageNumber() - 1));
            nptemplate.endText();
        }
    });

    document.add(new Paragraph("SQL Power Architect Profiling Report"));
    document.add(new Paragraph("Generated " + new java.util.Date() + " by " + System.getProperty("user.name")));

    float[] widths = new float[totalColumn]; // widths of widest cells per row in pdf table
    LinkedList<ProfileTableStructure> profiles = new LinkedList<ProfileTableStructure>(); // 1 table per profile result

    Font f = new Font(bf, fsize);

    // This ddl generator is set to the appropriate ddl generator for the source database
    // every time we encounter a table profile result in the list.
    DDLGenerator ddlg = null;

    PdfPTable pdfTable = null;
    for (ProfileResult result : profileResults) {
        if (result instanceof TableProfileResult) {
            TableProfileResult tableResult = (TableProfileResult) result;
            pdfTable = new PdfPTable(widths.length);
            pdfTable.setWidthPercentage(100f);
            ProfileTableStructure oneProfile = makeNextTable(tableResult, pdfTable, bf, fsize, widths);
            profiles.add(oneProfile);
            ddlg = tableResult.getDDLGenerator();
        } else if (result instanceof ColumnProfileResult) {
            final ColumnProfileResult columnResult = (ColumnProfileResult) result;
            TableProfileResult tResult = columnResult.getParent();
            addBodyRow(tResult, columnResult, ddlg, pdfTable, bf, f, fsize, widths);
        }
    }

    double allowedTableSize = pagesize.width() - mrgt - mlft;
    double totalWidths = 0;
    for (int i = 0; i < headings.length; i++) {
        if (!columnsToTruncate.contains(headings[i])) {
            widths[i] += PIXELS_PER_BORDER;
            totalWidths += widths[i];
        }
    }
    truncateLength = (allowedTableSize - totalWidths - (PIXELS_PER_BORDER * (columnsToTruncate.size())))
            / columnsToTruncate.size();
    logger.debug("Truncate length is " + truncateLength);
    widths = new float[totalColumn];

    profiles = new LinkedList<ProfileTableStructure>(); // 1 table per profile result
    for (ProfileResult result : profileResults) {
        if (result instanceof TableProfileResult) {
            TableProfileResult tableResult = (TableProfileResult) result;
            pdfTable = new PdfPTable(widths.length);
            pdfTable.setWidthPercentage(100f);
            ProfileTableStructure oneProfile = makeNextTable(tableResult, pdfTable, bf, fsize, widths);
            profiles.add(oneProfile);
            ddlg = tableResult.getDDLGenerator();
        } else if (result instanceof ColumnProfileResult) {
            final ColumnProfileResult columnResult = (ColumnProfileResult) result;
            TableProfileResult tResult = columnResult.getParent();
            addBodyRow(tResult, columnResult, ddlg, pdfTable, bf, f, fsize, widths);
        }
    }

    for (int i = 0; i < headings.length; i++) {
        widths[i] += PIXELS_PER_BORDER;
    }

    // add the PdfPTables to the document; try to avoid orphan and widow rows
    pos = writer.getVerticalPosition(true) - fsize;
    logger.debug("Starting at pos=" + pos);
    boolean newPageInd = true;

    for (ProfileTableStructure profile : profiles) {

        pdfTable = profile.getMainTable();
        pdfTable.setTotalWidth(pagesize.width() - mrgt - mlft);
        pdfTable.setWidths(widths);
        resetHeaderWidths(profile, widths);

        int startrow = pdfTable.getHeaderRows();
        int endrow = startrow; // current page will contain header+startrow..endrow

        /* no other rows in the table, just the header, and the header may
         * contain error message
         */
        if (endrow == pdfTable.size()) {
            pos = pdfTable.writeSelectedRows(0, pdfTable.getHeaderRows(), mlft, pos, cb);
            continue;
        }

        while (endrow < pdfTable.size()) {

            // figure out how many body rows fit nicely on the page
            float endpos = pos - calcHeaderHeight(pdfTable);

            // y position of page number# = (mbot/2+fsize)
            while ((endpos - pdfTable.getRowHeight(endrow)) >= (mbot / 2 + fsize + 2)
                    && endrow < pdfTable.size()) {
                endpos -= pdfTable.getRowHeight(endrow);
                endrow++;
            }

            // adjust for orphan rows. Might create widows or make
            // endrow < startrow, which is handled later by deferring the table
            if (endrow < pdfTable.size() && endrow + minRowsTogether >= pdfTable.size()) {

                // page # maybe fall into table area, but usually that's column of
                // min value, usually that's enough space for both, or we should
                // disable page # on this page
                if (endrow + 1 == pdfTable.size() && endpos - pdfTable.getRowHeight(endrow) > 10) {

                    // short by 1 row.. just squeeze it in
                    endrow = pdfTable.size();
                } else {
                    // more than 1 row remains: shorten this page so orphans aren't lonely
                    endrow = pdfTable.size() - minRowsTogether;
                }
            }

            if (endrow == pdfTable.size() || endrow - startrow >= minRowsTogether) {
                // this is the end of the table, or we have enough rows to bother printing
                pos = pdfTable.writeSelectedRows(0, pdfTable.getHeaderRows(), mlft, pos, cb);
                pos = pdfTable.writeSelectedRows(startrow, endrow, mlft, pos, cb);
                startrow = endrow;
                newPageInd = false;
            } else {
                // not the end of the table and not enough rows to print out
                if (newPageInd)
                    throw new IllegalStateException(
                            "PDF Page is not large engouh to display " + minRowsTogether + " row(s)");
                endrow = startrow;
            }

            // new page if necessary (that is, when we aren't finished the table yet)
            if (endrow != pdfTable.size()) {
                document.newPage();
                pos = pagesize.height() - mtop;
                newPageInd = true;
            }
        }
    }
    document.close();
}

From source file:classroom.intro.HelloWorld05.java

public static void main(String[] args) {
    // step 1/*w  w w.j ava2 s.  co m*/
    Document document = new Document();
    try {
        // step 2
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT));
        // step 3
        document.open();
        // step 4
        PdfContentByte cb = writer.getDirectContent();
        BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        cb.saveState(); // q
        cb.beginText(); // BT
        cb.moveText(36, 806); // 36 806 Td
        cb.moveText(0, -18); // 0 -18 Td
        cb.setFontAndSize(bf, 12); // /F1 12 Tf
        cb.showText("Hello World"); // (Hello World)Tj
        cb.endText(); // ET
        cb.restoreState(); // Q
    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    }
    // step 5
    document.close();
}

From source file:classroom.intro.HelloWorld06.java

public static void main(String[] args) {
    // step 1/*from ww w  .jav  a2 s.  c o  m*/
    Document document = new Document();
    try {
        // step 2
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT));
        // step 3
        document.open();
        // step 4
        PdfContentByte cb = writer.getDirectContent();
        BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        cb.beginText();
        cb.setTextMatrix(36, 788);
        cb.setFontAndSize(bf, 12);
        cb.showText("Hello World");
        cb.endText();
    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    }
    // step 5
    document.close();
}

From source file:classroom.intro.HelloWorld07.java

public static void main(String[] args) {
    // step 1//from   ww w .j  a v a2s  .co  m
    Document document = new Document();
    try {
        // step 2
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT));
        // step 3
        document.open();
        // step 4
        PdfContentByte cb = writer.getDirectContent();
        BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        cb.beginText();
        cb.setFontAndSize(bf, 12);
        cb.showTextAligned(Element.ALIGN_LEFT, "Hello World", 36, 788, 0);
        cb.endText();
    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    }
    // step 5
    document.close();
}

From source file:classroom.intro.HelloWorld08.java

public static void main(String[] args) {
    Document.compress = false;//www.  j  a v  a2 s .c o  m
    // step 1
    Document document = new Document();
    try {
        // step 2
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT));
        // step 3
        document.open();
        // step 4
        PdfContentByte cb = writer.getDirectContent();
        BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        cb.beginText();
        cb.setFontAndSize(bf, 12);
        cb.moveText(88.66f, 788);
        cb.showText("ld");
        cb.moveText(-22f, 0);
        cb.showText("Wor");
        cb.moveText(-15.33f, 0);
        cb.showText("llo");
        cb.endText();
        PdfTemplate tmp = cb.createTemplate(250, 25);
        tmp.beginText();
        tmp.setFontAndSize(bf, 12);
        tmp.moveText(0, 7);
        tmp.showText("He");
        tmp.endText();
        cb.addTemplate(tmp, 36, 781);
    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    }
    // step 5
    document.close();
}

From source file:classroom.intro.HelloWorld09.java

public static void main(String[] args) {
    Document.compress = false;/*  w w  w.j  ava 2s  . c o  m*/
    BaseFont bf = null;
    // step 1
    Document document = new Document();
    try {
        // step 2
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT1));
        // step 3
        document.open();
        // step 4
        PdfContentByte cb = writer.getDirectContent();
        bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        cb.beginText();
        cb.setFontAndSize(bf, 12);
        cb.moveText(88.66f, 788);
        cb.showText("ld");
        cb.moveText(-22f, 0);
        cb.showText("Wor");
        cb.endText();
    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    }
    // step 5
    document.close();

    try {
        PdfReader reader = new PdfReader(RESULT1);
        PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT2));
        PdfContentByte cb1 = stamper.getUnderContent(1);
        cb1.beginText();
        cb1.setFontAndSize(bf, 12);
        cb1.setTextMatrix(51.33f, 788);
        cb1.showText("llo");
        cb1.endText();
        PdfContentByte cb2 = stamper.getOverContent(1);
        PdfTemplate tmp = cb2.createTemplate(250, 25);
        tmp.beginText();
        tmp.setFontAndSize(bf, 12);
        tmp.moveText(0, 7);
        tmp.showText("He");
        tmp.endText();
        cb2.addTemplate(tmp, 36, 781);
        stamper.close();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }

}

From source file:classroom.newspaper_a.Newspaper03.java

public static void main(String[] args) {
    try {/*from w ww. j a  v  a2 s .c o  m*/
        PdfReader reader = new PdfReader(NEWSPAPER);
        PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT));
        PdfContentByte canvas = stamper.getOverContent(1);
        canvas.saveState();
        canvas.setRGBColorFill(0xFF, 0xFF, 0xFF);
        canvas.rectangle(LLX1, LLY1, W1, H1);
        canvas.rectangle(LLX2, LLY2, W2, H2);
        canvas.fillStroke();
        canvas.restoreState();
        BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
        putText(canvas, MESSAGE, bf, LLX1, LLY1, URX1, URY1);
        putText(canvas, MESSAGE, bf, LLX2, LLY2, URX2, URY2);
        stamper.close();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }
}

From source file:com.afunms.report.abstraction.ExcelReport1.java

public void createWordReport_hardware(String filename) {
    try {/* ww w  .  j a v a  2 s .c om*/
        String starttime = (String) reportHash.get("starttime");
        String totime = (String) reportHash.get("totime");
        Document document = new Document(PageSize.A4);
        RtfWriter2.getInstance(document, new FileOutputStream(filename));
        fileName = filename;
        document.open();
        BaseFont bfChinese = BaseFont.createFont("Times-Roman", "", BaseFont.NOT_EMBEDDED);
        Font titleFont = new Font(bfChinese, 12, Font.BOLD);
        Font contextFont = new Font(bfChinese, 10, Font.NORMAL);
        Paragraph title = new Paragraph("");
        title.setAlignment(Element.ALIGN_CENTER);
        document.add(title);

        String contextString = ":" + impReport.getTimeStamp() + " \n"// 
                + ":" + starttime + "  " + totime;
        Paragraph context = new Paragraph(contextString);
        // 
        context.setAlignment(Element.ALIGN_LEFT);
        // context.setFont(contextFont);
        // 
        context.setSpacingBefore(5);
        // 
        context.setFirstLineIndent(5);
        document.add(context);

        Table aTable = new Table(4);
        float[] widths = { 100f, 100f, 300f, 100f };
        aTable.setWidths(widths);
        aTable.setWidth(100); //  90%
        aTable.setAlignment(Element.ALIGN_CENTER);// 
        aTable.setAutoFillEmptyCells(true); // 
        aTable.setBorderWidth(1); // 
        aTable.setBorderColor(new Color(0, 125, 255)); // 
        aTable.setPadding(2);// 
        aTable.setSpacing(0);// 
        aTable.setBorder(2);// 
        aTable.endHeaders();
        aTable.addCell("");
        aTable.addCell("");
        aTable.addCell("");
        aTable.addCell("");
        Vector deviceV = (Vector) reportHash.get("deviceV");
        for (int m = 0; m < deviceV.size(); m++) {
            Devicecollectdata devicedata = (Devicecollectdata) deviceV.get(m);
            String name = devicedata.getName();
            String type = devicedata.getType();
            String status = devicedata.getStatus();
            aTable.addCell(m + 1 + "");
            aTable.addCell(type);
            aTable.addCell(name);
            aTable.addCell(status);
        }
        document.add(aTable);
        document.close();
        // System.out.println("abcdefg");
    } catch (Exception e) {
        SysLogger.error("", e);
    }
}