LISTSERV mailing list manager LISTSERV 16.5

Help for LCDET-SVN Archives


LCDET-SVN Archives

LCDET-SVN Archives


LCDET-SVN@LISTSERV.SLAC.STANFORD.EDU


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Proportional Font

LISTSERV Archives

LISTSERV Archives

LCDET-SVN Home

LCDET-SVN Home

LCDET-SVN  March 2015

LCDET-SVN March 2015

Subject:

r3580 - in /projects/lcsim/trunk/aida: pom.xml src/main/java/org/lcsim/util/aida/PDFWriter.java

From:

[log in to unmask]

Reply-To:

Notification of commits to the lcdet svn repository <[log in to unmask]>

Date:

Fri, 27 Mar 2015 18:20:07 -0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (130 lines)

Author: [log in to unmask]
Date: Fri Mar 27 11:20:02 2015
New Revision: 3580

Log:
Add class for writing out plotter graphics to a PDF.

Added:
    projects/lcsim/trunk/aida/src/main/java/org/lcsim/util/aida/PDFWriter.java
Modified:
    projects/lcsim/trunk/aida/pom.xml

Modified: projects/lcsim/trunk/aida/pom.xml
 =============================================================================
--- projects/lcsim/trunk/aida/pom.xml	(original)
+++ projects/lcsim/trunk/aida/pom.xml	Fri Mar 27 11:20:02 2015
@@ -38,6 +38,11 @@
             <groupId>org.freehep</groupId>
             <artifactId>freehep-record</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.pdfbox</groupId>
+            <artifactId>pdfbox</artifactId>
+            <version>1.8.8</version>
+        </dependency>
     </dependencies>
     <build>
         <plugins>

Added: projects/lcsim/trunk/aida/src/main/java/org/lcsim/util/aida/PDFWriter.java
 =============================================================================
--- projects/lcsim/trunk/aida/src/main/java/org/lcsim/util/aida/PDFWriter.java	(added)
+++ projects/lcsim/trunk/aida/src/main/java/org/lcsim/util/aida/PDFWriter.java	Fri Mar 27 11:20:02 2015
@@ -0,0 +1,89 @@
+package org.lcsim.util.aida;
+
+import hep.aida.IAnalysisFactory;
+import hep.aida.IHistogram1D;
+import hep.aida.IHistogramFactory;
+import hep.aida.IPlotter;
+import hep.aida.IPlotterFactory;
+import hep.aida.ref.AnalysisFactory;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Random;
+
+import org.apache.pdfbox.exceptions.COSVisitorException;
+import org.apache.pdfbox.util.PDFMergerUtility;
+
+/**
+ * Write out plotter graphics to a PDF file.
+ * 
+ * @author Jeremy McCormick <[log in to unmask]>
+ */
+public class PDFWriter {
+    
+    /**
+     * Create PDF files from plotters and merge them into a single file with one plot per page.
+     * @param plotters The list of plotters.
+     * @param fileName The name of the output file.
+     * @throws IOException If there is a problem merging the PDFs together.
+     */
+    public static void write(Collection<IPlotter> plotters, String fileName) throws IOException {
+        
+        PDFMergerUtility merge = new PDFMergerUtility();
+        merge.setDestinationFileName(fileName);
+        
+        List<File> files = new ArrayList<File>();
+        for (IPlotter plotter : plotters) {
+            File tempFile = File.createTempFile("plots", ".pdf");
+            files.add(tempFile);
+            plotter.writeToFile(tempFile.getPath(), "pdf");
+            merge.addSource(tempFile);
+        }
+        
+        try {
+            merge.mergeDocuments();
+        } catch (COSVisitorException e) {
+            throw new IOException("Error merging documents", e);
+        }
+    }
+    
+    /**
+     * This is just a simple test that writes a few plots.
+     * @param args
+     */
+    public static void main(String[] args) {
+        
+        IAnalysisFactory af = AnalysisFactory.create();
+        IPlotterFactory pf = af.createPlotterFactory();
+        IHistogramFactory hf = af.createHistogramFactory(null);
+        
+        IHistogram1D histogram1 = hf.createHistogram1D("Histogram 1", 100, 0., 10.);
+        IHistogram1D histogram2 = hf.createHistogram1D("Histogram 2", 100, 0., 10.);
+        Random random = new Random();
+        for (int i = 0; i < 10000; i++) {
+            histogram1.fill(random.nextDouble() * 10);
+            histogram2.fill(random.nextDouble() * 10);
+        }
+        
+        IPlotter plotter1 = pf.create();
+        plotter1.createRegion();
+        plotter1.region(0).plot(histogram1);
+        
+        IPlotter plotter2 = pf.create();
+        plotter2.createRegion();
+        plotter2.region(0).plot(histogram2);
+        
+        List<IPlotter> plotters = new ArrayList<IPlotter>();
+        plotters.add(plotter1);
+        plotters.add(plotter2);
+        
+        try {
+            PDFWriter.write(plotters, "PDFWriterTest.pdf");
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+    }
+}

########################################################################
Use REPLY-ALL to reply to list

To unsubscribe from the LCDET-SVN list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=LCDET-SVN&A=1

Top of Message | Previous Page | Permalink

Advanced Options


Options

Log In

Log In

Get Password

Get Password


Search Archives

Search Archives


Subscribe or Unsubscribe

Subscribe or Unsubscribe


Archives

January 2016
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
December 2013
November 2013

ATOM RSS1 RSS2



LISTSERV.SLAC.STANFORD.EDU

Secured by F-Secure Anti-Virus CataList Email List Search Powered by the LISTSERV Email List Manager

Privacy Notice, Security Notice and Terms of Use