• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

PDF Services API - File has been damaged

Community Beginner ,
May 04, 2022 May 04, 2022

Copy link to clipboard

Copied

After copying the code from Postman I can sucessfully gertate (in PHP using cURL) my tokens. I the POLL the returend link in javascript and sucessfully gernerate a respone. Here is part of the Polling code I use in javescript to save the response.

 

var xhr = new XMLHttpRequest();
xhr.open("GET", '<URL FROM HEADER>', true);
xhr.responseType = "blob";
xhr.setRequestHeader('Authorization', accTok);
xhr.setRequestHeader('x-api-key', '<KEY>');
xhr.onload = function(event) {
    if(this.status == 200) {
        // Create a new Blob object using the response data of the onload object
        var blob = new Blob([this.response], {type: 'application/octetstream'});
        //Create a link element, hide it, direct it towards the blob, and then 'click' it programatically
        let a = document.createElement("a");
        a.style = "display: none";
        document.body.appendChild(a);
        //Create a DOMString representing the blob and point the link element towards it
        let url = window.URL.createObjectURL(blob);
        a.href = url;
        a.download = 'myFile.pdf';
        //programatically click the link to trigger the download
        a.click();
        window.URL.revokeObjectURL(url);
        clearInterval(pollInterval);
    }else{
        //deal with your error state here
    }
};
xhr.send();

 

 

This generates and saves the PDF File, however this file can oly be opend in a browser. If it try loading it in Adobe Embed PDF Api, it shows up as damaged. When I try to upload myfile.pdf to this forum I get this:

 

Correct the highlighted errors and try again.

  • The attachment's myfile.pdf content type (application/pdf) does not match its file extension and has been removed.

 

What am I missing?

 

TOPICS
PDF Embed API , PDF Services API

Views

298

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Adobe Employee , May 06, 2022 May 06, 2022

In this case, you would need to look up how to parse multipart responses - that's not specific to our API, but is generic. I know I struggled with this myself. 

Likes

Translate

Translate
Adobe Employee ,
May 04, 2022 May 04, 2022

Copy link to clipboard

Copied

Can you zip the file you got and try attaching it? Or email it to jedimaster@adobe.com.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
May 05, 2022 May 05, 2022

Copy link to clipboard

Copied

So the issue is that the REST API is *not* returning just PDF binary, but a multipart response that *includes* the PDF. If you open the result in Notepad (or a text editor in general), you will see:

 

--Boundary_1288607_2006293805_1651660181826
Content-Type: application/json
Content-Disposition: form-data; name="contentAnalyzerResponse"

{"cpf:inputs":{"documentIn":{"dc:format":"application/vnd.openxmlformats-officedocument.wordprocessingml.document","cpf:location":"InputFile0"},"params":{"cpf:inline":{"outputFormat":"pdf","jsonDataForMerge":{"author":"Gary Lee","customer":{"name":"Jersy Cargo Logistics","address":{"line1":"4 Florence Alley","line2":"Coolidge Junction","city":"Comanche","state":"Namekagon","zip":98001}},"invoice":{"number":"AFC4S1222203171","date":"09-04-2021, 10:23 AM","customerId":"31LPAC20149E1T","currency":"$","taxPercentage":2.9,"shippingCharge":4.49,"miscellaneous":1.3,"notesSection":"The goods sold are intended for end user consumption and not for resale","orderDetails":{"date":"09-04-2021, 10:20 AM","customerPO":"CPO-12345-09876","orderNo":"OD2100397138762021","salesRep":"Handicrafts","shipping":"Jang Cargo"},"billDetails":[{"quantity":"2","item":"Aviator Sunglass","description":"Light weight, thin and grey color","discount":-25,"total":225},{"quantity":"1","item":"Bike Helmet","description":"ISI approved. Ideal for: Boys, Compact design and strong","discount":0,"total":450}]},"company":{"name":"Projected","address":{"line1":"13H Coastal Road","line2":"Whitestone Bridge","city":"Houston","state":"Texas","zip":12345}},"bankDetails":{"Name":"Safety Center Bank","routingNo":123456789,"accountNo":100200300400}}}}},"cpf:engine":{"repo:assetId":"urn:aaid:cpf:Service-52d5db6097ed436ebb96f13a4c7bf8fb"},"cpf:status":{"completed":true,"type":"","status":200},"cpf:outputs":{"documentOut":{"cpf:location":"multipartLabel","dc:format":"application/pdf"}}}
--Boundary_1288607_2006293805_1651660181826
Content-Type: application/octet-stream
Content-Disposition: form-data; name="multipartLabel"

