Example usage for com.lowagie.text PageSize LETTER

List of usage examples for com.lowagie.text PageSize LETTER

Introduction

In this page you can find the example usage for com.lowagie.text PageSize LETTER.

Prototype

Rectangle LETTER

To view the source code for com.lowagie.text PageSize LETTER.

Click Source Link

Document

This is the letter format

Usage

From source file:questions.tables.AutomaticExtensionOfTables.java

public static void createPdf(int rows) throws IOException, DocumentException {
    Document document = new Document(PageSize.LETTER);
    PdfWriter.getInstance(document, new FileOutputStream(RESULT[rows]));
    document.open();//from   w  ww .  j ava2 s . c  o  m
    PdfPTable outer = new PdfPTable(2);
    outer.setExtendLastRow(true);
    PdfPTable inner1 = new PdfPTable(5);
    for (int i = 0; i < ROWS[rows]; i++) {
        inner1.addCell("A" + i);
        inner1.addCell("B" + i);
        inner1.addCell("C" + i);
        inner1.addCell("D" + i);
        inner1.addCell("E" + i);
    }
    PdfPCell cell = new PdfPCell(inner1);
    cell.setColspan(2);
    outer.addCell(cell);
    PdfPTable inner2 = new PdfPTable(5);
    for (int i = 0; i < 20; i++) {
        inner2.addCell("testA");
    }
    outer.addCell(inner2);
    PdfPTable inner3 = new PdfPTable(3);
    for (int i = 0; i < 20; i++) {
        inner3.addCell("testB");
    }
    outer.addCell(inner3);
    document.add(outer);
    document.close();
}

From source file:test.itext.html.AimsPdf.java

License:Open Source License

public static void main(String[] args) throws Exception {
    Document doc = new Document(PageSize.LETTER);
    PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream("aims.pdf"));
    doc.open();// w  w w.  j av  a2s. c om
    FontFactory.register("C:\\WINDOWS\\FONTS\\ARIAL.TTF", "arial");
    //      AimsPdf.arial = BaseFont.createFont("C:\\WINDOWS\\FONTS\\ARIAL.TTF",BaseFont.CP1252,BaseFont.NOT_EMBEDDED);

    AimsPdf.style = new StyleSheet();

    style.loadTagStyle("p", "size", "10px");
    style.loadTagStyle("p", "align", "justify");
    style.loadTagStyle("p", "face", "arial");
    style.loadTagStyle("p", "leading", "14f");

    style.loadTagStyle("a", "color", "blue");
    style.loadTagStyle("a", "u", "");

    style.loadTagStyle("ul", "face", "arial");
    style.loadTagStyle("ul", "size", "10px");
    style.loadTagStyle("ul", "leading", "14f");

    style.loadTagStyle("li", "align", "justify");

    style.loadTagStyle("td", "cellpadding", "2");

    //      style.loadTagStyle("p", "spacingAfter", "35px"); 
    //      style.loadTagStyle("p", "spacingBefore", "35px"); 
    //      style.loadTagStyle("p", "style", "margin-top:20px;margin-bottom:20px"); 

    AimsPdf.addTitle(doc, "EA SPORTS FIFA 08");
    AimsPdf.addAgreement(doc, "");
    AimsPdf.addProductionDescription(doc, "");
    AimsPdf.addScreenShorts(doc, "");
    AimsPdf.addUsingApplication(doc, "");
    AimsPdf.addTipsAndTricks(doc, "");
    AimsPdf.addFaq(doc, "");
    AimsPdf.temp(doc, "");

    /*StringBuffer sb=new StringBuffer();               
    sb.append("<p><h1><span style=\"font-size: 100px\"><span style=\"\"><span style=\"font-family: Courier New\"><ins>Hello World</ins></span></span></span></h1></p>");
    writeData(doc, sb);*/
    doc.close();
}

From source file:tufts.vue.PresentationNotes.java

License:Educational Community License

