Steps I took
create a package location to store all your PDF reports
for my app,
package org.mycompany.appname.pdf.*
you will use the iText library to generate a ByteStream object. This ByteStream object will then be fed to a PdfScreen class
This article on creating a servlet to send Pdf's inspired my PdfScreen class
http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_20149865.html
I'll post my PdfScreen at the following URL
http://kiasoft.com/pdf/PdfScreen.html
I use empty vm files to pull the reports I wish to view (this may or may not be the best way to do it, but it works unless the byte stream is empty, you just get an empty page)
so...
Report screen templates/screens/pdf/Report1.vm
An empty template
Report screen class which extends PdfScreen org.mycompany.appname.modules.screens.pdf.Report1.java
This page calls the bytestream proper that we want to display and takes any necessary parameters that need to be fed to Report1
example:
package org.mycompany.appname.modules.screens.pdf;
import java.io.ByteArrayOutputStream;
import org.apache.turbine.modules.screens.RawScreen;
import org.apache.turbine.util.RunData;
import org.apache.turbine.util.Log;
import org.apache.torque.util.Criteria;
import org.apache.turbine.services.resources.TurbineResources;
import org.apache.velocity.context.Context;
import org.mycompany.appname.pdf.Report1;
/**
* RawScreen for displaying generated PDF files
*/
public class Confirmation extends PdfScreen
{
public ByteArrayOutputStream buildPdf (RunData data) throws Exception
{
int orderid = data.getParameters().getInt("orderid");
Criteria criteria = new Criteria();
criteria.add(OMPeer.ORDER_ID, orderid);
OM om = (OM) OMPeer.doSelect(criteria).get(0);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
Report1 rep = new Report1();
rep.createReport( om, byteArrayOutputStream);
return byteArrayOutputStream;
}
}
Report writer class org.mycompany.appname.pdf.Report1.java
This class uses the iText library to setup the bytestream. It implements the method createReport taking a ByteArrayOutputStream as an argument and stuffs the
contents of the PDF it is to generate into this stream.
The screen class itself should just return this stream to the users web browser and voila, you have a PDF open on the other end.
If you need a more clear example, I am working on documenting this a little better and hope to post it to the wiki soon.
Thanks,
Jeff Painter
[EMAIL PROTECTED] wrote:
Hello turbine experts,
i wanna build some reports on my web. I'm considered using iText. Does anybody
know how to use iText with TDK ...
i already try made a simple Screen : Tes.java
package org.ncs.jts.modules.screens;
import org.apache.velocity.context.Context;
import org.apache.turbine.util.RunData;
import org.apache.turbine.modules.actions.VelocityAction;
import org.apache.torque.util.Criteria;
import java.io.FileOutputStream;
import java.io.IOException;
import com.lowagie.text.*;
import com.lowagie.text.pdf.PdfWriter;
public class Tes extends SecureScreen
{
public void doBuildTemplate(RunData data, Context context)
{
Document document = new Document();
try {
PdfWriter.getInstance(document, new FileOutputStream("ChapTes.pdf"));
document.open();
document.add(new Paragraph("Hello World"));
}
catch(Exception de) {
data.setMessage(de.getMessage());
context.put("pesan",de.getMessage());
}
document.close();
}
}
There is no exception thrown ... and the pesan context is also null when i try to call it with Tes.vm it just display $pesan
Can any body help me or suggest me with others PDF report designer ?
Thank You
Amri Hidayat
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
