Hi,
I am using pdfjet, when I try to insert image I am getting this Error:
[ERROR] java.io.IOException: Stream closed
[ERROR] java.io.IOException: Stream closed
And this is my servlet code:
/**
*
*/
package com.veersoft.accounting.servlet;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.logging.Logger;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.pdfjet.A4;
import com.pdfjet.Font;
import com.pdfjet.Image;
import com.pdfjet.ImageType;
import com.pdfjet.PDF;
import com.pdfjet.Page;
import com.pdfjet.RGB;
import com.pdfjet.TextLine;
public class PDFServlet extends HttpServlet {
......
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
}
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
OutputStream out = res.getOutputStream();
try {
res.setStatus(HttpServletResponse.SC_OK);
res.setHeader("Content-Disposition", "attachment;");
res.setContentType("application/pdf");
OutputStream os = res.getOutputStream();
this.example(os);
os.flush();
os.close();
} catch (Exception e) {
LOG.severe(e.toString());
} finally {
out.close();
}
}
public void example(
OutputStream os) throws Exception {
ClassLoader cl = PDFServlet.class.getClassLoader();
PDF pdf = new PDF(os);
pdf.setTitle("Using TextLine class");
pdf.setSubject("Examples");
pdf.setAuthor("WebWineWatch");
Font f1 = new Font(pdf, "Helvetica");
Font f2 = new Font(pdf, "Helvetica");
Page page = new Page(pdf, A4.PORTRAIT);
f1.setSize(24);
f2.setSize(12);
Image image;
String fileName = "../images/intro-3.jpg";
try {
BufferedInputStream bis1 =
new BufferedInputStream(
getClass().getResourceAsStream(fileName));
image = new Image(pdf, bis1, ImageType.JPEG);
} catch (Exception e) {
LOG.severe(e.toString());
image = null;
}
if (image != null) {
image.setPosition(0, 200);
image.scaleBy(0.5);
image.drawOn(page);
}
Image image2;
try {
BufferedInputStream bis2 =
new BufferedInputStream(
getClass().getResourceAsStream(fileName));
image2 = new Image(pdf, bis2, ImageType.JPEG);
} catch (Exception e) {
LOG.severe(e.toString());
image2 = null;
}
if (image2 != null) {
image2.setPosition(100, 100);
image2.scaleBy(0.5);
image2.drawOn(page);
}
TextLine text1 = new TextLine(f1);
text1.setColor(RGB.BLACK);
text1.setText("Veersoft WebWineWatch");
text1.setPosition(250, 160);
text1.drawOn(page);
TextLine text2 = new TextLine(f2);
text2.setColor(RGB.BLUE);
text2.setText("Hello AccountingGuru.in!");
text2.setPosition(250, 350);
text2.drawOn(page);
pdf.flush();
os.close();
}
}
Any suggestion much appreciated.
--
Regards
Suresh Babu G
<http://www.accountingguru.in/>
--
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine?hl=en.