List of usage examples for com.lowagie.text.pdf PdfWriter close
public void close()
Document
was closed and that no other Elements
will be added. From source file:it.prato.comune.tolomeo.web.TolomeoPrintPDFServlet.java
License:Open Source License
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { LogInterface logger = getLogger(request); String titolo = request.getParameter("titolo"); String descrizione = request.getParameter("descrizione"); String scala = request.getParameter("scala"); String mapx = request.getParameter("mapx"); String mapy = request.getParameter("mapy"); //creo URL alla mappa URL urlMappa = new URL(URLDecoder.decode(request.getParameter("urlMappa"), "UTF-8")); URI uriMappa = null;/*from w w w . jav a2 s. c o m*/ try { uriMappa = new URI(urlMappa.getProtocol(), null, urlMappa.getHost(), urlMappa.getPort(), urlMappa.getPath(), urlMappa.getQuery() + "&mode=map&scale=" + scala + "&mapxy=" + mapx + "+" + mapy + "&map_size=500 500", null); logger.info("URI di stampa mappa: " + uriMappa); } catch (URISyntaxException e) { logger.error("URI errore di sintassi", e); } Font BOLD15 = new Font(Font.HELVETICA, 15, Font.BOLD); Font FONT12 = new Font(Font.HELVETICA, 12, Font.NORMAL); Font FONT10 = new Font(Font.HELVETICA, 10, Font.NORMAL); Document doc = new Document(); ; PdfWriter pdf = null; Paragraph par = new Paragraph(); try { //creo il PDF response.setContentType("application/pdf"); pdf = PdfWriter.getInstance(doc, response.getOutputStream()); //attributi file doc.addTitle("Mappa di Prato"); doc.addAuthor("Comune di Prato"); doc.open(); //intestazione par.setAlignment(Paragraph.ALIGN_CENTER); print("Comune di Prato", BOLD15, par, doc); print(titolo, FONT10, par, doc); print("", FONT10, par, doc); //mappa Image mappa = Image.getInstance(uriMappa.toURL()); mappa.setAlignment(Image.MIDDLE); mappa.setBorder(Rectangle.BOX); mappa.setBorderWidth(1f); doc.add(mappa); } catch (Exception e) { logger.error("Errore durante la creazione del PDF", e); printErr(doc); } finally { doc.close(); pdf.close(); response.getOutputStream().close(); } }
From source file:jp.ac.utokyo.rcast.karkinos.graph.output.PdfReport.java
License:Apache License
public static void report(ReadsSummary readsSummary, String readsStat, DataSet dataset, AllelicCNV alCNV, NoiseAnalysis na, PeaksInfo pi, String id, String outfile) throws Exception { List<DisplayObject> chartList = new ArrayList<DisplayObject>(); chartList.addAll(GetReadsStatsChart.getChartLists(readsSummary, readsStat)); // chartList.addAll(GetReadDirectionChart.getChartLists(dataset)); chartList.addAll(SNPGraph.getChartList(dataset)); chartList.addAll(GetGCAdjustGrapth.getChartLists(dataset)); chartList.addAll(GetCNVPreGraph.getChartLists(dataset)); chartList.addAll(GetCNVPeaksCharts.getChartLists(pi)); chartList.addAll(GetCNVCharts.getChartLists(dataset, pi, id)); //allelic CNV chartList.addAll(GetAllelicCNVGraph.getChartLists(alCNV, id)); chartList.addAll(GetCNVCharts.getTables(dataset)); // chartList.addAll(GetSNVDistChart.getChartLists(dataset)); ////from w ww . jav a 2s . c o m try { chartList.addAll(NoisePeakChart.getChartLists(na, dataset.getTumorRatio())); } catch (Exception ex) { ex.printStackTrace(); } chartList.addAll(GetSNVChart.getChartLists(dataset, pi)); chartList.addAll(GetThresholdsCharts.getChartLists(dataset)); Document document = null; PdfWriter writer = null; FileOutputStream fileOutputStream = new FileOutputStream(outfile); try { // instantiate document and writer document = new Document(); writer = PdfWriter.getInstance(document, fileOutputStream); // open document document.open(); // add image int width = 1200; int hight = 1000; int i = 0; int figcount = 0; for (DisplayObject dobj : chartList) { int size = dobj.getSize(); Object obj = dobj.getObject(); if (obj == null) continue; document.add(new Paragraph(String.valueOf(dobj.getTitle()))); if (obj instanceof List) { for (Object childObj : (List) obj) { addObj(document, childObj, width, hight, size, writer, figcount); if ((childObj instanceof Table) || (obj instanceof JFreeChart)) { figcount++; document.add(Chunk.NEXTPAGE); } } } else { addObj(document, obj, width, hight, size, writer, figcount); figcount++; } document.add(Chunk.NEXTPAGE); i++; } // release resources document.close(); document = null; writer.close(); writer = null; } catch (DocumentException de) { throw de; } catch (IOException ioe) { throw ioe; } finally { // release resources if (null != document) { try { document.close(); } catch (Exception ex) { } } if (null != writer) { try { writer.close(); } catch (Exception ex) { } } } }
From source file:jp.ac.utokyo.rcast.karkinos.summary.RegionGraph.java
License:Apache License
/** * @param args/*from w w w.j a v a 2s.co m*/ */ public static void main(String[] args) { String indir = "/GLUSTER_DIST/data/users/ueda/ICGC/ICGCkarkinos4.0/HCC_exome_rcast," + "/GLUSTER_DIST/data/users/ueda/ICGC/ICGCkarkinos4.0/HCC_NCC/karkinosver4.0.25," + "/GLUSTER_DIST/data/users/ueda/ICGC/ICGCkarkinos4.0/HCC_exome_baylor/HCC-JP-453-T-HCC-JP-453-N/HCC-JP-453-T-HCC-JP-453-N," + "/GLUSTER_DIST/data/users/ueda/ICGC/bcmtest/tcga," + "/GLUSTER_DIST/data/users/ueda/ICGC/bcmtest/goss,"; // // String indir = // "/GLUSTER_DIST/data/users/ueda/ICGC/ICGCkarkinos4.0/HCC_exome_rcast/THCC_167T-THCC_167N/THCC_167T-THCC_167N/"; String out = "/GLUSTER_DIST/data/users/ueda/ICGC/ICGCkarkinos4.0/chr5Graprh.pdf"; String outpng = "/GLUSTER_DIST/data/users/ueda/ICGC/ICGCkarkinos4.0/chr1Graprh.jpeg"; List<File> list = new ArrayList<File>(); for (String s : indir.split(",")) { File f = new File(s); // chage to reccursive file search searchRecursive(f, list); } String chr = "chr5"; int start = 0; int end = 50000000; // String chr = "chr11"; // int start = 0; // int end = 135000000; // String chr = "chr1"; // int start = 0; // int end = 247000000; int[][] target = new int[][] { { 1278756, 1295162 } }; Document document = null; PdfWriter writer = null; int width = 1200; int hight = 500; int size = 1; try { FileOutputStream fileOutputStream = new FileOutputStream(out); document = new Document(); writer = PdfWriter.getInstance(document, fileOutputStream); document.open(); for (File f : list) { document.add(new Paragraph(String.valueOf(f.getName()))); Object[] obj = getChart(f, chr, start, end, target); document.add(new Paragraph("mean=" + toStr(obj[1]) + "\t mean original=" + toStr(obj[2]))); JFreeChart chart = (JFreeChart) obj[0]; // try { // File jpn = new File(outpng); // ChartUtilities.saveChartAsJPEG(jpn, chart, 300, 300); // // } catch (Exception ex) { // // } BufferedImage bufferedImage = chart.createBufferedImage(width * size, hight * size); Image image = Image.getInstance(writer, bufferedImage, 1.0f); image.scalePercent(20); document.add(image); } document.close(); document = null; writer.close(); writer = null; } catch (Exception e) { e.printStackTrace(); } finally { // release resources if (null != document) { try { document.close(); } catch (Exception ex) { } } if (null != writer) { try { writer.close(); } catch (Exception ex) { } } } }
From source file:jp.ac.utokyo.rcast.karkinos.summary.RegionGraph2.java
License:Apache License
/** * @param args//from ww w . j a va 2 s . c o m */ public static void main(String[] args) { String indir = "/GLUSTER_DIST/data/users/ueda/ICGC/ICGCkarkinos4.0/HCC_exome_rcast," + "/GLUSTER_DIST/data/users/ueda/ICGC/ICGCkarkinos4.0/HCC_NCC/karkinosver4.0.25," + "/GLUSTER_DIST/data/users/ueda/ICGC/ICGCkarkinos4.0/HCC_exome_baylor/HCC-JP-453-T-HCC-JP-453-N/HCC-JP-453-T-HCC-JP-453-N," + "/GLUSTER_DIST/data/users/ueda/ICGC/bcmtest/tcga," + "/GLUSTER_DIST/data/users/ueda/ICGC/bcmtest/goss,"; // // String indir = // "/GLUSTER_DIST/data/users/ueda/ICGC/ICGCkarkinos4.0/HCC_exome_rcast/THCC_167T-THCC_167N/THCC_167T-THCC_167N/"; String out = "/GLUSTER_DIST/data/users/ueda/ICGC/ICGCkarkinos4.0/chr4allelicGraprh.pdf"; // String outpng = // "/GLUSTER_DIST/data/users/ueda/ICGC/ICGCkarkinos4.0/chr1Graprh.jpeg"; List<File> list = new ArrayList<File>(); for (String s : indir.split(",")) { File f = new File(s); // chage to reccursive file search searchRecursive(f, list); } // String chr = "chr5"; // int start = 0; // int end = 300000; // String chr = "chr11"; // int start = 0; // int end = 135000000; String chr = "chr4"; int start = 0; int end = 247000000; int[][] target = new int[][] { { 190328975, 190903950 } }; Document document = null; PdfWriter writer = null; int width = 1200; int hight = 500; int size = 1; try { FileOutputStream fileOutputStream = new FileOutputStream(out); document = new Document(); writer = PdfWriter.getInstance(document, fileOutputStream); document.open(); for (File f : list) { document.add(new Paragraph(String.valueOf(f.getName()))); Object[] obj = getChart(f, chr, start, end, target, 1); document.add(new Paragraph("mean=" + toStr(obj[1]) + "\t mean original=" + toStr(obj[2]))); JFreeChart chart = (JFreeChart) obj[0]; // try { // File jpn = new File(outpng); // ChartUtilities.saveChartAsJPEG(jpn, chart, 300, 300); // // } catch (Exception ex) { // // } BufferedImage bufferedImage = chart.createBufferedImage(width * size, hight * size); Image image = Image.getInstance(writer, bufferedImage, 1.0f); image.scalePercent(20); document.add(image); obj = getChart(f, chr, start, end, target, 2); chart = (JFreeChart) obj[0]; // try { // File jpn = new File(outpng); // ChartUtilities.saveChartAsJPEG(jpn, chart, 300, 300); // // } catch (Exception ex) { // // } bufferedImage = chart.createBufferedImage(width * size, hight * size); image = Image.getInstance(writer, bufferedImage, 1.0f); image.scalePercent(20); document.add(image); } document.close(); document = null; writer.close(); writer = null; } catch (Exception e) { e.printStackTrace(); } finally { // release resources if (null != document) { try { document.close(); } catch (Exception ex) { } } if (null != writer) { try { writer.close(); } catch (Exception ex) { } } } }
From source file:jp.ac.utokyo.rcast.karkinos.summary.TextToGraph.java
License:Apache License
/** * @param args/* w w w . ja v a 2 s .c o m*/ */ public static void main(String[] args) { // String s = // "/GLUSTER_DIST/data/users/ueda/ICGC/bcmtest/TCGA-MR-A520-01A-11D-A25V-10.vs-10_cnvAllelicDepth.txt"; // String s2 = // "/GLUSTER_DIST/data/users/ueda/ICGC/bcmtest/TCGA-MR-A520-01A-11D-A25V-10.vs-10_cnvdepth.txt"; // String sout = "/GLUSTER_DIST/data/users/ueda/ICGC/bcmtest/out.pdf"; String s = "/GLUSTER_DIST/data/users/ueda/ICGC/bcmtest/HCC-JP-468-T.vs-N_cnvAllelicDepth.txt"; String s2 = "/GLUSTER_DIST/data/users/ueda/ICGC/bcmtest/HCC-JP-468-T.vs-N_cnvdepth.txt"; String sout = "/GLUSTER_DIST/data/users/ueda/ICGC/bcmtest/468out.pdf"; Document document = null; PdfWriter writer = null; // try { int width = 1200; int hight = 500; int size = 1; FileOutputStream fileOutputStream = new FileOutputStream(sout); document = new Document(); writer = PdfWriter.getInstance(document, fileOutputStream); document.open(); JFreeChart chart0 = getChart(new File(s2), 0); JFreeChart chart1 = getChart(new File(s2), 1); JFreeChart chart2 = getChart(new File(s2), 2); JFreeChart chart3 = getChart(new File(s2), 3); JFreeChart chart4 = getChart(new File(s), 4); JFreeChart chart5 = getChart(new File(s), 5); JFreeChart chart6 = getChart(new File(s), 6); BufferedImage bufferedImage = chart0.createBufferedImage(width * size, hight * size); Image image = Image.getInstance(writer, bufferedImage, 1.0f); image.scalePercent(20); document.add(image); BufferedImage bufferedImage1 = chart1.createBufferedImage(width * size, hight * size); Image image1 = Image.getInstance(writer, bufferedImage1, 1.0f); image1.scalePercent(20); document.add(image1); BufferedImage bufferedImage2 = chart2.createBufferedImage(width * size, hight * size); Image image2 = Image.getInstance(writer, bufferedImage2, 1.0f); image2.scalePercent(20); document.add(image2); BufferedImage bufferedImage3 = chart3.createBufferedImage(width * size, hight * size); Image image3 = Image.getInstance(writer, bufferedImage3, 1.0f); image3.scalePercent(20); document.add(image3); BufferedImage bufferedImage4 = chart4.createBufferedImage(width * size, hight * size); Image image4 = Image.getInstance(writer, bufferedImage4, 1.0f); image4.scalePercent(20); document.add(image4); BufferedImage bufferedImage5 = chart5.createBufferedImage(width * size, hight * size); Image image5 = Image.getInstance(writer, bufferedImage5, 1.0f); image5.scalePercent(20); document.add(image5); BufferedImage bufferedImage6 = chart6.createBufferedImage(width * size, hight * size); Image image6 = Image.getInstance(writer, bufferedImage6, 1.0f); image6.scalePercent(20); document.add(image6); document.close(); document = null; writer.close(); writer = null; } catch (Exception e) { e.printStackTrace(); } finally { // release resources if (null != document) { try { document.close(); } catch (Exception ex) { } } if (null != writer) { try { writer.close(); } catch (Exception ex) { } } } }
From source file:knop.psfj.exporter.PDFExporter.java
License:Open Source License
/** * Write single file report./* www . j a va 2 s. c o m*/ * * @param frameList the frame list * @param path the path * @param page the page * @return the runnable */ public Runnable writeSingleFileReport(final BeadFrameList frameList, final String path, int page) { return new Runnable() { public void run() { Document document = null; PdfWriter writer = null; if (FileUtils.folderExists(path)) FileUtils.deleteFile(path); try { document = new Document(); writer = PdfWriter.getInstance(document, new FileOutputStream(path)); document.open(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (writer == null || document == null) return; for (BeadFrame frame : frameList) { //System.out.println("profile : " + frame); fillReport(document, writer, frame, frame.getId()); document.newPage(); incrementCount(); } document.close(); writer.close(); } }; }
From source file:knop.psfj.exporter.PDFExporter.java
License:Open Source License
/** * Export bead image list.//www . j a v a 2 s. c o m * * @param imageList the image list * @param path the path */ public void exportBeadImageList(BeadFrameList imageList, String path) { Document document = new Document(); try { int i = 0; int max = imageList.size(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(new File(path))); document.open(); for (BeadFrame frame : imageList) { fillReport(document, writer, frame, frame.getId()); setChanged(); Integer progress = new Integer(100 * i++ / max); if (progress == 0) progress = 1; notifyObservers(new Message(this, "progress changed", String.format("Generating bead PDF reports : %d/%d", i, max), progress)); document.newPage(); } document.close(); writer.close(); sendFinishMessage("Done."); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); setChanged(); notifyObservers(new Message("this", "error", "Error when generating PDF.")); } }
From source file:net.refractions.udig.printing.ui.internal.PdfPrintingEngine.java
License:Open Source License
public boolean printToPdf() { Dimension paperSize = page.getPaperSize(); Dimension pageSize = page.getSize(); float xScale = (float) paperSize.width / (float) pageSize.width; float yScale = (float) paperSize.height / (float) pageSize.height; Rectangle paperRectangle = new Rectangle(paperSize.width, paperSize.height); Document document = new Document(paperRectangle, 0f, 0f, 0f, 0f); try {/*from w w w .j a va 2s . c om*/ PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(outputPdfFile)); document.open(); PdfContentByte cb = writer.getDirectContent(); Graphics2D graphics = cb.createGraphics(paperRectangle.getWidth(), paperRectangle.getHeight()); // BufferedImage bI = new BufferedImage((int) paperRectangle.width(), (int) // paperRectangle // .height(), BufferedImage.TYPE_INT_ARGB); // Graphics graphics2 = bI.getGraphics(); List<Box> boxes = page.getBoxes(); for (Box box : boxes) { String id = box.getID(); System.out.println(id); Point boxLocation = box.getLocation(); if (boxLocation == null) continue; int x = boxLocation.x; int y = boxLocation.y; Dimension size = box.getSize(); if (size == null) continue; int w = size.width; int h = size.height; float newX = xScale * (float) x; float newY = yScale * (float) y; float newW = xScale * (float) w; float newH = yScale * (float) h; box.setSize(new Dimension((int) newW, (int) newH)); box.setLocation(new Point((int) newX, (int) newY)); Graphics2D boxGraphics = (Graphics2D) graphics.create((int) newX, (int) newY, (int) newW, (int) newH); BoxPrinter boxPrinter = box.getBoxPrinter(); boxPrinter.draw(boxGraphics, monitor); } graphics.dispose(); // ImageIO.write(bI, "png", new File("c:\\Users\\moovida\\Desktop\\test.png")); // graphics.drawImage(bI, null, 0, 0); document.newPage(); document.close(); writer.close(); } catch (DocumentException e) { e.printStackTrace(); return false; } catch (IOException e) { e.printStackTrace(); return false; } return true; }
From source file:org.andrill.coretools.graphics.driver.pdf.PDFDriver.java
License:Apache License
public static void main(final String[] args) throws Exception { Paper paper = Paper.getDefault(); // raster graphics RasterGraphics raster = new RasterGraphics(paper.getWidth(), paper.getHeight(), true); raster.pushTransform(AffineTransform.getTranslateInstance(36, 36)); drawTest(raster);/*from ww w .ja v a2s. c o m*/ raster.write(new File("Test.png")); // pdf graphics Document document = new Document(new com.lowagie.text.Rectangle(paper.getWidth(), paper.getHeight())); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("Test.pdf")); document.open(); drawTest(new GraphicsContext(new PDFDriver(writer.getDirectContent(), paper))); document.close(); writer.close(); }
From source file:org.dgl.imgstopdf.Main.java
public static void main(String[] args) { Document document = new Document(); ArrayList<String> input; String output = ".\\out.pdf"; try {//from w ww.j a v a 2s . com FileOutputStream fos = new FileOutputStream(output); PdfWriter pdfWriter = PdfWriter.getInstance(document, fos); Image image; JFileChooser fc = new JFileChooser(".\\"); fc.setMultiSelectionEnabled(true); FileNameExtensionFilter filter = new FileNameExtensionFilter("IMAGES", "jpg", "jpeg", "gif", "png", "bmp"); fc.setFileFilter(filter); int userOption = fc.showOpenDialog(null); if (userOption == JFileChooser.APPROVE_OPTION) { input = new ArrayList<String>(); for (File f : fc.getSelectedFiles()) { input.add(f.getAbsolutePath()); } if (fc.getSelectedFile() != null) { input.add(fc.getSelectedFile().getAbsolutePath()); } } else { return; } if (input.size() == 0) { return; } pdfWriter.open(); document.open(); for (Object fileName : input.toArray()) { image = Image.getInstance((String) fileName); float scaler = ((document.getPageSize().getWidth() - document.leftMargin() - document.rightMargin()) / image.getWidth()) * 100; image.scalePercent(scaler); document.add(image); } document.close(); pdfWriter.close(); JOptionPane.showMessageDialog(null, "OK", "", JOptionPane.INFORMATION_MESSAGE); } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(null, ex.toString(), "", JOptionPane.ERROR_MESSAGE); } }