-1

I am using Netbeans, google app engine, java. When I try to create pdf as follows it shows this error.

Java.io.FileOutputStream is restricted class in Google App Engine.

My code is,

Document document = new Document();

PdfWriter.getInstance(document, new BufferedOutputStream(new FileOutputStream("C:\\Examplenamaaaa.pdf")));

document.open();

PdfPTable table = new PdfPTable(2);

PdfPCell cell = new PdfPCell(new Paragraph("column span 2"));
cell.setColspan(2);

table.addCell(cell);

table.addCell("1");

table.addCell("Namita");

table.addCell("2");

table.addCell("Asmita");

document.add(table);

document.close();
Namrata
  • 1
  • 2
  • see http://stackoverflow.com/questions/8090670/google-appengine-not-supporting-fileoutputstream – reto Feb 19 '14 at 14:03

1 Answers1

1

You're writing code that creates a PDF file on your C-drive. While this may work on your machine, it probably will not on Google App Engine.

Instead, you could try to write the PDF to a ByteArrayOutputStream (for example) and later send that back to the web browser so you will be able to view the generated PDF.

A ByteArrayOutputStream behaves exactly the same as a FileOutputStream, except the bytes aren't written to a file, but to a byte[] (hence the name). Both of them extend the OutputStream interface, so they can be switched without further changes to your code.

Streaming the response back to the browser isn't supported in GAE so you could consider storing the contents of the ByteArrayOutputStream in the BlobStore in order to serve it back to the browser later on.

mthmulders
  • 9,483
  • 4
  • 37
  • 54
  • thanks mthmulders, but dont know how to use ByteArrayOutputStream. Could you please share any example link. – Namrata Feb 20 '14 at 13:36
  • If you want to persist the PDF file online, you may also want to look at [Google Cloud Storage](https://developers.google.com/appengine/docs/java/googlecloudstorageclient/). – tx802 Feb 20 '14 at 15:08