You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by "Marquart, Joshua D" <jo...@firstdata.com> on 2010/07/14 00:48:13 UTC

XML to TIFF CITT conversion - aid requested

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: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


RE: XML to TIFF CITT conversion - aid requested

Posted by "Marquart, Joshua D" <jo...@firstdata.com>.
As I noted in my original post, I'd follow-up with any findings.

In my research (I walked through TIFFRendererConfigurator) I discovered
the reason the following suggested in-line code was not working

FOUserAgent ua = fopFactory.newFOUserAgent(); 
TIFFRenderer renderer = new TIFFRenderer(); 
renderer.setUserAgent(ua);
renderer.getWriterParams().setCompressionMethod(TIFFConstants.COMPRESSIO
N_CCITT_T6);
ua.setRendererOverride(renderer);

It is missing the following line after setUserAgent()
renderer.setBufferedImageType(BufferedImage.TYPE_BYTE_BINARY);

SIDE-EFFECT NOTE: If you call on a Renderer which extends Java2DRenderer
you don't need to call
  ua.setRenfererOverride(renderer)
as this is side-effect called in renderer.setUserAgent(ua)

Hope this helps anyone who reads this going forward.

-Josh

-----------------------------------------
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: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: XML to TIFF CITT conversion - aid requested

Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
Joshua,

I've just played this through:
- Extracted FOP 0.95 binary distribution.
- Ran fop.bat -fo examples/fo/basic/simple.fo -tiff simple.tiff
    --> I get an RGB TIFF with RLE compression, 32bit IDE incl. alpha
- Copied jai_imageio.jar (1.1) to the lib directory.
- Created the following userconfig.xml:

<?xml version="1.0" encoding="UTF-8"?>
<fop>
  <renderers>
    <renderer mime="image/tiff">
      <compression>CCITT T.6</compression>
    </renderer>
  </renderers>
</fop>

- Ran fop.bat -c userconfig.xml -fo examples/fo/basic/simple.fo -tiff simple.tiff
    --> Results in a bi-level TIFF with CCITT Group 4 compression

I can't peek into your environment, but essentially, you need
jai_imageio.jar in the classpath (preferrably on the same level as
fop.jar so the META-INF/services mechanism works properly) and then
activate CCITT compression via some means (config file, option via Java
code etc.).

What you can also try is copy the jai_imageio.jar into your JRE's
lib/ext directory which makes it available on a really low level, almost
certainly avoiding any classloader trouble.

In the end, when something doesn't work, go back to the minimal case and
work back to bigger complexity when the minimal case works.

Good luck.

On 19.07.2010 19:46:06 Marquart, Joshua D wrote:
> "I updated everything to the latest JAR and am still getting the above
> compression exception."
> 
> What's meant by this is that I even moved to Fop .95 to check (per the
> jar list that followed where I note .95 as the version) and am still
> getting the problem.  I'm curious if other can replicate it, or if my
> system is unique, or if possibly I am missing something.
> 
> Beyond the JAI Tools jar, does there have to be an alteration to the JRE
> in use, as with a JAI deployment?
> 
> -Josh
> 


Jeremias Maerki


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


RE: XML to TIFF CITT conversion - aid requested

Posted by "Marquart, Joshua D" <jo...@firstdata.com>.
"I updated everything to the latest JAR and am still getting the above
compression exception."

What's meant by this is that I even moved to Fop .95 to check (per the
jar list that followed where I note .95 as the version) and am still
getting the problem.  I'm curious if other can replicate it, or if my
system is unique, or if possibly I am missing something.

Beyond the JAI Tools jar, does there have to be an alteration to the JRE
in use, as with a JAI deployment?

-Josh

-----------------------------------------
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: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


RE: XML to TIFF CITT conversion - aid requested

Posted by "Marquart, Joshua D" <jo...@firstdata.com>.
Hi Jeremias,

I've changed the app as follows.

Apparently JAI Tools JAR gets ignored because I'm using xmlgraphics 1.2,
which is bundled with fop 94.

