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 pedro <pe...@libero.it> on 2011/02/18 11:55:09 UTC

PrintPreview

HI all i use the PrintPreviewPanel


[code]
FopFactory fopFactory = FopFactory.newInstance();

					AWTRenderer renderer = new AWTRenderer();
					FOUserAgent userAgent = fopFactory.newFOUserAgent();
					userAgent.setRendererOverride(renderer);
					renderer.setScaleFactor(
						25.4 * 800
						/ (Toolkit.getDefaultToolkit().getScreenResolution() * 210.0));
					renderer.setPreviewDialogDisplayed(false);
					renderer.setUserAgent(userAgent);
					
					Fop fop = fopFactory.newFop(userAgent);
					
					PreviewPanel previewPanel = new PreviewPanel(userAgent,
						null, renderer);

					// Standard fop usage...
					TransformerFactory factory = TransformerFactory.newInstance();
					Transformer transformer = factory.newTransformer();


					ByteArrayInputStream arrayInputStream = new ByteArrayInputStream(fo.
						getBytes());

					Source src = new StreamSource(arrayInputStream);
					Result res = new SAXResult(fop.getDefaultHandler());
					transformer.transform(src, res);

					// To handle several pages on the same panel :
					previewPanel.setDisplayMode(PreviewPanel.CONTINUOUS);

[/code]


The problem is that i have to use a AreaTreeHandler but i don't know how to
do it.
The other problem is how to display the toolbar.


Thanks!
-- 
View this message in context: http://old.nabble.com/PrintPreview-tp30957628p30957628.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: PrintPreview

Posted by Eric Douglas <ed...@blockhouse.com>.
I skipped over your other message.  I see now where you tried to
reference an AreaTreeHandler, but that's not necessary.
You sent 2 incomplete pieces of code.  The second one looks closer.
Here's a bit of a combination.  See if this helps.

[code]
File fileXsl = new File("c:\\xsl.xml");
FileInputStream xslFIS = new FileInputStream(fileXsl);
byte[] xslSource = new byte[xslFIS.available()];
xslFIS.read(xslSource);
xslFIS.close();
ByteArrayInputStream xslBAIS = new ByteArrayInputStream(xslSource);
InputSource xslIS = new InputSource(xslBAIS);
xslSS = new SAXSource(xslIS);

File xmlFile = new File("c:\\xml.xml");
FileInputStream xmlFIS = new FileInputStream(xmlFile);
byte[] xmlSource = new byte[xmlFIS.available()];
xmlFIS.read(xmlSource);
xmlFIS.close();
ByteArrayInputStream xmlBAIS = new ByteArrayInputStream(xmlSource);
InputSource xmlIS = new InputSource(xmlBAIS);
xmlSS = new SAXSource(xmlIS);

FopFactory fopFactory = FopFactory.newInstance();
AWTRenderer renderer = new AWTRenderer(true);
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
renderer.setUserAgent(foUserAgent);
foUserAgent.setRendererOverride(renderer);

PreviewPanel previewPanel = new PreviewPanel(foUserAgent, null,
renderer);

renderer.setScaleFactor(25.4 * 800 /
(Toolkit.getDefaultToolkit().getScreenResolution() * 210.0));
renderer.setPreviewDialogDisplayed(false);

Fop fop = fopFactory.newFop(MimeConstants.MIME_FOP_AWT_PREVIEW,
foUserAgent);

// Standard fop usage...
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(xslSS);

Result res = new SAXResult(fop.getDefaultHandler());
transformer.transform(xmlSS, res);

// To handle several pages on the same panel :
previewPanel.setDisplayMode(PreviewPanel.CONTINUOUS);
previewPanel.showPage();
previewPanel.setPage(0);
[/code] 

That's pretty much how I wrote mine initially, excluding some custom
code like font loading.
The only problem I found with this built in preview panel is the
renderer attached to the PreviewPanel.
1) I'm doing client-server code.  Transforms normally run on the server.
The PreviewPanel of course has to run on the client.  Changing the zoom
(ScaleFactor) has to re-render the entire document.
2) This also has to create a transformer and renderer object on the
client which is taking a long time.

In my new custom preview panel I'm using the PNGRenderer.  This holds
the transformed output in the renderer.  I can use it's getNumberOfPages
method to create an array and retrieve the pages with getPageImage.  For
the zoom I just use drawImage from Graphics2D which makes the pages a
little fuzzy at any level other than the initial size but they're
readable and it's a lot faster.

-----Original Message-----
From: pedro [mailto:pedro.riky@libero.it] 
Sent: Friday, February 18, 2011 5:55 AM
To: fop-users@xmlgraphics.apache.org
Subject: PrintPreview


HI all i use the PrintPreviewPanel

The problem is that i have to use a AreaTreeHandler but i don't know how
to do it.
The other problem is how to display the toolbar.


Thanks!
--
View this message in context:
http://old.nabble.com/PrintPreview-tp30957628p30957628.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


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


RE: PrintPreview

Posted by Eric Douglas <ed...@blockhouse.com>.
Why would you access an AreaTreeHandler?
It looks like you've got correct code to create a PreviewPanel there.
What are you trying to embed it in?
I expect you'll want a window of some sort.
 

-----Original Message-----
From: pedro [mailto:pedro.riky@libero.it] 
Sent: Friday, February 18, 2011 5:55 AM
To: fop-users@xmlgraphics.apache.org
Subject: PrintPreview


HI all i use the PrintPreviewPanel


[code]
FopFactory fopFactory = FopFactory.newInstance();

					AWTRenderer renderer = new
AWTRenderer();
					FOUserAgent userAgent =
fopFactory.newFOUserAgent();
	
userAgent.setRendererOverride(renderer);
					renderer.setScaleFactor(
						25.4 * 800
						/
(Toolkit.getDefaultToolkit().getScreenResolution() * 210.0));
	
renderer.setPreviewDialogDisplayed(false);
	
renderer.setUserAgent(userAgent);
					
					Fop fop =
fopFactory.newFop(userAgent);
					
					PreviewPanel previewPanel = new
PreviewPanel(userAgent,
						null, renderer);

					// Standard fop usage...
					TransformerFactory factory =
TransformerFactory.newInstance();
					Transformer transformer =
factory.newTransformer();


					ByteArrayInputStream
arrayInputStream = new ByteArrayInputStream(fo.
						getBytes());

					Source src = new
StreamSource(arrayInputStream);
					Result res = new
SAXResult(fop.getDefaultHandler());
					transformer.transform(src, res);

					// To handle several pages on
the same panel :
	
previewPanel.setDisplayMode(PreviewPanel.CONTINUOUS);

[/code]


The problem is that i have to use a AreaTreeHandler but i don't know how
to do it.
The other problem is how to display the toolbar.


Thanks!
--
View this message in context:
http://old.nabble.com/PrintPreview-tp30957628p30957628.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


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