You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Alvaro Moraleda <al...@gmail.com> on 2009/04/22 16:55:31 UTC
transform to PDF
Hi everyone!
I'm working with xerces to transform XML to PDF using a XSL file. I
have the following XML:
<comment content=" blablablabla
blablablabla" />
(The field "content" is written by an user of my application)
When I try to transform the XML to PDF the newline doesn't appears.
Do I miss something?
Thanks!
This is my java code:
try {
// configure fopFactory as desired
FopFactory fopFactory = FopFactory.newInstance();
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
// Setup output
OutputStream out = new java.io.FileOutputStream(pdfFile);
out = new java.io.BufferedOutputStream(out);
try {
// Construct fop with desired output format
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);
// Setup XSLT
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(new
StreamSource(xsltfile));
// Set the value of a <param> in the stylesheet
transformer.setParameter("versionParam", "2.0");
// Setup input for XSLT transformation
Source src = new StreamSource(xmlPath);
// 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(src, res);
} finally {
out.close();
}
} catch (Exception e) {
e.printStackTrace(System.err);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org
Re:
transform to PDF
Posted by Alvaro Moraleda <al...@gmail.com>.
You'r right. I'm sorry!
2009/4/22 Michael Glavassevich <mr...@ca.ibm.com>:
> Good question, except that you're not asking it in the right forum. Xerces
> doesn't "transform XML to PDF using a XSL file". Looks like you're using FOP
> [1] and also perhaps Xalan is involved in the transform. I'd suggest you ask
> this question on the FOP user mailing list.
>
> Thanks.
>
> [1] http://xmlgraphics.apache.org/fop/
>
> Michael Glavassevich
> XML Parser Development
> IBM Toronto Lab
> E-mail: mrglavas@ca.ibm.com
> E-mail: mrglavas@apache.org
>
> Alvaro Moraleda <al...@gmail.com> wrote on 04/22/2009 10:55:31 AM:
>
>> Hi everyone!
>> I'm working with xerces to transform XML to PDF using a XSL file. I
>> have the following XML:
>>
>> <comment content=" blablablabla
blablablabla" />
>>
>>
>> (The field "content" is written by an user of my application)
>>
>> When I try to transform the XML to PDF the newline doesn't appears.
>> Do I miss something?
>>
>> Thanks!
>>
>> This is my java code:
>>
>> try {
>> // configure fopFactory as desired
>> FopFactory fopFactory = FopFactory.newInstance();
>> FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
>>
>> // Setup output
>> OutputStream out = new java.io.FileOutputStream(pdfFile);
>>
>> out = new java.io.BufferedOutputStream(out);
>>
>> try {
>> // Construct fop with desired output format
>> Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF,
>> foUserAgent, out);
>>
>> // Setup XSLT
>> TransformerFactory factory = TransformerFactory.newInstance();
>> Transformer transformer = factory.newTransformer(new
>> StreamSource(xsltfile));
>>
>> // Set the value of a <param> in the stylesheet
>> transformer.setParameter("versionParam", "2.0");
>>
>> // Setup input for XSLT transformation
>> Source src = new StreamSource(xmlPath);
>>
>> // 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(src, res);
>>
>> } finally {
>> out.close();
>> }
>>
>> } catch (Exception e) {
>> e.printStackTrace(System.err);
>> }
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
>> For additional commands, e-mail: j-users-help@xerces.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org
Re:
transform to PDF
Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Good question, except that you're not asking it in the right forum. Xerces
doesn't "transform XML to PDF using a XSL file". Looks like you're using
FOP [1] and also perhaps Xalan is involved in the transform. I'd suggest
you ask this question on the FOP user mailing list.
Thanks.
[1] http://xmlgraphics.apache.org/fop/
Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org
Alvaro Moraleda <al...@gmail.com> wrote on 04/22/2009 10:55:31
AM:
> Hi everyone!
> I'm working with xerces to transform XML to PDF using a XSL file. I
> have the following XML:
>
> <comment content=" blablablabla
blablablabla" />
>
>
> (The field "content" is written by an user of my application)
>
> When I try to transform the XML to PDF the newline doesn't appears.
> Do I miss something?
>
> Thanks!
>
> This is my java code:
>
> try {
> // configure fopFactory as desired
> FopFactory fopFactory = FopFactory.newInstance();
> FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
>
> // Setup output
> OutputStream out = new java.io.FileOutputStream(pdfFile);
>
> out = new java.io.BufferedOutputStream(out);
>
> try {
> // Construct fop with desired output format
> Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF,
> foUserAgent, out);
>
> // Setup XSLT
> TransformerFactory factory =
TransformerFactory.newInstance();
> Transformer transformer = factory.newTransformer(new
> StreamSource(xsltfile));
>
> // Set the value of a <param> in the stylesheet
> transformer.setParameter("versionParam", "2.0");
>
> // Setup input for XSLT transformation
> Source src = new StreamSource(xmlPath);
>
> // 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(src, res);
>
> } finally {
> out.close();
> }
>
> } catch (Exception e) {
> e.printStackTrace(System.err);
> }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org