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

PDF Compression using Rest API

Community Beginner ,
Dec 21, 2021 Dec 21, 2021

Copy link to clipboard

Copied

I have been attempting to compress PDFs using the rest api POST call - my issue is that no matter how I format the InputFile0, form-data field - the subsequent GET api call is saying that my file is corrupted however I am 100% confident that I am passing a valid PDF file - I have been attempting to compare results using postman on the same file, which works, but setting this field programmatically there is something I am missing:  I have tried all the formats in the FileReader object namely:  

readAsBinaryString, 
readAsDataURL, 
readAsText,
readAsArrayBuffer
None of them resolve the error - how is anyone else programmaticaly setting InputFile0 such the the server does not complain about a corrupted file ?
TOPICS
PDF Services API

Views

1.9K

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

Community Beginner , Dec 23, 2021 Dec 23, 2021

I found the problem - so this thread is resolved -- thank u

Votes

Translate

Translate
Adobe Employee ,
Dec 22, 2021 Dec 22, 2021

Copy link to clipboard

Copied

Could you share the code you are using, and possibly the PDF as well? (Note, Adobe is about to go on holiday break so we may be slow to respond.)

Votes

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 ,
Dec 23, 2021 Dec 23, 2021

Copy link to clipboard

Copied

Sure - the variable finalPdf is 100% a valid pdf file and I have attached the pdf file:  here is the code:

 

            reader.onload = function(ev) {
                var formData = new FormData();
                               
                formData.append('contentAnalyzerRequests',
                    JSON.stringify(
                        {
                            "cpf:inputs": {
                                "params": {
                                    "cpf:inline": {
                                        "compressionLevel": "HIGH"
                                    }
                                },
                                "documentIn": {
                                    "cpf:location": "InputFile0",
                                    "dc:format": "application/pdf"
                                }
                            },
                            "cpf:engine": {
                                "repo:assetId": "urn:aaid:cpf:Service-f37d36f4e6724eed92149a8ff35ea061"
                            },
                            "cpf:outputs": {
                                "documentOut": {
                                    "cpf:location": "multipartLabelOut",
                                    "dc:format": "application/pdf"
                                }
                            }
                        }                        
                    ));
//&?
debugger
                formData.append('InputFile0', ev.target.result);

                $.ajax({
                    type: 'POST',
                    cache: false,
                    data: formData,
                    processData: false,
                    contentType: false,
                    enctype: 'multipart/form-data',
                    headers: {
                        'Prefer': 'respond-async,wait=0',
                        'Authorization': 'Bearer ' + APIKEY,
                        'Accept': 'application/json, text/plain, */*',
                        'x-api-key': 'f05e4d2e20fb43b3bf390925a1e3253e',
                    },

                    success: function(res, stat, xhr) {
//&?
debugger
                        $.ajax({
                            type: 'GET',
                            processData: false,
                            contentType: false,
                            url: xhr.getResponseHeader('location'),
                            headers: {
                                'Authorization': 'Bearer ' + APIKEY,
                                'x-api-key': 'f05e4d2e20fb43b3bf390925a1e3253e',
                            },

                            success: function(data) {
//&?
debugger
                            }
                        });
                    }
                });

            };


            var pdffileBlobContract = new Blob(new Uint8Array(finalPdf), {type: 'application/pdf'});

            reader.readAsArrayBuffer(pdffileBlobContract);

Votes

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 ,
Dec 23, 2021 Dec 23, 2021

Copy link to clipboard

Copied

I found the problem - so this thread is resolved -- thank u

Votes

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 ,
Mar 17, 2022 Mar 17, 2022

Copy link to clipboard

Copied

Hello, It appears you are able to solve your problem, can you please share your fix?

 

Votes

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 ,
Mar 18, 2022 Mar 18, 2022

Copy link to clipboard

Copied

I actually used something else - never got this to work unfortunately

Votes

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 ,
Mar 18, 2022 Mar 18, 2022

Copy link to clipboard

Copied

Can you please share what did you use?

 

Votes

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 ,
Mar 18, 2022 Mar 18, 2022

Copy link to clipboard

Copied

LATEST

We are using jspdf library to build our pdfs, it has a compression switch where it will compress the pdfs it generates - works just as well as the adobe compression demo for our files so mission accomplished

Votes

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