PDF.co API for Word to PDF Conversion and Parsing
Hello,
I am posting this topic here because the developer community has been so helpful in the past. We have been attempting to work with PDF.co to get an answer on some issues we're having, but there must be a time zone delay, and there's just been a lot of back and forth, rather than an actual resolution. Here is what we're attempting to do:
- Download a .docx file from a custom module's attachments
- Obtain a pre-signed URL from PDF.co (they're using AWS) to work with the file
- URL response - url to access uploaded file
- Presigned URL - used to upload local file
- Upload the .docx file to AWS with the pre-signed URL
- Convert the .docx file to a PDF using the PDF.co endpoint and the URL obtained from the pre-signed URL upload
- Parse the PDF and return as JSON to our deluge custom function
- We then iterate through it and do the things we need to do
A couple more notes before we get into the code:
- We tried to convert the .docx file to a PDF using the Zoho Writer API and found that cell borders disappeared causing issues with the parsing at PDF.co. BUT, everything else worked great, including uploading the PDF to the pre-signed URL.
- We attempted to upload the file to PDF.co's built in storage, rather than the pre-signed URL, but when we download the file, and then attempt to pass it as a parameter, we get an error saying the file parameter is missing. We believe this is because the upload endpoint wants the file path. We don't know how to get that or if we even can get that from Zoho.
- The pre-signed URL endpoint worked for us when we uploaded the Zoho converted PDF file.
Okay, on to the code. Thanks in advance for your help and grace with this far from perfect code! I have omitted the parsing code since we're getting hung up before then.
- thisRec = zoho.crm.getRecordById("Meeting_Details",thisRecId);
- accountId = thisRec.get("Account").get("id");
- newList = List();
- //Get all attachments on meeting detail rec
- response = invokeurl
- [
- url :"https://www.zohoapis.com/crm/v6/Meeting_Details/" + thisRecId + "/Attachments?fields=id,Owner,File_Name,Created_Time,Parent_Id&sort_order=desc&sort_by=Created_Time"
- type :GET
- connection:"******"
- ];
- // info response;
- responseNull = response.isNull();
- info "Attachment Response Empty: " + responseNull;
- if(responseNull == true)
- {
- info "No Attachments to parse";
- return;
- }
- //Get last uploaded file
- fileRec = response.get("data").get(0);
- info "File Rec: " + fileRec;
- fileId = fileRec.get("id");
- info "File ID: " + fileId;
- fileName = fileRec.get("File_Name");
- info "File Name: " + fileName;
- createdTime = fileRec.get("Created_Time");
- info "Created Time: " + createdTime;
- //Download File from Meeting Detail Rec
- downloadResponse = invokeurl
- [
- url :"https://www.zohoapis.com/crm/v6/Meeting_Details/" + thisRecId + "/Attachments/" + fileId
- type :GET
- connection:"******"
- ];
- info downloadResponse;
- fileCheck = downloadResponse.isFile();
- info "File? " + fileCheck;
- //
- //PDF.co Headers
- apiKey = "*******************";
- headers = Map();
- headers = {"x-api-key":apiKey};
- // Upload Permission
- setupFileUpload = invokeurl
- [
- url :"https://api.pdf.co/v1/file/upload/get-presigned-url?name=" + fileName + "&encrypt=false"
- type :GET
- headers:headers
- detailed:true
- ];
- setupFileUpload = setupFileUpload.get("responseText");
- // info "File Upload Response: " + setupFileUpload;
- uploadUrl = setupFileUpload.get("presignedUrl");
- info "Upload URL: " + uploadUrl;
- workingFileUrl = setupFileUpload.get("url");
- info "Working URL: " + workingFileUrl;
- // Actual Upload
- uploadHeaders = Map();
- uploadHeaders.put("x-api-key",apiKey);
- uploadHeaders.put("Content-Type","application/octet-stream");
- uploadParams = Map();
- uploadParams.put("file",downloadResponse);
- uploadParams.put("expiration",20);
- uploadParams.put("async","true");
- actualUpload = invokeurl
- [
- url :uploadUrl
- type :PUT
- parameters:uploadParams
- headers:uploadHeaders
- detailed:true
- ];
- info "Actual Upload: " + actualUpload;
- //
- //Convert to PDF
- conversionURL = "https://api.pdf.co/v1/pdf/convert/from/doc";
- conversionHeader = Map();
- conversionHeader.put("x-api-key",apiKey);
- conversionHeader.put("Content-Type","application/json");
- conversionPayload = {"url":workingFileUrl,"async":false,"inline":"true","password":"","profiles":""};
- conversionResult = invokeurl
- [
- url :conversionURL
- type :POST
- parameters:conversionPayload
- headers:conversionHeader
- detailed:true
- ];
- info "Conversion Result: " + conversionResult;
- convertedDocURL = conversionResult.get("responseText").get("url");
- info "Converted Doc URL: " + convertedDocURL;
We believe the issue is happening on the upload to the pre-signed URL. Once we upload the file 66-74, we then use the workingFileURL to look at the document. We are able to download, but have to use Word's recovery tool as it's corrupted. The code continues and it converts the file to a PDF, but it is unintelligible.
Thanks so much for your help!
Zoho Desk Resources
-
Desk Community Learning Series
-
-
-
-
-
-
-
-
-
Sticky Posts
Zoho CRM Functions 53: Automatically name your Deals during lead conversion.
Welcome back everyone! Last week's function was about automatically updating the recent Event date in the Accounts module. This week, it's going to be about automatically giving a custom Deal name whenever a lead is converted. Business scenario Deals are the most important records in CRM. After successful prospecting, the sales cycle is followed by deal creation, follow-up, and its subsequent closure. Being a critical function of your sales cycle, it's good to follow certain best practices. One such
Custom Function : Automatically send the Quote to the related contact
Scenario: Automatically send the Quote to the related contact. We create Quotes for customers regularly and when we want to send the quote to the customer, we have to send it manually. We can automate this, using Custom Functions. Based on a criteria, you can trigger a workflow rule and the custom function associated to the rule and automatically send the quote to customer through an email. Please note that the quote will be sent as an inline email content and not as a PDF attachment. Please follow
Function #50: Schedule Calls to records
Welcome back everyone! Last week's function was about changing ownership of multiple records concurrently. This week, it's going to be about scheduling calls for records in various modules. Business scenario Calls are an integral part of most sales routines.. Sales, Management, Support, all the branches of the business structure would work in cohesion only through calls. You could say they are akin to engine oil, which is required by the engine to make all of it's components function perfectly. CRM
Function #37: Create a Purchase Order from a Quote
Welcome back everyone! Last week, we learnt how to calculate the total number of activities for a lead and further take note of the activity count for particular dates. For instance, from the period of Demo to Negotiation. This week, let's look at a function that lets you create a Purchase Order instantly from a Quote. Business scenario: In any form of business, one of the most important things to do is to document the transactions. Naturally, negotiation, signing an agreement, placing an order,
Function-2: Round-Robin assignment of records
Welcome back folks! Last week, we saw how to update sales commission in quotes using a custom function. This week, let's see an interesting use case asked by many of you - auto-assignment records by round-robin method. Business scenario: Right now, the solution allows you to auto-assign leads from web form and imported lists. Let us look at a need where you want to auto-assign leads from in-bound calls in a round-robin method, across modules. Prerequisite: You must create a permanent record in the
Zoho CRM Plus Resources
Zoho Books Resources
Zoho Subscriptions Resources
Zoho Projects Resources
Zoho Sprints Resources
Zoho Orchestly Resources
Zoho Creator Resources
Zoho WorkDrive Resources
Zoho Campaigns Resources
Zoho CRM Resources
Writer Get Started. Write Away!
Writer is a powerful online word processor, designed for collaborative work.