I am using it in nodeJs to convert .docx to .pdf and its taking too long (more then one minute) to do that . can anyone help me out ??
Please share your sample code along with input document. We will look into the issue and share our findings with you.
import {
DocxLoadOptions,
ConvertApi,
ConvertDocumentDirectRequest,
} from "groupdocs-conversion-cloud";
const clientId: string = process.env.GROUPDOCS_CLOUD_CLIENT_ID;
const clientSecret: string = process.env.GROUPDOCS_CLOUD_CLIENT_SECRET;
const convertApi = ConvertApi.fromKeys(clientId, clientSecret);
const convertDocxToPDF = async (docxContent) => {
try {
const format = "pdf";
const loadOptions = new DocxLoadOptions();
loadOptions.format = "docx";
const request = new ConvertDocumentDirectRequest(
format,
docxContent,
undefined,
undefined,
loadOptions,
undefined
);
// Is taking approximately 1 minute on local machine -- Unacceptable
const response = await convertApi.convertDocumentDirect(request);
return response;
} catch (err) {
throw new Error(`[convertDocxToPDF] -- ${err.message}`);
}
};
export { convertDocxToPDF };
Input file
job-offer-letter - Copy.docx (5.6 KB)
Please ensure you are using the latest version of the GroupDocs.Conversion Cloud SDK for Node.js. As it is taking less than 10 seconds for the conversion of your shared DOCX file.
// load the module
var GroupDocs = require('groupdocs-conversion-cloud');
var fs = require('fs');
// get your appSid and appKey at https://dashboard.groupdocs.cloud (free registration is required).
var appSid = "xxxxxx-xxxx-xxxx-xxxx-xxxxxxxx";
var appKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
const convertDocument = async () => {
// construct Api
var convertApi = GroupDocs.ConvertApi.fromKeys(appSid, appKey);
try {
const format = "pdf";
const loadOptions = new GroupDocs.DocxLoadOptions();
const docxContent = fs.readFileSync('job-offer-letter - Copy.docx');
loadOptions.format = "docx";
const request = new GroupDocs.ConvertDocumentDirectRequest(
format,
docxContent,
undefined,
undefined,
loadOptions,
undefined);
// convert document directly
const result = await convertApi.convertDocumentDirect(request);
console.log(result);
fs.writeFileSync("output.pdf", result);
} catch (err) {
throw err;
}
}
convertDocument()
.then(() => {
console.log("Document converted successfully");
})
.catch((err) => {
console.log("Error occurred while converting the document:", err);
})
Hey thanks , Can you tell me what is the version that you are using ??
And also i am not using fs module i am directly passing buffer to it . Is that fine ??
I used GroupDocs.Conversion Cloud Sdk for Node.js 23.6.
In reference to pasaing a buffer, I don’t think so it would be an issue. Please try the latest SDK version and confirm.
Hey Sorry for late reply,
I have update the SDK as well but its still taking time .
image.png (29.4 KB)
It’s not working for us. and because netlify has a timeout limit of 10 seconds, we cannot use it.
Can you please check this on another machine? As it is taking ~10 second on my machine.
we’ve tested on 2 separate machines and the request we’ve seen is from netlify lambda function.
Can you please share your code as well ??
Please find below my sample code.
// load the module
var GroupDocs = require('groupdocs-conversion-cloud');
var fs = require('fs');
// get your appSid and appKey at https://dashboard.groupdocs.cloud (free registration is required).
var appSid = "xxxxxx-xxxx-xxxx-xxxx-xxxxxxxx";
var appKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
const convertDocument = async () => {
// construct Api
var convertApi = GroupDocs.ConvertApi.fromKeys(appSid, appKey);
try {
const format = "pdf";
const loadOptions = new GroupDocs.DocxLoadOptions();
const docxContent = fs.readFileSync('job-offer-letter - Copy.docx');
loadOptions.format = "docx";
const request = new GroupDocs.ConvertDocumentDirectRequest(
format,
docxContent,
undefined,
undefined,
loadOptions,
undefined);
// convert document directly
const result = await convertApi.convertDocumentDirect(request);
console.log(result);
fs.writeFileSync("output.pdf", result);
} catch (err) {
throw err;
}
}
convertDocument()
.then(() => {
console.log("Document converted successfully");
})
.catch((err) => {
console.log("Error occurred while converting the document:", err);
})
Thanks will test it out and report back
Hey @tilal.ahmad,
We tested the conversion out with your code using the docx file I’m attaching in this comment. I did 4 tests, and out of which only 2 had a response time of 28 seconds the other two were 2min 37 seconds and 3mins 24 seconds respectively.
temporary.docx (6.9 MB)
Anything you think might be weird here? Or any other recommendations you might have?
Version of node module is 23.6
Yes, your above document(temorary.docx) conversion is taking more than one minute at my side. There are many factors that matter in document processing: document structure, document size and server resource availability. You may try self hosting the GroupDocs.Conversion Cloud API on your own server using a Docker container. Hopefully, it will help you control the processing time yourself.