public static void createMapAsPDF(File file, LWMap map) {
    // step 1: creation of a document-object
    Document document = new Document(PageSize.LETTER.rotate());

    try {/* w  w w.  j av a  2  s .co m*/
        GUI.activateWaitCursor();
        // step 2:
        // we create a writer that listens to the document
        // and directs a PDF-stream to a file            
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file));
        writer.setDefaultColorspace(PdfName.DEFAULTRGB, null);
        // writer.setStrictImageSequence(true);
        // step 3: we open the document

        document.open();

        PdfContentByte cb = writer.getDirectContent();
        //  cb.setFontAndSize(arg0, arg1)
        PdfTemplate tp = cb.createTemplate(document.getPageSize().getWidth() - 70,
                document.getPageSize().getHeight() - 70);
        // tp.createGraphicsShapes(arg0, arg1) 

        PdfGraphics2D g2d = (PdfGraphics2D) tp.createGraphics(document.getPageSize().getWidth() - 70,
                document.getPageSize().getHeight() - 70, getFontMapper(), false, 60.0f);

        Dimension page = new Dimension((int) document.getPageSize().getWidth() - 70,
                (int) document.getPageSize().getHeight() - 70);
        // compute zoom & offset for visible map components
        Point2D.Float offset = new Point2D.Float();
        offset.x = 35;
        offset.y = 35;
        // center vertically only if landscape mode
        //if (format.getOrientation() == PageFormat.LANDSCAPE)
        //TODO: allow horizontal centering, but not vertical centering (handle in computeZoomFit)
        Rectangle2D bounds = map.getBounds();
        double scale = ZoomTool.computeZoomFit(page, 5, bounds, offset, true);
        //  System.out.println(scale  + " zoom factor...");
        // set up the DrawContext
        DrawContext dc = new DrawContext(g2d, scale, -offset.x, -offset.y, null, // frame would be the PageFormat offset & size rectangle
                map, false); // todo: absolute links shouldn't be spec'd here

        //    dc.setAntiAlias(true);
        dc.setMapDrawing();
        //   dc.setPDFRender(true);
        //dc.setPrioritizeQuality(false); // why was this low quality?
        dc.setPrintQuality();
        //dc.setAntiAlias(false); // why was this turned off?  was it redundant?

        dc.setClipOptimized(true);
        //   dc.setDraftQuality(true);
        //  dc.setRawDrawing();
        //dc.setClipOptimized(false);

        dc.setInteractive(false);
        dc.setDrawPathways(false);

        // VUE.getActiveMap().draw(dc);
        LWPathway.setShowSlides(false);
        map.drawZero(dc);
        LWPathway.setShowSlides(true);
        g2d.dispose();
        //  document.add(new Paragraph(new Chunk().setAnchor("http://www.cnn.com")));
        cb.addTemplate(tp, 0, 0);
        document.newPage();

    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    } finally {
        GUI.clearWaitCursor();
    }

    // step 5: we close the document
    document.close();
}

From source file:tufts.vue.PresentationNotes.java

License:Educational Community License

