List of usage examples for com.lowagie.text Document newPage
public boolean newPage()
From source file:tufts.vue.PresentationNotes.java
License:Educational Community License
public static void createSpeakerNotes1PerPage(File file) { // step 1: creation of a document-object //This is a bit of a mess but because of hte bugs with drawing the slides //the easy way, we have no other choice but to render them directly onto the pdf //which makes it hard to use tables for stuff like formatting text...so we'll render // a blank table cell then render the image into it. Document document = new Document(); try {/*from w ww .j a v a2 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)); // step 3: we open the document document.open(); PdfPTable table; PdfPCell cell; 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(); //String label = entry.getLabel(); PdfContentByte cb = writer.getDirectContent(); Point2D.Float offset = new Point2D.Float(); Rectangle2D bounds = null; //if (!entry.isMapView()) bounds = slide.getBounds(); //else //bounds = entry.getFocal().getBounds(); Dimension page = null; page = new Dimension(432, 324); PdfTemplate tp = cb.createTemplate(432, 324); double scale = ZoomTool.computeZoomFit(page, 5, bounds, offset, true); PdfGraphics2D g2d = (PdfGraphics2D) tp.createGraphics(432, 324, 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(); cb.addTemplate(tp, 80, 482); //Paragraph p = new Paragraph(); //p.setExtraParagraphSpace(330); // p.setSpacingBefore(330f); // p.setAlignment(Element.ALIGN_CENTER); Paragraph phrase = new Paragraph(notes); //phrase.setExtraParagraphSpace(340f); phrase.setSpacingBefore(320f); phrase.setKeepTogether(true); //cell = new PdfPCell(phrase); //cell.setBorder(0); // table = new PdfPTable(new float[]{ 1 }); // table.setWidthPercentage(100.0f); // table.getDefaultCell().setBorder(0); //table.getDefaultCell().setPaddingTop(30); //PdfPCell c2 = new PdfPCell(); //c2.setFixedHeight(340); //slides are 540x405 //c2.setBorder(0); //table.addCell(c2); //table.addCell(cell); //table.setKeepTogether(false); //cell.setVerticalAlignment(PdfPCell.ALIGN_TOP); //p.add(table); //System.out.println("CELL HEIGHT : " + cell.getHeight()); //Section s1 = new Section(); //ColumnText chunk2 = new ColumnText(cb); //chunk2.setText(phrase); //chunk2.setSi //chunk2.setSimpleColumn(phrase,70, 330, document.getPageSize().width()-70,document.getPageSize().height()-70,15, Element.ALIGN_LEFT); // chunk2.go(); //PdfChunk chunk2 = new PdfChunk); Paragraph p2 = new Paragraph(" "); p2.setKeepTogether(false); phrase.setKeepTogether(false); // p2.setExtraParagraphSpace(230f); document.add(p2); document.add(phrase); document.newPage(); } 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:ugh.fileformats.pdf.PortableDocumentFormat.java
License:Open Source License
/*************************************************************************** * @param document//from w w w . j av a 2s .c om * @param cf * @return **************************************************************************/ private boolean writeTIFFImage(com.lowagie.text.Document document, ContentFile cf) { RenderedOp inImage = null; RenderedOp outImage = null; Image itextimg = null; // Read metadata. String xresolution_string = null; String yresolution_string = null; String samples_string = null; String bitspersamples_string = null; String height_string = null; String width_string = null; long orig_width = 0; long orig_height = 0; List<Metadata> allMD = cf.getAllMetadata(); // No metadata available. if (allMD == null) { return false; } Iterator<Metadata> it = allMD.iterator(); while (it.hasNext()) { Metadata md = it.next(); if (md.getType().getName().equals("ugh_height")) { height_string = md.getValue(); } if (md.getType().getName().equals("ugh_width")) { width_string = md.getValue(); } if (md.getType().getName().equals("ugh_xresolution")) { xresolution_string = md.getValue(); } if (md.getType().getName().equals("ugh_yresolution")) { yresolution_string = md.getValue(); } if (md.getType().getName().equals("ugh_samples")) { samples_string = md.getValue(); } if (md.getType().getName().equals("ugh_bitspersamples")) { bitspersamples_string = md.getValue(); } } if (xresolution_string == null || yresolution_string == null || height_string == null || width_string == null || samples_string == null || bitspersamples_string == null) { System.err .println("ERROR: Can't get all needed technical metadata for contentfile " + cf.getLocation()); return false; } int xresolution = Integer.parseInt(xresolution_string); int yresolution = Integer.parseInt(yresolution_string); // Read tiff file and convert it to Buffered Images. try { FileSeekableStream ffs = new FileSeekableStream(cf.getLocation()); // Create an image for Java Advanced Imaging. inImage = JAI.create("stream", ffs); orig_width = inImage.getWidth(); orig_height = inImage.getHeight(); } catch (IOException ioe) { System.err.println("Can't read contentfile " + cf.getLocation()); return false; } // Set scaling factor; usually we had to calculate it. int scale = 100; ParameterBlock params = new ParameterBlock(); params.addSource(inImage); params.add(scale); params.add(scale); params.add(0.0F); params.add(0.0F); params.add(new InterpolationNearest()); outImage = JAI.create("scale", params); // Create buffered image. BufferedImage newbi = outImage.getAsBufferedImage(); try { itextimg = Image.getInstance(newbi, null, true); } catch (IOException ioe) { } catch (BadElementException bee) { } // Define page size. int page_w = 210; int page_h = 297; // Scale image, if it doesn't fit on page. float page_w_pixel = (float) (page_w * xresolution / 25.4); float page_h_pixel = (float) (page_h * yresolution / 25.4); // Calculate actual scale factor. // // Check, if image will fit on page. if ((orig_width > page_w_pixel) || (orig_height > page_h_pixel)) { // Does not fit on page. float scalefactor = 0; float scalefactor_w = page_w_pixel / orig_width; float scalefactor_h = page_h_pixel / orig_height; if (scalefactor_h < scalefactor_w) { scalefactor = scalefactor_h; } else { scalefactor = scalefactor_w; } // orig_width = (long) (orig_width * scalefactor); // orig_height = (long) (orig_height * scalefactor); // Do scaling. itextimg.scalePercent((72f / xresolution * 100) * scalefactor, (72f / yresolution * 100) * scalefactor); } else { // Do scaling. itextimg.scalePercent((72f / xresolution * 100), (72f / yresolution * 100)); } // Add page. try { document.add(itextimg); // Create new page. document.newPage(); } catch (DocumentException de) { System.err.println("PortableDocumentFormat: DocumentException for Contentfile " + cf.getLocation()); } return true; }