I updated to xmlgraphics 1.4 and kept the same fop .94, and I'm getting
the compression exception mentioned in the other e-mail:

javax.imageio.IIOException: Bits per sample must be 1 for T6
compression!

I updated everything to the latest JAR and am still getting the above
compression exception.  

From what I can tell by viewing the source of the JAI Tools code, if the
bits per sample array in the write function of TIFFT6Compressor isn't
length 1 containing a value of 1 (which is appropriate for a Group 4
compression tiff), it throws.

Bits per sample array size is set by the numBands calculated in IO Tools
TIFFImageWriter, which is determined by the samplemodel and the
colormodel.
 
Bits per sample value (1 is needed) is set by the bitDepth, calculated
in same, which since it needs to be 1, is determined by sampleSize[0],
which is also set by samplemodel.getSampleSize()

Since I see attachments work well in this mailing list, I'm attaching my
latest JAVA file and FOP-formatted XSL file.  Maybe my resulting xml is
overkill in some way, causing an unexpectedly high value in samplemodel?
 
I'm going to investigate further and see how the sampleModel is being
set within the code and what values it received, but while I'm still
researching, any advice would be greatly appreciated.

Worst case on this, I'll end up trying to create a Graphics2D and using
JAI Tools to create the TIFF (I'll make sure to post the code as a
follow-up), or go back to our old way of generating a PostScript from
FOP and using a third party tool to convert it to TIFF (a tactic I am
trying to avoid).
 
Also, semi-topical since it concerns TIFF conversion and since you're
the one who made the fix, would you happen to know if the
multi-threading issue with with Java2D renderer (Revision 895012) is
resolved with xmlgraphics 1.4, or if that is still unreleased; I'm still
getting up to speed on how /  whether some specific revisions/fixes are
applied to releases.

Much Thanks,

Josh (JAR LIST FOLLOWS)

JAR LIST
jai_imageio.jar (1.1)
avalon-framework-4.2.0.jar
batik-all-1.6.jar
commons-logging-1.0.4.jar
fop.jar (.95)
serializer-2.7.0.jar
xalan-2.7.0.jar
xercesImpl-2.7.1.jar
xml-apis-1.3.02.jar
log4j-1.2.13.jar
commons-io-1.4.jar
xmlgraphics-commons-1.4.jar





-----------------------------------------
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. 

Re: XML to TIFF CITT conversion - aid requested

Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
Hi Josh

You've had JAI ImageIO Tools on the list on your first post, but yes, if
the internal TIFFImageWriter is activated (which does not support CCITT
compression, yet), that means the ImageIO implementation fell through.
I'd double-check the classpath.

On 14.07.2010 15:33:13 Marquart, Joshua D wrote:
> Hi Jeremias,
> 
> I've applied your change and now it proceeds, but I receive the
> following exception:
> 
> java.lang.UnsupportedOperationException: Compression method not
> supported: CCITT T.6
> 	at
> org.apache.xmlgraphics.image.writer.internal.TIFFImageWriter.createTIFFE
> ncodeParams(TIFFImageWriter.java:75)
> 	at
> org.apache.xmlgraphics.image.writer.internal.TIFFImageWriter.access$000(
> TIFFImageWriter.java:41)
> 	at
> org.apache.xmlgraphics.image.writer.internal.TIFFImageWriter$TIFFMultiIm
> ageWriter.writeImage(TIFFImageWriter.java:135)
> 	at
> org.apache.fop.render.bitmap.TIFFRenderer.stopRenderer(TIFFRenderer.java
> :140)
> 
> Maybe I missed something with the JAI Tools jar?
> I'll take a look at the source as well and see what's supposed to
> happen.
> 
> -Josh
> 



Jeremias Maerki


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


RE: XML to TIFF CITT conversion - aid requested

Posted by "Marquart, Joshua D" <jo...@firstdata.com>.
Hi Jeremias,

I've applied your change and now it proceeds, but I receive the
following exception:

java.lang.UnsupportedOperationException: Compression method not
supported: CCITT T.6
	at