public static void createPresentationSlidesDeck(File file) {
    // step 1: creation of a document-object
    final Document document = new Document(PageSize.LETTER.rotate());

    try {//from ww  w.ja  v  a2s  .  co m
        GUI.activateWaitCursor();
        // step 2:
        // we create a writer that listens to the document
        // and directs a PDF-stream to a file            
        final PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file));
        writer.setDefaultColorspace(PdfName.DEFAULTRGB, null);
        writer.setStrictImageSequence(true);
        // step 3: we open the document

        document.open();

        final float pageWidth = document.getPageSize().getWidth();
        final float pageHeight = document.getPageSize().getHeight();
        final float fillWidth = pageWidth - 70;
        final float fillHeight = pageHeight - 70;

        if (DEBUG.Enabled) {
            System.out.println("\n---------------------------------");
            System.out.println("PDF DOCUMENT: pageSize " + document.getPageSize());
            System.out.println("fillWidth=" + fillWidth + " fillHeight=" + fillHeight);
        }
        int currentIndex = VUE.getActivePathway().getIndex();
        VUE.getActivePathway().setIndex(-1);
        for (LWPathway.Entry entry : VUE.getActivePathway().getEntries()) {

            if (DEBUG.Enabled)
                Log.debug("\n\nHANDLING DECK ENTRY " + entry);
            final LWSlide slide = entry.produceSlide();
            final LWComponent toDraw = (slide == null ? entry.node : slide);

            final PdfTemplate template = PdfTemplate.createTemplate(writer, fillWidth, fillHeight);
            final PdfGraphics2D graphics = (PdfGraphics2D) template.createGraphics(fillWidth, fillHeight,
                    getFontMapper(), false, 60.0f);
            final DrawContext dc = new DrawContext(graphics, 1.0);
            //                 //final DrawContext dc = new DrawContext(graphics, scale);
            //final DrawContext dc = new DrawContext(graphics, toDraw); // ideally, should use this
            dc.setClipOptimized(false);
            dc.setInteractive(false); // should be un-needed
            dc.setPrintQuality();

            // We set dc.focused to the node, which is needed for portals so they know to render contents in their clip-region.
            // Normally a portal knows to do this because it's the focal (dc.focal), but in this case, the dc.focal could,
            // at best, be the slide.  The current code actually uses NO focal in creating the DrawContext above,
            // and I'm not changing that just now as that would require lots of regression testing of printing.  SMF 6/24/10
            dc.focused = entry.node;

            if (DEBUG.Enabled) {
                Log.debug("DRAWING INTO " + dc + " g=" + graphics + " clip="
                        + tufts.Util.fmt(graphics.getClip()));
                if (DEBUG.PDF) {
                    dc.g.setColor(Color.green);
                    dc.g.fillRect(-Short.MAX_VALUE / 2, -Short.MAX_VALUE / 2, Short.MAX_VALUE, Short.MAX_VALUE);
                }
            }

            try {
                if (DEBUG.Enabled)
                    dc.clearDebug();
                toDraw.drawFit(dc, 0);
            } catch (Throwable t) {
                Log.error("exception drawing " + toDraw, t);
            }

            try {

                if (DEBUG.Enabled)
                    Log.debug("painted " + DrawContext.getDebug() + " to " + dc);

                if (DEBUG.PDF) {
                    final String dcDesc = dc.toString()
                            + String.format(" scale=%.1f%%", dc.g.getTransform().getScaleX() * 100);
                    dc.setRawDrawing();
                    dc.g.setColor(Color.red);
                    dc.g.setFont(VueConstants.FixedSmallFont);
                    dc.g.drawString(dcDesc, 10, fillHeight - 27);
                    dc.g.drawString(entry.toString(), 10, fillHeight - 16);
                    dc.g.drawString(toDraw.toString(), 10, fillHeight - 5);
                }

                // the graphics dispose appears to be very important -- we've seen completely intermittant
                // problems with generating many page PDF documents, which would be well explained by
                // java or internal itext buffers running out of memory.
                graphics.dispose();

                document.add(Image.getInstance(template));
                document.newPage();
            } catch (Throwable t) {
                Log.error("exception finishing " + toDraw + " in " + dc, t);
            }
        }
        VUE.getActivePathway().setIndex(currentIndex);
        if (DEBUG.Enabled)
            Log.debug("PROCESSED ALL ENTRIES");

    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    } finally {
        GUI.clearWaitCursor();
    }

    // step 5: we close the document
    document.close();
}

From source file:tufts.vue.PresentationNotes.java

License:Educational Community License

