Skip navigation
Ankit Khujneri
Currently Being Moderated

Problem generating PDF using LifeCycle Designer ES

May 27, 2009 7:42 AM

Hi,

 

I am facing one problem while creating PDF using life cycle designer tool.

I am trying to generate a PDF that will contain a simple textInput with some text. I am using a snapshot class to capture this component.

This captured image is converted to base64 using base64Encoder.Now, this encoded string creates a problem with lifeCycle Designer..

If I enter,say 7, in textInput, the PDF gets generated properly with a complete snaphot of text box and the text within. But if I enter some other text, say XXDD, the PDF generation fails. Is there any problem with decoding the base64 encoded string?

Here is some code snippet :

 

// Flex code

private function generateImagePdf() : void {
                       
            var url:String = "/pdfSampleApp";
                     
        var snapshot:ImageSnapshot = ImageSnapshot.captureImage(uname);// uname is a textInput
        containerImage = ImageSnapshot.encodeImageAsBase64(snapshot);
        url = url + "/PDFGeneratorServlet?xmlData="+xmlImageModel";
         navigateToURL(new URLRequest(url), "_New");
       
        }

// this XML is passed as parameter

<mx:XML id="xmlImageModel" >
    <root><imagefield>{uname}</imagefield></root>
</mx:XML>

//java

//This code wil build the document from param String. This param is a parameter from request.

String param = req.getParameter("xmlData");

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db;
            Document doc = null;
            db = dbf.newDocumentBuilder();
            doc = db.parse(new InputSource(new StringReader(param)));

 

  processElement(doc.getDocumentElement());

helper.importDataset(doc);

// Save new PDF as a byte array in the current session
            byte[] bytes = helper.saveToByteArray();

            // Close any resources
            helper.close();

            resp.setContentType("application/pdf");
            resp.setContentLength(bytes.length);

            BufferedOutputStream bos = new BufferedOutputStream(resp
                    .getOutputStream());
            bos.write(bytes);

 

private void processElement(Element elem) throws Exception {
        System.out.println("****************************************");
        System.out.println("Tag:  " + elem.getNodeName());
        //System.out.println("NS:   " + elem.getNamespaceURI());

        NodeList children = elem.getChildNodes();
        for (int ii = 0; ii < children.getLength(); ii++) {
            Node child = children.item(ii);
            if (child instanceof Element)
                processElement((Element) child);
            else if (child instanceof Text) {
                String a = child.getNodeValue();
                a = a.replace(' ', '/');
                child.setNodeValue(a);

                System.out.println("Text: " + child.getNodeValue());
            }
        }
        System.out.println("****************************************");
    }


 

 

 

On printing the value of the node <imageField> gives me data like:

         iVBORw0KGgoAAAANSUhEUgAAAN4AAAA4CAYAAACSekYo.// this is Base64 encoded string. For this case the PDF generation is successful, but if the string contains some spaces in between, the PDF generation fails.

 

Please suggest!

 
Replies

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points