yyn0210 / alivepdf

Automatically exported from code.google.com/p/alivepdf
0 stars 0 forks source link

Issue adding an image and text on the same page #250

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
MXML :

printPDF=new PDF(Orientation.LANDSCAPE, Unit.CM, Size.A4);
printPDF.setDisplayMode(Display.FULL_PAGE, Layout.SINGLE_PAGE, "UseNone", 1);
printPDF.addPage();
printPDF.addImageStream(new imgClass() as ByteArray, ColorSpace.DEVICE_RGB,
new Resize(Mode.RESIZE_PAGE, Position.LEFT));
printPDF.setXY(8, 4);
printPDF.setFont(new CoreFont(FontFamily.HELVETICA_BOLD), 14)
printPDF.writeText(0.5, "My Text", null);
printPDF.end();
printPDF.save(Method.REMOTE, "OPServ", Download.INLINE, "test.pdf", '_self');

Java Servlet :
  int maxLength = request.getContentLength();
  byte[] bytes = new byte[maxLength];
  String method = request.getParameter("method");
  String name = request.getParameter("name");
  ServletInputStream si = request.getInputStream();
  int k = si.read(bytes);
  if (bytes != null && k>0)
  {
  ServletOutputStream so = response.getOutputStream();
  response.setContentType("application/pdf");
  response.setContentLength(bytes.length);
  response.setHeader("Content-Disposition", method + ";filename=" + name);
  so.write(bytes);
  so.flush();
  so.close();
  }

What is the expected output? What do you see instead?
Expected : First the image must appear as header and then the text.
Getting : Error : "The file is damaged and cannot be repaired"

What version of the product are you using? On what operating system?
AlivePDF 0.1.5 RC, Flash Builder 4, Flex 3.5 SDK, Windows 7

Please provide any additional information below.
Please provide a workaround ASAP. Thanks

Original issue reported on code.google.com by kumarpra...@gmail.com on 5 Jun 2010 at 3:13

GoogleCodeExporter commented 8 years ago
The issue has been solved. The problem was not with AlivePDF. It was java 
servlet
part causing problem. After changing it to,
         int i = 0;
     int k = 0;
     int maxLength = request.getContentLength();
     byte[] bytes = new byte[maxLength];
     String method = request.getParameter("method");
     String name = request.getParameter("name");
     ServletInputStream si = request.getInputStream();
     while (true)
     {
     k = si.read(bytes,i,maxLength);
     i += k;
     if (k <= 0)
     break;
     }
     if (bytes != null)
     {
     ServletOutputStream stream = response.getOutputStream();
     response.setContentType("application/pdf");
     response.setContentLength(bytes.length);
     response.setHeader("Content-Disposition",method + ";filename=" + name);
     stream.write(bytes);
     stream.flush();
     stream.close();

it solved the problem.

Original comment by kumarpra...@gmail.com on 5 Jun 2010 at 6:05