public static void createPresentationNotes8PerPage(File file) {
    //page size notes:
    //martin-top,left,right,bottom = 36
    //widht :612/* ww w. j a v a2 s . co  m*/
    //height : 792
    //usable space 540 x 720
    // step 1: creation of a document-object
    Document document = new Document(PageSize.LETTER);

    try {
        GUI.activateWaitCursor();
        // step 2:
        // we create a writer that listens to the document
        // and directs a PDF-stream to a file            
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file));
        //  writer.setDefaultColorspace(PdfName.DEFAULTRGB, null);
        // writer.setStrictImageSequence(true);

        // step 3: we open the document
        document.open();

        // PdfPTable table;
        // PdfPCell cell;            
        int entryCount = 0;
        int entryOnPage = 0;
        int currentIndex = VUE.getActivePathway().getIndex();

        VUE.getActivePathway().setIndex(-1);

        for (LWPathway.Entry entry : VUE.getActivePathway().getEntries()) {

            final LWSlide slide = entry.produceSlide();
            final LWComponent toDraw = (slide == null ? entry.node : slide);

            entryCount++;
            //String label = entry.getLabel();
            PdfContentByte cb = writer.getDirectContent();
            //cb.cr
            PdfTemplate tp = cb.createTemplate(SlideSizeX, SlideSizeY);
            Point2D.Float offset = new Point2D.Float();

            Rectangle2D bounds = null;

            bounds = slide.getBounds();

            Dimension page = null;

            page = new Dimension(SlideSizeX, 172);

            //PdfTemplate tp = cb.createTemplate(document.getPageSize().width()-80, document.getPageSize().height()-80);
            double scale = ZoomTool.computeZoomFit(page, 5, bounds, offset, true);
            PdfGraphics2D g2d = (PdfGraphics2D) tp.createGraphics(SlideSizeX, SlideSizeY, getFontMapper(),
                    false, 60.0f);
            DrawContext dc = new DrawContext(g2d, scale, -offset.x, -offset.y, null, // frame would be the PageFormat offset & size rectangle
                    entry.isMapView() ? entry.getFocal() : slide, false); // todo: absolute links shouldn't be spec'd here

            dc.setClipOptimized(false);
            dc.setPrintQuality();
            //slide.drawZero(dc);
            toDraw.drawFit(dc, 0);

            g2d.dispose();
            //document.add(Image.getInstance(tp));

            if (entryOnPage == 0) {
                drawSequenceNumber(writer, 36, 739, entryCount);
                cb.addTemplate(tp, 56, 583);
            }
            if (entryOnPage == 1) {
                drawSequenceNumber(writer, 296, 739, entryCount);
                cb.addTemplate(tp, 306, 583);
            }
            if (entryOnPage == 2) {
                drawSequenceNumber(writer, 36, 559, entryCount);
                cb.addTemplate(tp, 56, 403);
            }
            if (entryOnPage == 3) {
                drawSequenceNumber(writer, 296, 559, entryCount);
                cb.addTemplate(tp, 306, 403);
            }
            if (entryOnPage == 4) {
                drawSequenceNumber(writer, 36, 375, entryCount);
                cb.addTemplate(tp, 56, 219);
            }
            if (entryOnPage == 5) {
                drawSequenceNumber(writer, 296, 375, entryCount);
                cb.addTemplate(tp, 306, 219);
            }
            if (entryOnPage == 6) {
                drawSequenceNumber(writer, 36, 192, entryCount);
                cb.addTemplate(tp, 56, 36);
                //cb.addTemplate(drawLines(writer),296,18);
            }
            if (entryOnPage == 7) {
                drawSequenceNumber(writer, 296, 192, entryCount);
                cb.addTemplate(tp, 306, 36);
            }

            entryOnPage++;
            if (entryCount % 8 == 0) {
                document.newPage();
                entryOnPage = 0;
            }
        }
        VUE.getActivePathway().setIndex(currentIndex);
    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    } finally {
        GUI.clearWaitCursor();
    }

    // step 5: we close the document
    document.close();
}

From source file:tufts.vue.PresentationNotes.java

License:Educational Community License