org.apache.xmlgraphics.image.writer.internal.TIFFImageWriter.createTIFFE
ncodeParams(TIFFImageWriter.java:75)
	at
org.apache.xmlgraphics.image.writer.internal.TIFFImageWriter.access$000(
TIFFImageWriter.java:41)
	at
org.apache.xmlgraphics.image.writer.internal.TIFFImageWriter$TIFFMultiIm
ageWriter.writeImage(TIFFImageWriter.java:135)
	at
org.apache.fop.render.bitmap.TIFFRenderer.stopRenderer(TIFFRenderer.java
:140)

Maybe I missed something with the JAI Tools jar?
I'll take a look at the source as well and see what's supposed to
happen.

-Josh

-----------------------------------------
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: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


RE: XML to TIFF CITT conversion - aid requested

Posted by "Marquart, Joshua D" <jo...@firstdata.com>.
I've changed to using Xml Graphics 1.4 (from 1.2, which is bundled with
fop94) and I get a different exception (entirety is post-sig).

javax.xml.transform.TransformerException: javax.imageio.IIOException:
I/O error writing TIFF file!
...
Caused by: javax.imageio.IIOException: Bits per sample must be 1 for T6
compression!
  at
com.sun.media.imageioimpl.plugins.tiff.TIFFT6Compressor.encode(TIFFT6Com
pressor.java:178)
  at
com.sun.media.imageioimpl.plugins.tiff.TIFFImageWriter.writeTile(TIFFIma
geWriter.java:2309)
  at
com.sun.media.imageioimpl.plugins.tiff.TIFFImageWriter.write(TIFFImageWr
iter.java:2686)

I'll see about updating to fop95.jar

-Josh

javax.xml.transform.TransformerException: javax.imageio.IIOException:
I/O error writing TIFF file!
  at
org.apache.xalan.transformer.TransformerIdentityImpl.transform(Transform
erIdentityImpl.java:501)
  at FopTiffTester.main(FopTiffTester.java:61)
Caused by: javax.imageio.IIOException: I/O error writing TIFF file!
  at
org.apache.fop.area.RenderPagesModel.endDocument(RenderPagesModel.java:2
47)
  at
org.apache.fop.area.AreaTreeHandler.endDocument(AreaTreeHandler.java:283
)
  at org.apache.fop.fo.FOTreeBuilder.endDocument(FOTreeBuilder.java:171)
  at
org.apache.xalan.transformer.TransformerIdentityImpl.endDocument(Transfo
rmerIdentityImpl.java:962)
  at org.apache.xerces.parsers.AbstractSAXParser.endDocument(Unknown
Source)
  at org.apache.xerces.impl.XMLDocumentScannerImpl.endEntity(Unknown
Source)
  at org.apache.xerces.impl.XMLEntityManager.endEntity(Unknown Source)
  at org.apache.xerces.impl.XMLEntityScanner.load(Unknown Source)
  at org.apache.xerces.impl.XMLEntityScanner.skipSpaces(Unknown Source)
  at
org.apache.xerces.impl.XMLDocumentScannerImpl$TrailingMiscDispatcher.dis
patch(Unknown Source)
  at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unkno
wn Source)
  at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
  at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
  at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
  at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
  at
org.apache.xalan.transformer.TransformerIdentityImpl.transform(Transform
erIdentityImpl.java:484)
  ... 1 more
---------
javax.imageio.IIOException: I/O error writing TIFF file!
  at
org.apache.fop.area.RenderPagesModel.endDocument(RenderPagesModel.java:2
47)
  at
org.apache.fop.area.AreaTreeHandler.endDocument(AreaTreeHandler.java:283
)
  at org.apache.fop.fo.FOTreeBuilder.endDocument(FOTreeBuilder.java:171)
  at
org.apache.xalan.transformer.TransformerIdentityImpl.endDocument(Transfo
rmerIdentityImpl.java:962)
  at org.apache.xerces.parsers.AbstractSAXParser.endDocument(Unknown
Source)
  at org.apache.xerces.impl.XMLDocumentScannerImpl.endEntity(Unknown
Source)
  at org.apache.xerces.impl.XMLEntityManager.endEntity(Unknown Source)
  at org.apache.xerces.impl.XMLEntityScanner.load(Unknown Source)
  at org.apache.xerces.impl.XMLEntityScanner.skipSpaces(Unknown Source)
  at
