Resolved. I walked through the Main class code and replicated the steps.
Part of my problem was I was trying to use the java code posted earlier instead of the userconfig.xml FOUserAgent ua = fopFactory.newFOUserAgent(); TIFFRenderer renderer = new TIFFRenderer(); renderer.setUserAgent(ua); renderer.getWriterParams().setCompressionMethod(TIFFConstants.COMPRESSIO N_CCITT_T6); ua.setRendererOverride(renderer); The above will throw the exception I had been seeing. Thanks for all the help! I'll see what I can do to contribute to the group. -Josh -----Original Message----- From: Jeremias Maerki [mailto:[email protected]] Sent: Wednesday, July 14, 2010 2:49 AM To: [email protected] Subject: Re: XML to TIFF CITT conversion - aid requested Hi Joshua Make the config file: <fop version="1.0"> <renderers> <renderer mime="image/tiff"> <compression>CCITT T.6</compression> </renderer> </renderers> </fop> ...and you're there. As for your other question, you can do something like: FOUserAgent ua = fopFactory.newFOUserAgent(); TIFFRenderer renderer = new TIFFRenderer(); renderer.setUserAgent(ua); renderer.getWriterParams().setCompressionMethod(TIFFConstants.COMPRESSIO N_CCITT_T6); ua.setRendererOverride(renderer); ...but the above only applies to FOP 0.95 or later, I think. On 14.07.2010 00:48:13 Marquart, Joshua D wrote: > Hello, > > I've been working on a project to transform XML to TIFF in the CITT G4 > Format and have read several threads regarding the conversion, which has > lead me to believe conversion is a common problem among users. > > Most of the G4 TIFF-related threads end with guru JM providing an > explanation, but with no follow-up response from the thread-starting > user as to whether the explanation/solution worked. I promise if my > issue gets resolved, I will post a success story as a follow-up to this > thread. > > Here is my situation: > > I am trying to convert a FOP-readable xml file into a G4 TIFF. No > matter what I do, it applies as PackBits. > > In addition to resolving this, I am curious as to why there appears to > be no programmatic way to set CCITT compression within the code (ex: a > setCompression(String) method), when TIFFRenderer even contains String > constants representing the three available compression types. > > Also, I could not find a sample configuration file in the distribution; > maybe I missed it. > > Any help / advice would be much appreciated, thanks. > > -Josh (details follow) > > JARS on CLASSPATH: > avalon-framework-4.2.0.jar > batik-all-1.6.jar > commons-io-1.3.1.jar > commons-logging-1.0.4.jar > fop.jar (implementation.94) > serializer-2.7.0.jar > xaland-2.7.0.jar > xercesImpl-2.7.1.jar > xml-apis-1.3.02.jar > xmlgraphics-commons-1.2.jar > log4j-1.2.13.jar > jai-imageio.jar (implementation 1.1) > > FILES: > There are 3 files involved in this (contents follow) > > FILE 1 - testFop.xml > This is the fop formatted xml; I've successfully transformed it to > PostScript and Tiff. > > FILE 2 - tiffFopConfig.xml > This only contains the compression line for CCITT T.6 > > FILE 3 - FopTiffTester.javaThis is the java file for conversion. The > code is abstracted from my own larger codebase where I do instantiate a > single fopFactory and perform best practices - no need for best > practices on this example, IMHO. :-) > > FILE CONTENT: > > FILE 1 - testFop.xml > <?xml version="1.0" encoding="UTF-8"?> > <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"> > <fo:layout-master-set> > <fo:simple-page-master margin-top="0.0in" margin-bottom="0.0in" > page-width="8.5in" page-height="11.0in" master-name="single"> > <fo:region-body padding="0pt 0pt" margin-bottom="0cm" margin-top="0.5cm" > margin-right="1cm" margin-left="1cm"/> > <fo:region-before padding="0pt" display-align="after" extent="1cm" > region-name="left-top"/> > <fo:region-after padding="0pt" display-align="before" extent="1cm" > region-name="footer"/> > <fo:region-start padding="0pt" display-align="center" precedence="true" > extent="1in" region-name="outside"/> > <fo:region-end padding="0pt " display-align="after" precedence="true" > extent="1in" region-name="inside"/> > </fo:simple-page-master> > <fo:page-sequence-master master-name="contents"> > <fo:repeatable-page-master-reference master-reference="single"/> > </fo:page-sequence-master> > </fo:layout-master-set> > <fo:page-sequence initial-page-number="2" master-reference="contents"> > <fo:flow flow-name="xsl-region-body"> > <fo:table width="100%" table-layout="fixed"> > <fo:table-column column-width="19cm"/> > <fo:table-body> > <fo:table-row> > <fo:table-cell font-size="9pt" font-family="Helvetica"> > <fo:block line-height="14pt"> > <fo:block white-space-collapse="true"> > <fo:block font-family="Helvetica" font-size="10pt">Test test test test > test times five.</fo:block> > </fo:block> > </fo:block> > </fo:table-cell> > </fo:table-row> > </fo:table-body> > </fo:table> > </fo:flow> > </fo:page-sequence> > </fo:root> > > FILE 2 - tiffFopConfig.xml > <fop version="1.0"> > <renderer mime="image/tiff"> > <compression>CCITT T.6</compression> > </renderer> > </fop> > > FILE 3 - FopTiffTester.java > import java.io.BufferedOutputStream; > import java.io.File; > import java.io.FileOutputStream; > import java.io.OutputStream; > import java.io.StringReader; > import java.net.URL; > > import javax.xml.transform.Source; > import javax.xml.transform.Transformer; > import javax.xml.transform.TransformerFactory; > import javax.xml.transform.sax.SAXResult; > import javax.xml.transform.stream.StreamSource; > > import org.apache.avalon.framework.configuration.Configuration; > import > org.apache.avalon.framework.configuration.DefaultConfigurationBuilder; > import org.apache.commons.io.FileUtils; > import org.apache.fop.apps.FOUserAgent; > import org.apache.fop.apps.Fop; > import org.apache.fop.apps.FopFactory; > import org.apache.fop.apps.MimeConstants; > import org.apache.log4j.helpers.Loader; > > public class FopTiffTester { > > public FopTiffTester() {} > > public static void main(String[] args) { > > try { > > // Load the File Objects > File testPath = new File("C:\\test\\foptifftest\\"); > testPath.mkdirs(); > File fopFile = new File(testPath, "testFop.xsl"); > File tiffFile = new File(testPath, > String.valueOf(System.currentTimeMillis()) + ".tiff"); > > // Read FOP File to String > String fopString = FileUtils.readFileToString(fopFile); > > // Get Fop Factory and Configure > FopFactory fopFactory = FopFactory.newInstance(); > URL configUrl = > Loader.getResource("tiffFopConfig.xml"); > DefaultConfigurationBuilder cfgBuilder = new > DefaultConfigurationBuilder(); > Configuration cfg = > cfgBuilder.build(configUrl.openStream()); > fopFactory.setUserConfig(cfg); > > // Generate Fop User Agent and Configure > FOUserAgent fopAgent = > fopFactory.newFOUserAgent(); > fopAgent.setTargetResolution(200); > > // Transform Fop to Tiff > OutputStream outStream = new > BufferedOutputStream(new FileOutputStream(tiffFile)); > Fop fop = > fopFactory.newFop(MimeConstants.MIME_TIFF, fopAgent, outStream); > Transformer transformer = > TransformerFactory.newInstance().newTransformer(); > transformer.transform((Source)new > StreamSource(new StringReader(fopString)), new > SAXResult(fop.getDefaultHandler())); > outStream.close(); > > } catch (Exception ex) { > ex.printStackTrace(); > } > } > } > > ----------------------------------------- > The information in this message may be proprietary and/or > confidential, and protected from disclosure. If the reader of this > message is not the intended recipient, or an employee or agent > responsible for delivering this message to the intended recipient, > you are hereby notified that any dissemination, distribution or > copying of this communication is strictly prohibited. If you have > received this communication in error, please notify First Data > immediately by replying to this message and deleting it from your > computer. > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > Jeremias Maerki --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