public static void createAudienceNotes(File file) {
    //page size notes:
    //martin-top,left,right,bottom = 36
    //widht :612//from w  ww .j  ava 2 s .c  om
    //height : 792
    //usable space 540 x 720
    // step 1: creation of a document-object
    Document document = new Document(PageSize.LETTER);

    try {
        GUI.activateWaitCursor();
        // step 2:
        // we create a writer that listens to the document
        // and directs a PDF-stream to a file            
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file));
        //  writer.setDefaultColorspace(PdfName.DEFAULTRGB, null);
        // writer.setStrictImageSequence(true);

        // step 3: we open the document
        document.open();

        // PdfPTable table;
        // PdfPCell cell;            
        int entryCount = 0;
        int entryOnPage = 0;
        int currentIndex = VUE.getActivePathway().getIndex();

        VUE.getActivePathway().setIndex(-1);

        for (LWPathway.Entry entry : VUE.getActivePathway().getEntries()) {

            final LWSlide slide = entry.produceSlide();
            final LWComponent toDraw = (slide == null ? entry.node : slide);

            entryCount++;
            //String label = entry.getLabel();
            PdfContentByte cb = writer.getDirectContent();
            //cb.cr
            PdfTemplate tp = cb.createTemplate(SlideSizeX, SlideSizeY);
            Point2D.Float offset = new Point2D.Float();
            // center vertically only if landscape mode
            //if (format.getOrientation() == PageFormat.LANDSCAPE)
            //TODO: allow horizontal centering, but not vertical centering (handle in computeZoomFit)

            Rectangle2D bounds = null;

            bounds = slide.getBounds();

            Dimension page = null;

            page = new Dimension(SlideSizeX, 172);

            //PdfTemplate tp = cb.createTemplate(document.getPageSize().width()-80, document.getPageSize().height()-80);
            double scale = ZoomTool.computeZoomFit(page, 5, bounds, offset, true);
            PdfGraphics2D g2d = (PdfGraphics2D) tp.createGraphics(SlideSizeX, SlideSizeY, getFontMapper(),
                    false, 60.0f);
            DrawContext dc = new DrawContext(g2d, scale, -offset.x, -offset.y, null, // frame would be the PageFormat offset & size rectangle
                    entry.isMapView() ? entry.getFocal() : slide, false); // todo: absolute links shouldn't be spec'd here

            dc.setClipOptimized(false);
            dc.setPrintQuality();

            toDraw.drawFit(dc, 0);

            g2d.dispose();
            //document.add(Image.getInstance(tp));

            if (entryOnPage == 0) {
                drawSequenceNumber(writer, 36, 739, entryCount);
                cb.addTemplate(tp, 56, 583);
                cb.addTemplate(drawLines(writer), 296, 565);

            }
            if (entryOnPage == 1) {
                drawSequenceNumber(writer, 36, 559, entryCount);
                cb.addTemplate(tp, 56, 403);
                cb.addTemplate(drawLines(writer), 296, 385);
            }
            if (entryOnPage == 2) {
                drawSequenceNumber(writer, 36, 375, entryCount);
                cb.addTemplate(tp, 56, 219);
                cb.addTemplate(drawLines(writer), 296, 201);
            }
            if (entryOnPage == 3) {
                drawSequenceNumber(writer, 36, 192, entryCount);
                cb.addTemplate(tp, 56, 36);
                cb.addTemplate(drawLines(writer), 296, 18);
            }

            entryOnPage++;
            if (entryCount % 4 == 0) {
                document.newPage();
                entryOnPage = 0;
            }
        }
        VUE.getActivePathway().setIndex(currentIndex);
    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    } finally {
        GUI.clearWaitCursor();
    }

    // step 5: we close the document
    document.close();
}

From source file:tufts.vue.PresentationNotes.java

License:Educational Community License