org.apache.xerces.impl.XMLDocumentScannerImpl$TrailingMiscDispatcher.dis
patch(Unknown Source)
  at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unkno
wn Source)
  at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
  at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
  at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
  at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
  at
org.apache.xalan.transformer.TransformerIdentityImpl.transform(Transform
erIdentityImpl.java:484)
  at FopTiffTester.main(FopTiffTester.java:61)
---------
javax.imageio.IIOException: I/O error writing TIFF file!
  at
com.sun.media.imageioimpl.plugins.tiff.TIFFImageWriter.write(TIFFImageWr
iter.java:2706)
  at
com.sun.media.imageioimpl.plugins.tiff.TIFFImageWriter.insert(TIFFImageW
riter.java:2903)
  at
com.sun.media.imageioimpl.plugins.tiff.TIFFImageWriter.writeInsert(TIFFI
mageWriter.java:2862)
  at
com.sun.media.imageioimpl.plugins.tiff.TIFFImageWriter.writeToSequence(T
IFFImageWriter.java:2754)
  at
org.apache.xmlgraphics.image.writer.imageio.ImageIOImageWriter$IIOMultiI
mageWriter.writeImage(ImageIOImageWriter.java:277)
  at
org.apache.fop.render.bitmap.TIFFRenderer.stopRenderer(TIFFRenderer.java
:140)
  at
org.apache.fop.area.RenderPagesModel.endDocument(RenderPagesModel.java:2
45)
  at
org.apache.fop.area.AreaTreeHandler.endDocument(AreaTreeHandler.java:283
)
  at org.apache.fop.fo.FOTreeBuilder.endDocument(FOTreeBuilder.java:171)
  at
org.apache.xalan.transformer.TransformerIdentityImpl.endDocument(Transfo
rmerIdentityImpl.java:962)
  at org.apache.xerces.parsers.AbstractSAXParser.endDocument(Unknown
Source)
  at org.apache.xerces.impl.XMLDocumentScannerImpl.endEntity(Unknown
Source)
  at org.apache.xerces.impl.XMLEntityManager.endEntity(Unknown Source)
  at org.apache.xerces.impl.XMLEntityScanner.load(Unknown Source)
  at org.apache.xerces.impl.XMLEntityScanner.skipSpaces(Unknown Source)
  at
org.apache.xerces.impl.XMLDocumentScannerImpl$TrailingMiscDispatcher.dis
patch(Unknown Source)
  at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unkno
wn Source)
  at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
  at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
  at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
  at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
  at
org.apache.xalan.transformer.TransformerIdentityImpl.transform(Transform
erIdentityImpl.java:484)
  at FopTiffTester.main(FopTiffTester.java:61)
Caused by: javax.imageio.IIOException: Bits per sample must be 1 for T6
compression!
  at
com.sun.media.imageioimpl.plugins.tiff.TIFFT6Compressor.encode(TIFFT6Com
pressor.java:178)
  at
com.sun.media.imageioimpl.plugins.tiff.TIFFImageWriter.writeTile(TIFFIma
geWriter.java:2309)
  at
com.sun.media.imageioimpl.plugins.tiff.TIFFImageWriter.write(TIFFImageWr
iter.java:2686)
  ... 22 more

-----------------------------------------
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: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


RE: XML to TIFF CITT conversion - aid requested

Posted by "Marquart, Joshua D" <jo...@firstdata.com>.
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:dev@jeremias-maerki.ch] 
Sent: Wednesday, July 14, 2010 2:49 AM
To: fop-users@xmlgraphics.apache.org
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: fop-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
> 




Jeremias Maerki



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: XML to TIFF CITT conversion - aid requested

Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
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.COMPRESSION_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: fop-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
> 




Jeremias Maerki


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org