RE: Need help calling FOP correctly
"Clark, Raymond C" <[email protected]>
| Newsgroups | gmane.text.xml.fop.user |
|---|---|
| Message-ID | <4591925761C70C40B4A618BDB72D231A12ABACD0@ETC-EXMB-13.corp.erac.com> |
Thank you for the reply.
What I would really like to do is to bypass the XML input that FOP normally uses and call the FOP Java methods from our framework directly in order to produce a PostScript file. Checking examples online I didn’t have a configuration file. I’m thinking now that I need one to define the fonts. At this point I am just trying to get 1 line of text to come out in the PS file. Here is my code.
OutputStream output = new FileOutputStream("C:/snapshotviews/sts-workspace-3.7/billing-document-system/bds-service/src/test/resources/Products/Paper/xmlgraphicsTest.ps");
PSGenerator psGenerator = new PSGenerator(output);
// Setup
FopFactory fopFactory = FopFactory.newInstance(new File(".").toURI());
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
IFContext context = new IFContext(foUserAgent);
PSDocumentHandler psDocumentHandler = new PSDocumentHandler(context);
// Stuff the Fonts in the class
FontInfo fontInfo = new FontInfo();
fontInfo.addFontProperties("header", "Helvetica", "normal", 0);
psDocumentHandler.setFontResources(fontInfo);
psDocumentHandler.setFontInfo(fontInfo);
psDocumentHandler.setGenerator(psGenerator);
// Create the top of the PostScript file
psDocumentHandler.endDocumentHeader();
// Loop through the pages
PSPainter ifPainter = psDocumentHandler.startPageContent();
// Set up the font for the text
IFState ifState = IFState.create();
ifState.setFontFamily("Helvetica");
ifState.setFontStyle("normal");
ifState.setFontWeight(0);
ifState.setFontSize(10);
ifState.setTextColor(Color.BLACK);
ifPainter.setState(ifState);
// Write the text to the PostScript file
ifPainter.drawText(100, 500, 2, 5, null, "PDF Text");
// Wrap up
psGenerator.flush();
output.flush();
output.close();
Thank you,
Ray
From: Szeak (Register Man) [mailto:[email protected]]
Sent: Tuesday, August 30, 2016 1:41 AM
To: [email protected]
Subject: Re: Need help calling FOP correctly
Hi,
We need more info about how do you using FOP. What is in FOP config?
Can you show us your used config, and small piece from your code which loads or sets the config?
2016-08-29 22:51 keltezéssel, Clark, Raymond C írta:
Hi all,
At work we have a Java framework that I need to hook in with FOP. So I need our framework to call the appropriate FOP classes.methods to produce a PostScript file. I have it producing a PostScript file but I am having trouble with fonts.
What do I need to call to get a font, Helvetica or Times New Roman, etc, loaded into PSDocumentHandler correctly so that when I call PSPainter.drawText the text appears in the PostScript file? Right now I am getting the Font not available exception.
Thank you,
Ray
________________________________
CONFIDENTIALITY NOTICE: This e-mail and any files transmitted with it are intended solely for the use of the individual or entity to whom they are addressed and may contain confidential and privileged information protected by law. If you received this e-mail in error, any review, use, dissemination, distribution, or copying of the e-mail is strictly prohibited. Please notify the sender immediately by return e-mail and delete all copies from your system.
--------------------------------------------------------------------- To unsubscribe, e-mail: [email protected]<mailto:[email protected]> For additional commands, e-mail: [email protected]<mailto:[email protected]>