public static void createSpeakerNotes4PerPage(File file) {
    //page size notes:
    //martin-top,left,right,bottom = 36
    //widht :612/*  ww  w  .jav a  2s . c o m*/
    //height : 792
    //usable space 540 x 720
    // step 1: creation of a document-object

    Document document = new Document(PageSize.LETTER);

    try {
        GUI.activateWaitCursor();
        // step 2:
        // we create a writer that listens to the document
        // and directs a PDF-stream to a file            
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file));
        //  writer.setDefaultColorspace(PdfName.DEFAULTRGB, null);
        // writer.setStrictImageSequence(true);

        // step 3: we open the document
        document.open();

        PdfPTable table;
        PdfPCell cell;
        int entryCount = 0;
        int entryOnPage = 0;
        int currentIndex = VUE.getActivePathway().getIndex();

        VUE.getActivePathway().setIndex(-1);

        for (LWPathway.Entry entry : VUE.getActivePathway().getEntries()) {

            final LWSlide slide = entry.produceSlide();
            final LWComponent toDraw = (slide == null ? entry.node : slide);
            final String notes = entry.getNotes();
            entryCount++;

            table = new PdfPTable(new float[] { 1, 1 });
            table.getDefaultCell().setBorder(0);
            //table.getDefaultCell().setPaddingBottom(50.0f);
            table.setSpacingAfter(20.0f);
            Paragraph p = new Paragraph();

            p.setAlignment(Element.ALIGN_CENTER);

            Phrase phrase = new Phrase(notes);
            Font f = phrase.getFont();
            f.setSize(8.0f);
            p.setFont(f);
            cell = new PdfPCell(phrase);
            cell.setBorder(0);

            PdfPCell i2 = new PdfPCell();
            i2.setFixedHeight(172);
            i2.setBorder(0);

            //Render the table then throw the images on
            PdfContentByte cb = writer.getDirectContent();
            PdfTemplate tp = cb.createTemplate(SlideSizeX, SlideSizeY);

            Point2D.Float offset = new Point2D.Float();
            // center vertically only if landscape mode
            //if (format.getOrientation() == PageFormat.LANDSCAPE)
            //TODO: allow horizontal centering, but not vertical centering (handle in computeZoomFit)

            Rectangle2D bounds = null;
            //if (!entry.isMapView())
            bounds = slide.getBounds();
            //else 
            //bounds = entry.getFocal().getBounds();

            Dimension page = null;

            page = new Dimension(SlideSizeX, 172);

            //PdfTemplate tp = cb.createTemplate(document.getPageSize().width()-80, document.getPageSize().height()-80);
            double scale = ZoomTool.computeZoomFit(page, 5, bounds, offset, true);
            PdfGraphics2D g2d = (PdfGraphics2D) tp.createGraphics(SlideSizeX, SlideSizeY, getFontMapper(),
                    false, 60.0f);
            DrawContext dc = new DrawContext(g2d, scale, -offset.x, -offset.y, null, // frame would be the PageFormat offset & size rectangle
                    entry.isMapView() ? entry.getFocal() : slide, false); // todo: absolute links shouldn't be spec'd here

            dc.setClipOptimized(false);
            dc.setPrintQuality();
            /*if (!entry.isMapView())                   
               slide.drawZero(dc);
            else
            {                
               entry.getFocal().draw(dc);
            }*/
            toDraw.drawFit(dc, 0);

            g2d.dispose();
            //document.add(Image.getInstance(tp));

            //  int position = cell.
            //     drawSequenceNumber(writer,36,position+203,entryCount);

            //     cb.addTemplate(tp,56, position);                                                           

            Image img = Image.getInstance(tp);
            table.addCell(img);
            table.addCell(cell);
            p.add(table);
            document.add(p);
        }
        VUE.getActivePathway().setIndex(currentIndex);
    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    } finally {
        GUI.clearWaitCursor();
    }

    // step 5: we close the document
    document.close();

}

From source file:tufts.vue.PresentationNotes.java

License:Educational Community License

