Printing a JChart
Printing a JChart
I was wondering if anybody could tell me how I would print a chart that I created. Should I use the print class that java has available or is there something better with JFreeChart. Any direction and/or code would be very useful. Thanks
with iText to PDF:
1. read http://www.jfree.org/phpBB2/viewtopic.p ... echart+jsp
I have learned alot from that
1. Modify web.xml
2. test out following code just by iText.jar by itself. it works cause i tested yesterday.
create servlet:
3. Combine iText & jfreechart using pmarsollier' s codes for PDF, and read thoughly of what psupa wrote.
4. in jsp, all i did, was just using a jsp:forward to my servlet page, and it worked.
1. read http://www.jfree.org/phpBB2/viewtopic.p ... echart+jsp
I have learned alot from that
1. Modify web.xml
2. test out following code just by iText.jar by itself. it works cause i tested yesterday.
create servlet:
Code: Select all
// http://www.softhouse.com.cn/html/200410/2004102610123400001359.html
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException,ServletException
{
Document document = new Document(PageSize.A4, 36,36,36,36);
ByteArrayOutputStream ba = new ByteArrayOutputStream();
try
{
PdfWriter writer = PdfWriter.getInstance(document, ba);
document.open();
document.add(new Paragraph("Hello World"));
}
catch(DocumentException de)
{
de.printStackTrace();
System.err.println("A Document error:" +de.getMessage());
}
document.close();
response.setContentType("application/pdf");
response.setContentLength(ba.size());
ServletOutputStream out = response.getOutputStream();
ba.writeTo(out);
out.flush();
}
4. in jsp, all i did, was just using a jsp:forward to my servlet page, and it worked.