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 David J <da...@columbiaultimate.com> on 2008/04/17 19:20:30 UTC
Direct Printing and setting print parameters in FOP 0.94
We are upgrading to FOP 0.94 from 0.20.5 (on Java 1.5). I am new to java
printing in general, so any help in pointing me to the solution is greatly
appreciated.
My goal is to print directly to a printer from my java program (I have
already generated an FO document) with printer parameters that have already
been set up (so no user interaction for this process).
We had the following code working in FOP 0.20.5:
/**
* Renders and prints a source XSL-FO document to specified print job
*/
public static void print(InputSource source, DocPrintJob job,
PrintRequestAttributeSet pras)
throws AjentException {
if (job != null) {
AWTRenderer renderer = new AWTRenderer(null);
render(source, renderer);
try {
Doc doc = new SimpleDoc(renderer,
DocFlavor.SERVICE_FORMATTED.PAGEABLE, null);
job.print(doc, pras);
} catch (PrintException e) {
...
}
}
}
/**
* Render a source XSL-FO document using specified renderer
*/
public static void render(InputSource source, Renderer renderer) throws
AjentException {
Driver driver = new Driver();
driver.setInputSource(source);
driver.setRenderer(renderer);
try {
driver.run();
} catch (IOException e) {
…
} catch (FOPException e) {
...
}
}
I want to do something similar in 0.94 (directly print with my settings). I
have looked at the ExampleFO2OldStylePrint example on the FOP site, however,
I cannot figure out how to set the printer properties that I was setting
before. (Printer and printer tray are the main properties).
I realize that I will be complete changing this for 0.94, however, an
example of setting printer options to print directly in the new API would be
greatly appreciated.
Thanks for any help or direction on this.
David J
Columbia Ultimate
--
View this message in context: http://www.nabble.com/Direct-Printing-and-setting-print-parameters-in-FOP-0.94-tp16747594p16747594.html
Sent from the FOP - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
Re: Direct Printing and setting print parameters in FOP 0.94
Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
I'm not aware of any problems in that area. FOP should pick up
automatically all fonts installed in your operating system for direct
print. You say you found "Arial Negreta cursiva" in the used fonts. How
do you specify the fonts in FO? Do you use the localized font names?
That could explain the problems as we're currently guessing "bold" and
"italic" font variants by the English tags. "Negreta" and "cursiva" will
probably not be recognized as font style modifiers. So basically, your
question is the right one: How to configure fonts?
Basically the same way as for the other output formats. See:
http://xmlgraphics.apache.org/fop/trunk/fonts.html#basics
http://xmlgraphics.apache.org/fop/trunk/fonts.html#register
You just need to add a <fonts> tag with the right children under the
section for the "application/X-fop-print" renderer. Something like this:
<fop>
[..]
<renderers>
[..]
<renderer mime="application/X-fop-print">
<fonts>
<directory recursive="true">D:/Install/fonts/dejavu-ttf-2.5</directory>
<font embed-url="test\resources\fonts\glb12.ttf">
<font-triplet name="Gladiator" style="normal" weight="normal"/>
</font>
</fonts>
</renderer>
</renderers>
</fop>
Note: I haven't tested this. And the fonts will most probably be
registered under their English names unless you use the <font> tag as
shown above where you can specify the font names yourself.
HTH
On 18.02.2009 21:21:13 tanya C wrote:
>
>
> Jeremias Maerki-2 wrote:
> >
> > The best approach was to create a new renderer: PageableRenderer. This
> > should only implement Pageable and provide the from/to and odd/even
> > functionality that the PrintRenderer offers. PrintRenderer can then
> > be derived from the PageableRenderer while preserving its original
> > behaviour.
> >
> > This can now be found in FOP Trunk. I've added a minimal example, too:
> > http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleFO2JPSPrint.java?view=markup
> >
> > I'll be grateful for feedback on this as I don't have a real-life
> > use-case for this, unfortunately, in which I could test this. It was
> > simply fun to implement. ;-) HTH
> >
> >
>
> I used your example to send the form directly to the printer. I checked out
> FOP Trunk and build the fop.jar which I used for my test. It works with the
> minor issue of the font, which I can't figure out how to fix. The form uses
> Arial font with bold, normal, and italic style, but when it is sent directly
> to the printer, all the information on the form is printed in what looks
> like Arial Bold Italic. When I debugged the code, I saw that after
> transform() method is completed, PageableRenderer -> FontInfo -> usedFonts
> has these values key = "F28" value = "Arial Negreta cursiva".
>
> Here is the code:
>
> FopFactory fopFactory = FopFactory.newInstance();
>
> FOUserAgent userAgent = fopFactory.newFOUserAgent();
> userAgent.setFontBaseURL(fontDir);
>
> PageableRenderer renderer = new PageableRenderer();
> renderer.setUserAgent(userAgent);
>
> userAgent.setRendererOverride(renderer);
>
> Fop fop = fopFactory.newFop(userAgent);
>
> TransformerFactory factory = TransformerFactory.newInstance();
> Transformer transformer = factory.newTransformer(); // identity transformer
>
> Source src = new StreamSource(fo);
>
> Result res = new SAXResult(fop.getDefaultHandler());
>
> transformer.transform(src, res);
>
> Is there a way to define the fonts for the PageableRenderer in the
> fop-config.xml or in any other way?
>
>
> --
> View this message in context: http://www.nabble.com/Direct-Printing-and-setting-print-parameters-in-FOP-0.94-tp16747594p22087146.html
> Sent from the FOP - Users mailing list archive at Nabble.com.
>
Jeremias Maerki
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
Re: Direct Printing and setting print parameters in FOP 0.94
Posted by tanya C <tc...@yahoo.com>.
Jeremias Maerki-2 wrote:
>
> The best approach was to create a new renderer: PageableRenderer. This
> should only implement Pageable and provide the from/to and odd/even
> functionality that the PrintRenderer offers. PrintRenderer can then
> be derived from the PageableRenderer while preserving its original
> behaviour.
>
> This can now be found in FOP Trunk. I've added a minimal example, too:
> http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleFO2JPSPrint.java?view=markup
>
> I'll be grateful for feedback on this as I don't have a real-life
> use-case for this, unfortunately, in which I could test this. It was
> simply fun to implement. ;-) HTH
>
>
I used your example to send the form directly to the printer. I checked out
FOP Trunk and build the fop.jar which I used for my test. It works with the
minor issue of the font, which I can't figure out how to fix. The form uses
Arial font with bold, normal, and italic style, but when it is sent directly
to the printer, all the information on the form is printed in what looks
like Arial Bold Italic. When I debugged the code, I saw that after
transform() method is completed, PageableRenderer -> FontInfo -> usedFonts
has these values key = "F28" value = "Arial Negreta cursiva".
Here is the code:
FopFactory fopFactory = FopFactory.newInstance();
FOUserAgent userAgent = fopFactory.newFOUserAgent();
userAgent.setFontBaseURL(fontDir);
PageableRenderer renderer = new PageableRenderer();
renderer.setUserAgent(userAgent);
userAgent.setRendererOverride(renderer);
Fop fop = fopFactory.newFop(userAgent);
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(); // identity transformer
Source src = new StreamSource(fo);
Result res = new SAXResult(fop.getDefaultHandler());
transformer.transform(src, res);
Is there a way to define the fonts for the PageableRenderer in the
fop-config.xml or in any other way?
--
View this message in context: http://www.nabble.com/Direct-Printing-and-setting-print-parameters-in-FOP-0.94-tp16747594p22087146.html
Sent from the FOP - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
Re: Direct Printing and setting print parameters in FOP 0.94
Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
On 18.04.2008 21:09:52 David J wrote:
>
> I made the modifiecations in my 0.94 version. I also had to add the
> org.apache.fop.render.print.PagesMode class that I did not see in the list
> that you provided. I have only done a very simple test so far, I will be
> attempting to do more shortly, however, it appears to do exactly what I
> need.
>
> Will this fix be integrated into the 0.95 version or will be in the version
> after?
Since this is done in FOP Trunk and we should only do stabilizing work
on the 0.95 branch, no, it will be in the release after 0.96.
> Once again, thank you for your response.
>
> David J
>
>
> Interesting coincidence that I've done a few things in PrintRenderer
> today. With some fresh memory about this whole thing it was easy to come
> up with support for JPS, at least in FOP Trunk...
>
> (some of the stuff below may be a bit fop-dev-ish. Forgive me.)
> This can now be found in FOP Trunk. I've added a minimal example, too:
> http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleFO2JPSPrint.java?view=markup
>
> If you want to port this back to 0.94, you can try. Should be possible,
> too, without too many problems. The relevant changes are:
> http://svn.apache.org/viewvc?rev=649279&view=rev
> http://svn.apache.org/viewvc?rev=649285&view=rev
>
> I'll be grateful for feedback on this as I don't have a real-life
> use-case for this, unfortunately, in which I could test this. It was
> simply fun to implement. ;-) HTH
>
>
> --
> View this message in context: http://www.nabble.com/Direct-Printing-and-setting-print-parameters-in-FOP-0.94-tp16747594p16764209.html
> Sent from the FOP - Users mailing list archive at Nabble.com.
>
Jeremias Maerki
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
Re: Direct Printing and setting print parameters in FOP 0.94
Posted by David J <da...@columbiaultimate.com>.
I made the modifiecations in my 0.94 version. I also had to add the
org.apache.fop.render.print.PagesMode class that I did not see in the list
that you provided. I have only done a very simple test so far, I will be
attempting to do more shortly, however, it appears to do exactly what I
need.
Will this fix be integrated into the 0.95 version or will be in the version
after?
Once again, thank you for your response.
David J
Interesting coincidence that I've done a few things in PrintRenderer
today. With some fresh memory about this whole thing it was easy to come
up with support for JPS, at least in FOP Trunk...
(some of the stuff below may be a bit fop-dev-ish. Forgive me.)
This can now be found in FOP Trunk. I've added a minimal example, too:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleFO2JPSPrint.java?view=markup
If you want to port this back to 0.94, you can try. Should be possible,
too, without too many problems. The relevant changes are:
http://svn.apache.org/viewvc?rev=649279&view=rev
http://svn.apache.org/viewvc?rev=649285&view=rev
I'll be grateful for feedback on this as I don't have a real-life
use-case for this, unfortunately, in which I could test this. It was
simply fun to implement. ;-) HTH
--
View this message in context: http://www.nabble.com/Direct-Printing-and-setting-print-parameters-in-FOP-0.94-tp16747594p16764209.html
Sent from the FOP - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
Re: Direct Printing and setting print parameters in FOP 0.94
Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
Interesting coincidence that I've done a few things in PrintRenderer
today. With some fresh memory about this whole thing it was easy to come
up with support for JPS, at least in FOP Trunk...
(some of the stuff below may be a bit fop-dev-ish. Forgive me.)
The current PrintRenderer uses java.awt.print, i.e. the "old" Java
printing API. Because the printing is started within the stopRenderer()
method it is not possible in 0.94 to use PrintRenderer with JPS even
though PrintRenderer readily implements Pageable and Printable.
If you want to create a temporary solution with minimal effort, you
could copy PrintRenderer.java and adjust it to JPS. That will work, is
easy to do but is not a beautiful solution.
I thought it should be possible to turn the PrintRenderer into a pure
Pageable without active parts (i.e. it does not call PrintJob.print() or
DocPrintJob.print()). That would make it usable for both java.awt.print
and JPS.
The best approach was to create a new renderer: PageableRenderer. This
should only implement Pageable and provide the from/to and odd/even
functionality that the PrintRenderer offers. PrintRenderer can then
be derived from the PageableRenderer while preserving its original
behaviour.
This can now be found in FOP Trunk. I've added a minimal example, too:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleFO2JPSPrint.java?view=markup
If you want to port this back to 0.94, you can try. Should be possible,
too, without too many problems. The relevant changes are:
http://svn.apache.org/viewvc?rev=649279&view=rev
http://svn.apache.org/viewvc?rev=649285&view=rev
I'll be grateful for feedback on this as I don't have a real-life
use-case for this, unfortunately, in which I could test this. It was
simply fun to implement. ;-) HTH
On 17.04.2008 19:20:30 David J wrote:
>
> We are upgrading to FOP 0.94 from 0.20.5 (on Java 1.5). I am new to java
> printing in general, so any help in pointing me to the solution is greatly
> appreciated.
>
> My goal is to print directly to a printer from my java program (I have
> already generated an FO document) with printer parameters that have already
> been set up (so no user interaction for this process).
>
> We had the following code working in FOP 0.20.5:
>
> /**
> * Renders and prints a source XSL-FO document to specified print job
> */
> public static void print(InputSource source, DocPrintJob job,
> PrintRequestAttributeSet pras)
> throws AjentException {
> if (job != null) {
> AWTRenderer renderer = new AWTRenderer(null);
> render(source, renderer);
> try {
> Doc doc = new SimpleDoc(renderer,
> DocFlavor.SERVICE_FORMATTED.PAGEABLE, null);
> job.print(doc, pras);
> } catch (PrintException e) {
> ...
> }
> }
> }
> /**
> * Render a source XSL-FO document using specified renderer
> */
> public static void render(InputSource source, Renderer renderer) throws
> AjentException {
> Driver driver = new Driver();
> driver.setInputSource(source);
> driver.setRenderer(renderer);
> try {
> driver.run();
> } catch (IOException e) {
> …
> } catch (FOPException e) {
> ...
> }
> }
>
>
> I want to do something similar in 0.94 (directly print with my settings). I
> have looked at the ExampleFO2OldStylePrint example on the FOP site, however,
> I cannot figure out how to set the printer properties that I was setting
> before. (Printer and printer tray are the main properties).
>
> I realize that I will be complete changing this for 0.94, however, an
> example of setting printer options to print directly in the new API would be
> greatly appreciated.
>
> Thanks for any help or direction on this.
>
> David J
> Columbia Ultimate
>
> --
> View this message in context: http://www.nabble.com/Direct-Printing-and-setting-print-parameters-in-FOP-0.94-tp16747594p16747594.html
> Sent from the FOP - Users mailing list archive at Nabble.com.
>
Jeremias Maerki
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org