public static void createNodeNotes4PerPage(File file) {
    //page size notes:
    //martin-top,left,right,bottom = 36
    //widht :612/*from   w w w  .ja  v a 2 s  .  co m*/
    //height : 792
    //usable space 540 x 720
    // step 1: creation of a document-object

    Document document = new Document(PageSize.LETTER);

    try {
        GUI.activateWaitCursor();
        // step 2:
        // we create a writer that listens to the document
        // and directs a PDF-stream to a file            
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file));
        //  writer.setDefaultColorspace(PdfName.DEFAULTRGB, null);
        // writer.setStrictImageSequence(true);

        // step 3: we open the document
        document.open();

        PdfPTable table;
        PdfPCell cell;
        int entryCount = 0;
        int entryOnPage = 0;

        Iterator i = VUE.getActiveMap().getAllDescendents(LWComponent.ChildKind.PROPER).iterator();
        while (i.hasNext()) {
            LWComponent component = (LWComponent) i.next();
            if (component instanceof LWNode) {
                final LWNode node = (LWNode) component;

                final String notes = node.getNotes();

                entryCount++;

                table = new PdfPTable(new float[] { 1, 1 });
                table.getDefaultCell().setBorder(0);

                table.setSpacingAfter(20.0f);
                Paragraph p = new Paragraph();

                p.setAlignment(Element.ALIGN_CENTER);

                Phrase phrase = new Phrase(notes);

                Font f = phrase.getFont();
                f.setSize(8.0f);
                p.setFont(f);
                cell = new PdfPCell(phrase);
                cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
                cell.setBorder(0);

                PdfPCell i2 = new PdfPCell();
                i2.setFixedHeight(172);
                i2.setBorder(0);

                //Render the table then throw the images on
                PdfContentByte cb = writer.getDirectContent();
                PdfTemplate tp = cb.createTemplate(SlideSizeX, SlideSizeY);

                Point2D.Float offset = new Point2D.Float();
                //center vertically only if landscape mode
                //if (format.getOrientation() == PageFormat.LANDSCAPE)
                //TODO: allow horizontal centering, but not vertical centering (handle in computeZoomFit)

                Rectangle2D bounds = null;

                bounds = node.getBounds();

                Dimension page = null;

                page = new Dimension(SlideSizeX, 172);

                //   PdfTemplate tp = cb.createTemplate(document.getPageSize().width()-80, document.getPageSize().height()-80);
                double scale = ZoomTool.computeZoomFit(page, 15, bounds, offset, true);
                PdfGraphics2D g2d = (PdfGraphics2D) tp.createGraphics(SlideSizeX, SlideSizeY, getFontMapper(),
                        false, 60.0f);
                DrawContext dc = new DrawContext(g2d, scale, -offset.x, -offset.y, null, // frame would be the PageFormat offset & size rectangle
                        node, false); // todo: absolute links shouldn't be spec'd here

                dc.setClipOptimized(false);
                dc.setPrintQuality();
                node.drawFit(dc, 15);

                g2d.dispose();

                Image img = Image.getInstance(tp);
                table.addCell(img);
                table.addCell(cell);
                p.add(table);
                document.add(p);
            }
        }

    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    } finally {
        GUI.clearWaitCursor();
    }

    // step 5: we close the document
    document.close();

}

From source file:tufts.vue.PresentationNotes.java

License:Educational Community License

public static void createOutline(File file) {
    //page size notes:
    //martin-top,left,right,bottom = 36
    //widht :612/*from www .  java2  s .c  om*/
    //height : 792
    //usable space 540 x 720
    // step 1: creation of a document-object               
    Document document = new Document(PageSize.LETTER);

    try {
        GUI.activateWaitCursor();
        // step 2:
        // we create a writer that listens to the document
        // and directs a PDF-stream to a file            
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file));
        //  writer.setDefaultColorspace(PdfName.DEFAULTRGB, null);
        // writer.setStrictImageSequence(true);

        // step 3: we open the document
        document.open();

        Paragraph p1 = new Paragraph(VUE.getActivePathway().getLabel());
        p1.setSpacingAfter(15.0f);
        Font f = p1.getFont();
        f.setStyle(Font.BOLD);
        p1.setFont(f);
        document.add(p1);

        /*p1.add("The leading of this paragraph is calculated automagically. ");
        p1.add("The default leading is 1.5 times the fontsize. ");
        p1.add(new Chunk("You can add chunks "));
        p1.add(new Phrase("or you can add phrases. "));
        p1.add(new Phrase(
           */
        int entryCount = 1;
        int currentIndex = VUE.getActivePathway().getIndex();

        VUE.getActivePathway().setIndex(-1);
        for (LWPathway.Entry entry : VUE.getActivePathway().getEntries()) {

            String notes = entry.getNotes();
            Paragraph p = new Paragraph(entryCount + ".  " + entry.getLabel());
            f = p.getFont();
            f.setStyle(Font.BOLD);
            p.setFont(f);
            Paragraph notesP = new Paragraph(notes);
            notesP.setIndentationLeft(15.0f);
            notesP.setSpacingAfter(15.0f);
            document.add(p);
            document.add(notesP);

            entryCount++;
        }
        VUE.getActivePathway().setIndex(currentIndex);
    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    } finally {
        GUI.clearWaitCursor();
    }
    // step 5: we close the document
    document.close();

}

