Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session

Error while invoking renderPDFForm with attachment

Avatar

Level 2

hi,

I'm using ES4 renderPDFForm service to render pdf along with attachment.

This service works if I dont have PDF attachment but doesn't work PDF with attachments.

I'm sending the PDF attachment like below.

     Map attachments = new Map();

     MapItem item = new MapItem();

     itme.setKey("attachment");

     byte[] pdfAttachment = new byte[10,20,30...]

     com.adobe.idp.Document doc = new com.adobe.idp.Document(pdfAttachment );

     item.setValue(doc);

     attachments .add(item);

service.renderPDFForm("CORR0040-MiscellaneousMS-8.xdp", inputData, renderSpec, spec, attachments);

Error I'm getting is:  javax.xml.ws.soap.SOAPFaultException: java.lang.ClassCastException: java.lang.String incompatible with com.adobe.idp.Document

Please help me how to resolve this...

10 Replies

Avatar

Employee Advisor

See if below helps :

================================================ renderPDFForm2==================================================================

Map attach = new HashMap();

String attachmemntfilename = "Attachment.pdf";

Document attachmemntfile = new Document(new FileInputStream("C:\\Users\\Administrator\\Desktop\\Testing.pdf"));

                     attach.put(attachmemntfilename, attachmemntfile);

Document formQuery = new Document(new FileInputStream("C:\\Users\\Administrator\\Desktop\\PreLoanForm.xdp"));

Document oInputData = new Document(new FileInputStream("C:\\Users\\Administrator\\Desktop\\firstAppTestData.xml"));

FormsResult formOut = formsClient.renderPDFForm2(formQuery, // formQuery

                     oInputData, // inDataDoc

                     pdfFormRenderSpec, // PDFFormRenderSpec

                     uriValues, // urlSpec

                     attach // attachments

                     );

                                    // Create a Document object that stores form data

                   Document myData = formOut.getOutputContent();

                   myData.copyToFile(new File("OutputPDF.pdf"));

================================================= renderPDFForm ============================================================

                    FormsServiceClient formsClient = new FormsServiceClient(myFactory);

                                         // Set the parameter values for the renderPDFForm method

                     String formName = "PreLoanForm.xdp";

                     Document formQuery = new Document(new FileInputStream("C:\\Users\\Administrator\\Desktop\\PreLoanForm.xdp"));

                     Map attach = new HashMap();

                     String attachmemntfilename = "Attachment.pdf";

                     Document attachmemntfile = new Document(new FileInputStream("C:\\Users\\Administrator\\Desktop\\Testing.pdf"));

attach.put(attachmemntfilename, attachmemntfile);

byte[] cData = "".getBytes();

Document oInputData = new Document(new FileInputStream("C:\\Users\\Administrator\\Desktop\\firstAppTestData.xml"));

// Set run-time options using a PDFFormRenderSpec instance

PDFFormRenderSpec pdfFormRenderSpec = new PDFFormRenderSpec();

pdfFormRenderSpec.setCacheEnabled(new Boolean(true));

pdfFormRenderSpec.setAcrobatVersion(AcrobatVersion.Acrobat_9);

// Specify URI values that are required to render a form

URLSpec uriValues = new URLSpec();

uriValues.setContentRootURI("repository:///Applications/FirstAppSolution/1.0/");

FormsResult formOut = formsClient.renderPDFForm(formName, // formQuery

oInputData, // inDataDoc

pdfFormRenderSpec, // PDFFormRenderSpec

uriValues, // urlSpec

attach // attachments

);

// Create a Document object that stores form data

Document myData = formOut.getOutputContent();

myData.copyToFile(new File("OutputPDF.pdf"));

Thanks,

Wasil

Avatar

Level 2

Wasil,

Thanks for the reply what version of WSDL is this? I'm using 11.0 but not supported Java.Util.HashMap, it only supports import org.apache.xml.xml_soap.Map;

Here is my renderForm XSD:

<element name="renderPDFForm">

  <complexType>

  <sequence>

  <element maxOccurs="1" minOccurs="0" name="formQuery" type="xsd:string" />

  <element maxOccurs="1" minOccurs="0" name="inDataDoc" type="impl:BLOB" />

  <element maxOccurs="1" minOccurs="0" name="pdfFormRenderSpec" type="impl:PDFFormRenderSpec" />

  <element maxOccurs="1" minOccurs="0" name="urlSpec" type="impl:URLSpec" />

  <element maxOccurs="1" minOccurs="0" name="attachments" type="apachesoap:Map" />

  </sequence>

  </complexType>

  </element>

Avatar

Level 2

@WASIL: please let me know what version are you using...

Avatar

Employee Advisor

That was done by using SDK. I'll try by consuming WSDL, generating proxy classes.

-Wasil

Avatar

Level 2

Wasil,

Have you got a chance to try it ?

Avatar

Level 2

Wasil,

I tried still getting the same error...

javax.xml.ws.soap.SOAPFaultException: java.lang.ClassCastException: java.lang.String incompatible with com.adobe.idp.Document

Avatar

Employee Advisor

The above code I shared was tested using SDK. Are you using LiveCycle SDK ? Please share your code.

Thanks

Wasil

Avatar

Level 2

Thanks for the reply, here is my code..

I'm using ES4

public GenerateDocumentResponse generateDocument(GenerateDocumentRequest

generateDocumentRequest) throws SystemFault, ValidationFault

    myLogger.info("invoking ES4 Tech Service...");

    System.out.println("invoking ES4 Tech Service...");

    com.adobe.idp.services.FormsService service = getAdobeES4RenderService();

    BLOB inputData = ES4DataTransformer.transformInputData(templatesList);

    inputData.setContentType(contentType);

    PDFFormRenderSpec renderSpec = new PDFFormRenderSpec();

    renderSpec.setCacheEnabled(new Boolean(true));

    URLSpec spec = new URLSpec();

    spec.setContentRootURI(ReadProperties.getValue(ES4_CONTENT_ROOT_URI));

    spec.setBaseURL(ReadProperties.getValue(ES4_REMOTE_URL));

    Map attachments = ES4DataTransformer.populateAttachments(templatesList);

    System.out.println("Renderfom is about to invoke:::");

    service.renderPDFForm(templatePath, inputData, renderSpec, spec,attachments, outRenderFormResultDoc, pageCount, locale, formResult);

    response = new GenerateDocumentResponse();

    return response;

}

public static Map populateAttachments(List<DocumentTemplate> templatesList){

Map attachments = new Map();

       List<MapItem> items = attachments.getItem();

       if(null == items){

            items = new  ArrayList<MapItem> ();

       }

  for(DocumentTemplate template: templatesList){

       if(null != template){

       List<DocumentAttachmentDataType> attachmentList = template.getAttachments();

       if(null !=  attachmentList ){

            int i = 0;

       for(DocumentAttachmentDataType dataType: attachmentList){

            MapItem item = new MapItem();

           byte[] attachmentData = dataType.getAttachment();

            com.adobe.idp.Document doc = new com.adobe.idp.Document(attachmentData);

            item.setKey("CDT00000000003933811.xdp");

            item.setValue(doc);

            items.add(item);

            ++i;

       }

       }

       }

  }

  return attachments;

}

Avatar

Employee Advisor

You are using the WSDL generated proxy classes, not SDK. Previously,I also found some issues with the generated proxy classes API. Did you contact Enterprise Support regarding this ?

If not, please contact Enterprise Support so that this could be worked upon in case it is a bug.

-Wasil

Avatar

Level 2

Nope. Not contacted. Woul you pls give me their email id where I can reach them

Thanks

TPReddy