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 andrew mercer <an...@sundayta.com> on 2003/03/13 17:33:16 UTC
Printing using Java
Hi,
I have only just started using fop and need to print the final output
automatically from within my java code.
I notice from the users mailing list that questions have been raised
before (eg: 'Printing from FOP Driver' dated 2002-06-02 and 'Printing
from Java-Application' 2002-04-16) but not answered.
I have the same questions, ie how to overcome the exception and are
there memory concerns.
I have tried printing from the command line using ...Fop -print ... and
have noticed that the positioning of the data is different to when I
output the same file to pdf and then print the pdf.
Does this suggest that the I have to set the layout differently for each
style of output?
Thanks Andrew
--
Andrew Mercer, Sundayta Ltd. http://www.sundayta.com
iDocSys for Document Management. VisibleResults for Fundraising.
Development and Hosting of Web Applications and Sites.
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-user-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-user-help@xml.apache.org
Re: Printing using Java
Posted by Clay Leeds <cl...@medata.com>.
Andrew,
I too have noticed a difference when I use -print and when I output to a
file using -pdf. The primary differences I've found relate to VERTICAL
FontMetrics. In other words, in the PDF version, the region-before and
region-after sections appear larger than necessary. The percentage
difference ranges from 112% larger to 150% larger (it appears to be
almost exponential, generally depending on how large the region-before
or region-after is). I think it has to do with postscript rendering
differences, as I've moticed the same problem when I render to -ps. In
addition, if I send it to -print, but specify Acrobat PDFWriter or
Acrobat Distiller, I notice the same problem.
What follows is not exactly a "fix" but instead is more of a
work-around. My work-around is to have two versions of my FO files: a
"print" version and a "pdf" version. Then, since I call FOP using either
a script (*.BAT file for Win or a *.sh for Unix), I merely specify a
different script depending on the output method. Since I'd rather not
have to modify two files when making changes, the "pdf" version is
fairly short and instead does an <xsl:include> of the print version.
After the xsl:include line, I set the following:
- xsl:attributes
- fo:root
- fo:layout-master-set
- fo:simple-page-master
- fo:region-body
- fo:region-before
- fo_region-after
- fo:page-sequence-master
- repeatable-page-master-reference
- single-page-master-reference
- fo:page-sequence
- fo:static-content
- fo:static-content
- fo:flow
Here's the actual code (I removed a bunch of comments and xsl:if &
choose statements to improve readability--if you find I haven't closed a
tag that's why--the unmodified version works ;-).
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:include href="xml_med7_default.fo"/>
<xsl:attribute-set name="attNormal">
<xsl:attribute name="background-color">#ffffff</xsl:attribute>
<xsl:attribute name="color">#000000</xsl:attribute>
<xsl:attribute name="font-family">courier new, courier,
monospace</xsl:attribute>
<xsl:attribute name="font-size">8pt</xsl:attribute>
</xsl:attribute-set>
<xsl:variable name="varNormalBGColor">#ffffff</xsl:variable>
<xsl:variable name="varHeadingBGColor">#dddddd</xsl:variable>
<xsl:variable name="varAccentBGColor">#ccffff</xsl:variable>
<xsl:variable name="varWIWCHeading2BGColor">#999999</xsl:variable>
<xsl:variable name="varHeadingFontSize">9pt</xsl:variable>
<xsl:template match="/">
<xsl:apply-templates select="doc"/>
</xsl:template>
<xsl:template match="doc">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="repeating"
page-height="28cm" page-width="22cm" margin-top="1cm"
margin-bottom="1cm" margin-left="1cm" margin-right="0cm">
<fo:region-body margin-bottom="2.6cm" margin-top="6.4cm"/>
<fo:region-before extent="6.4cm"/>
<fo:region-after extent="2.6cm"/>
</fo:simple-page-master>
<fo:simple-page-master master-name="refundletter"
page-height="28cm" page-width="22cm" margin-top="1cm"
margin-bottom="1cm" margin-left="1cm" margin-right="1cm">
<fo:region-body region-name="refundletter"/>
</fo:simple-page-master>
<fo:page-sequence-master master-name="repeating_pm">
<fo:repeatable-page-master-reference master-name="repeating"/>
<fo:single-page-master-reference
master-reference="refundletter"/>
</fo:page-sequence-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="repeating">
<fo:static-content flow-name="xsl-region-before">
<fo:block padding="0pt" xsl:use-attribute-sets="attNormal">
<xsl:call-template name="tmpHeader"/>
</fo:block>
</fo:static-content>
<fo:static-content flow-name="xsl-region-after">
<fo:block xsl:use-attribute-sets="attNormal">
<xsl:call-template name="tmpFooter"/>
</fo:block>
</fo:static-content>
<fo:flow flow-name="xsl-region-body">
<fo:block xsl:use-attribute-sets="attNormal">
<xsl:call-template name="tmpBody"/>
<fo:block padding="0pt" font-size="1pt">
<fo:marker marker-class-name="table-continued"/>
</fo:block>
</fo:block>
</fo:flow>
</fo:page-sequence>
<fo:page-sequence master-reference="refundletter">
<fo:flow flow-name="refundletter">
<fo:block xsl:use-attribute-sets="attNormal">
<xsl:call-template name="tmpRefundLetter"/>
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
</xsl:stylesheet>
BTW, you may notice that I've placed all of my content for each
fo:page-sequence item in a template. I found this makes it easier for me
to make modifications to margins, etc. You may also notice my
"table-continued" marker at the end of the fo:flow which I use for a
"Continued on next page" marker on every page except the last.
I hope you find this useful.
--
Clay Leeds - cleeds@medata.com
Web Developer - Medata, Inc. - http://www.medata.com
PGP Public Key: https://mail.medata.com/pgp/cleeds.asc
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-user-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-user-help@xml.apache.org
Re: Printing using Java
Posted by Ralf Butterweck <ra...@ubh.de>.
Hi,
I have the some problem that fop produces different outputs
by writing a pdf-file, 'fop -print' or 'printing -pcl'
My workaround is to let fop produce a pdf-file and then print
this file (The variable outfile contains the name of the pdf-file):
Windows NT:
Runtime.getRuntime().exec("cmd /C AcroRd32.exe /p /h "+outfile);
Linux:
Runtime.getRuntime().exec("lp -d printer1 "+outfile);
If someone knows a better way (Windows or Linux) to print a pdf-file
from a Java-Application, please let me know.
Or knows someone a 'PDF Printer service' so the Java Print API
(javax.print.*) can be used?
Ralf
>Date sent: Thu, 13 Mar 2003 16:33:16 +0000
>From: andrew mercer <an...@sundayta.com>
>Subject: Printing using Java
>To: fop-user@xml.apache.org
>Send reply to: fop-user@xml.apache.org
>
> Hi,
>
> I have only just started using fop and need to print the final output
> automatically from within my java code.
>
> I notice from the users mailing list that questions have been raised
> before (eg: 'Printing from FOP Driver' dated 2002-06-02 and 'Printing
> from Java-Application' 2002-04-16) but not answered.
>
> I have the same questions, ie how to overcome the exception and are
> there memory concerns.
>
> I have tried printing from the command line using ...Fop -print ... and
> have noticed that the positioning of the data is different to when I
> output the same file to pdf and then print the pdf.
>
> Does this suggest that the I have to set the layout differently for each style
> of output?
>
> Thanks Andrew
> --
>
>
> Andrew Mercer, Sundayta Ltd. http://www.sundayta.com
> iDocSys for Document Management. VisibleResults for Fundraising.
> Development and Hosting of Web Applications and Sites.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: fop-user-help@xml.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-user-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-user-help@xml.apache.org