From source file:tufts.vue.PresentationNotes.java

License:Educational Community License

public static void createNodeOutline(File file) {
    //page size notes:
    //martin-top,left,right,bottom = 36
    //widht :612//w ww  .  j  a  v  a 2 s .c  om
    //height : 792
    //usable space 540 x 720
    // step 1: creation of a document-object               
    Document document = new Document(PageSize.LETTER);

    try {
        GUI.activateWaitCursor();
        // step 2:
        // we create a writer that listens to the document
        // and directs a PDF-stream to a file            
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file));
        //  writer.setDefaultColorspace(PdfName.DEFAULTRGB, null);
        // writer.setStrictImageSequence(true);

        // step 3: we open the document
        document.open();

        Paragraph p1 = new Paragraph(VUE.getActiveMap().getLabel());

        p1.setSpacingAfter(15.0f);
        Font f = p1.getFont();
        f.setStyle(Font.BOLD);
        f.setSize(18f);
        p1.setFont(f);
        document.add(p1);

        String n2 = VUE.getActiveMap().getNotes();
        if (n2 != null && n2.length() > 0) {
            Paragraph p2 = new Paragraph(n2);
            p2.setIndentationLeft(30.0f);
            p2.setSpacingAfter(15.0f);
            //   f = p2.getFont();
            //f.setSize(f.getSize()-2);
            //p2.setFont(f);
            document.add(p2);
        }

        int entryCount = 1;
        float indentation = 0.0f;
        Iterator it = VUE.getActiveMap().getAllDescendents(LWComponent.ChildKind.PROPER).iterator();

        while (it.hasNext()) {
            LWComponent c = (LWComponent) it.next();
            if (c instanceof LWNode) {
                LWNode n = (LWNode) c;
                outlineChildNode(document, indentation, n, entryCount);
                entryCount++;
                iterateChildren(document, indentation + 10, n, 1);
            }

        }

        it = VUE.getActiveMap().getAllDescendents(LWComponent.ChildKind.PROPER).iterator();
        while (it.hasNext()) {
            LWComponent c = (LWComponent) it.next();
            if (c instanceof LWLink) {
                LWLink l = (LWLink) c;
                String notes = l.getNotes();
                String linkLabel = l.getLabel();

                if ((notes == null || notes.length() == 0) && (linkLabel == null || linkLabel.length() == 0))
                    continue;

                if (linkLabel == null || linkLabel.length() == 0)
                    linkLabel = "Link";

                Paragraph p = new Paragraph(entryCount + ".  " + linkLabel.replaceAll("\\n", ""));
                f = p.getFont();
                f.setStyle(Font.BOLD);
                f.setSize(14f);
                p.setFont(f);
                Paragraph notesP = new Paragraph(notes);

                // f = notesP.getFont();
                //   f.setSize(f.getSize()-2);
                notesP.setIndentationLeft(30.0f);
                notesP.setSpacingAfter(15.0f);
                document.add(p);
                document.add(notesP);

                entryCount++;
            }
        }

    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    } finally {
        GUI.clearWaitCursor();
    }
    // step 5: we close the document
    document.close();

}