%PDF-1.7
binary stuff here...

 

In order to get the PDF, you have to handle the mutlpart response first. 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 06, 2022 May 06, 2022

Copy link to clipboard

Copied

Many thanks for the reply. As you can see from my code I'm not hadeling it properly. This is where the online documentation gets thin. I've no idea how to handle the application/octetstream. Is this encoded? How do i extract the pdf exactly in JavaScript? Any help or tips are greatly appreciated. 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 06, 2022 May 06, 2022

Copy link to clipboard

Copied

help! I did not want to mark this as a correct answer. How can i undo this?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
May 06, 2022 May 06, 2022

Copy link to clipboard

Copied

In this case, you would need to look up how to parse multipart responses - that's not specific to our API, but is generic. I know I struggled with this myself. 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 16, 2022 Jun 16, 2022

Copy link to clipboard

Copied

lucky for you i came across your thread and actually did this today...

<cfscript>
contentType = variables.fileres.Responseheader['Content-Type'];  
dataSource  = createObject("java", "javax.mail.util.ByteArrayDataSource").init(variables.fileres.fileContent.toByteArray(), javaCast( "string", contentType));
mimeParts   = createObject("java", "javax.mail.internet.MimeMultipart").init(dataSource);
for (i = 0; i < mimeParts.getCount(); i++) {
  bp = mimeParts.getBodyPart( javacast("int", i));
  if (!isNull(bp) && bp.isMimeType("application/octet-stream")) {
   outputFile = createObject("java", "java.io.File").init(variables.ocrFileHandle);
   bp.saveFile(outputFile);
  }
 }
</cfscript>

does anyone else think it's strange Adobe doesn't have a ColdFusion option in their insert code WYSIWYG???

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Jun 20, 2022 Jun 20, 2022

Copy link to clipboard

Copied

If you are on ColdFusion, why not just use the Java SDK? 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 20, 2022 Jun 20, 2022

Copy link to clipboard

Copied

I don't have a great reason, but trying to restructure the architecture of an existing app, the use of dev environments and build tools and deployment strategies that are different from what I typically do, make writing the 9 or so lines of code above more efficient for me. Maybe if I started a new project I could take that path more easily. Probably just my lack of knowledge to make the sdk an option. Couldn't they just hand out the jar file?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Jun 20, 2022 Jun 20, 2022

Copy link to clipboard

Copied

There's an issue with our JAR and CF - but there's an easy workaround. I documented it here: https://medium.com/adobetech/adobe-coldfusion-and-document-services-living-in-harmony-46279ec09d21

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 20, 2022 Jun 20, 2022

Copy link to clipboard

Copied

I'm looking at giving this a shot.... looks like he changed some of the class paths from what you have in your example. But thanks for the direction.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 22, 2022 Jun 22, 2022

Copy link to clipboard

Copied

Just thought I'd follow up on this... when his JAR is loaded in the CF class path, it creates conflict in some Java io functionality. <cfmailparam name="Content-Type" value="text/x-gm-impdata"> causes failure.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Jun 23, 2022 Jun 23, 2022

Copy link to clipboard

Copied

LATEST

I'd suggest filing that as a bug report on his repo. 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources