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 Ralph Soika <ra...@imixs.com> on 2011/04/14 20:33:42 UTC
PDF File content ist not visible
Hi,
I have a strange problem with FOP PDF creation.
In general everything looks fine. But I try to provide REST Service to
create pdf files.
The result seems to work but the File which is provided by my
ResponseBuild consits only of blank pages?
Also when I try to write the result into a file the file seems to have
the right size and is regogniced as a pdf file but the pages are blank.
Has anybody a idea what I did wrong?
My JAX-RS Code looks like this..
....
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
ReportService.fopTranformation(sXML, sXSL,
outputStream.flush();
Response.ResponseBuilder builder =
Response.ok(outputStream.toString(encoding),
sContentType);
} finally {
outputStream.close();
return builder.build();
......
......
public static void fopTranformation(String xmlSource, String
xslSource,
String aEncoding, ByteArrayOutputStream output) throws
Exception {
// configure fopFactory as desired
FopFactory fopFactory = FopFactory.newInstance();
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
// configure foUserAgent as desired
try {
// Construct fop with desired output format
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF,
foUserAgent,
output);
// Setup XSLT
TransformerFactory factory = TransformerFactory.newInstance();
ByteArrayInputStream baisXSL = new ByteArrayInputStream(
xslSource.getBytes());
InputStreamReader isreaderXSL = new InputStreamReader(baisXSL,
aEncoding);
Source xslSrc = new StreamSource(isreaderXSL);
Transformer transformer = factory.newTransformer(xslSrc);
// Setup input for XSLT transformation
ByteArrayInputStream baisXML = new ByteArrayInputStream(
xmlSource.getBytes());
InputStreamReader isreaderXML;
isreaderXML = new InputStreamReader(baisXML, aEncoding);
Source xmlSrc = new StreamSource(isreaderXML);
// Resulting SAX events (the generated FO) must be piped
through to
// FOP
Result res = new SAXResult(fop.getDefaultHandler());
// Start XSLT transformation and FOP processing
transformer.transform(xmlSrc, res);
} finally {
output.flush();
output.close();
}
}
--
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
Re: PDF File content ist not visible
Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
If you're working with JAX-RS, I think you actually left out the
critical parts, namely the full request method including the annotations.
That makes it difficult to help. I'm pretty sure that the PDF is
produced properly, but something goes wrong in the communication between
the browser and the server. If you stream the PDF over HTTPS, you might
want to take a look at this:
http://xmlgraphics.apache.org/fop/trunk/servlets.html#ie
What applies to servlet may easily apply to JAX-RS, too.
On 14.04.2011 20:33:42 Ralph Soika wrote:
> Hi,
> I have a strange problem with FOP PDF creation.
> In general everything looks fine. But I try to provide REST Service to
> create pdf files.
> The result seems to work but the File which is provided by my
> ResponseBuild consits only of blank pages?
> Also when I try to write the result into a file the file seems to have
> the right size and is regogniced as a pdf file but the pages are blank.
> Has anybody a idea what I did wrong?
>
> My JAX-RS Code looks like this..
> ....
> ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
> try {
>
> ReportService.fopTranformation(sXML, sXSL,
> outputStream.flush();
> Response.ResponseBuilder builder =
> Response.ok(outputStream.toString(encoding),
> sContentType);
>
> } finally {
> outputStream.close();
>
> return builder.build();
> ......
> ......
>
>
> public static void fopTranformation(String xmlSource, String
> xslSource,
> String aEncoding, ByteArrayOutputStream output) throws
> Exception {
> // configure fopFactory as desired
> FopFactory fopFactory = FopFactory.newInstance();
>
> FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
> // configure foUserAgent as desired
>
> try {
> // Construct fop with desired output format
>
> Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF,
> foUserAgent,
> output);
>
> // Setup XSLT
> TransformerFactory factory = TransformerFactory.newInstance();
> ByteArrayInputStream baisXSL = new ByteArrayInputStream(
> xslSource.getBytes());
> InputStreamReader isreaderXSL = new InputStreamReader(baisXSL,
> aEncoding);
> Source xslSrc = new StreamSource(isreaderXSL);
>
> Transformer transformer = factory.newTransformer(xslSrc);
>
> // Setup input for XSLT transformation
> ByteArrayInputStream baisXML = new ByteArrayInputStream(
> xmlSource.getBytes());
> InputStreamReader isreaderXML;
>
> isreaderXML = new InputStreamReader(baisXML, aEncoding);
>
> Source xmlSrc = new StreamSource(isreaderXML);
>
> // Resulting SAX events (the generated FO) must be piped
> through to
> // FOP
> Result res = new SAXResult(fop.getDefaultHandler());
>
> // Start XSLT transformation and FOP processing
> transformer.transform(xmlSrc, res);
> } finally {
> output.flush();
> output.close();
> }
> }
> --
Jeremias Maerki
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org