We have noticed the reported issue and logged a ticket CONVERSIONCLOUD-504 for further investigation and rectification. We will notify you as soon as it is resolved.
Sure, I’m using this code to convert all my templates, I’m facing this issue only with the PDFs which contains more than 1 page.
// initialize api
let convertApi = groupdocs_conversion_cloud.ConvertApi.fromKeys(
clientId,
clientSecret
);
// define convert settings
let settings = new groupdocs_conversion_cloud.ConvertSettings();
let convertOptions = new groupdocs_conversion_cloud.DocxConvertOptions();
convertOptions.pageSize =
groupdocs_conversion_cloud.WordProcessingConvertOptions.PageSizeEnum.Custom;
settings.convertOptions = convertOptions;
settings.filePath = `${params.documentName}.pdf`; // input file path on the cloud
settings.format = 'docx'; // output format
settings.outputPath = 'output'; // output file folder on the cloud
console.log('Conerting PDF ... ');
// create convert document request
let request = new groupdocs_conversion_cloud.ConvertDocumentRequest(settings);
// console.log('request', request);
// convert document
let result = await convertApi.convertDocument(request);
Please let me know if we need to change any convert settings for more then one pages.
Thanks
I am afraid, I am still unable to reproduce the issue with test38.pdf. Can you please double check that you are using the latest version of the SDK?
test38_gd.docx (20.5 KB)
// load the module
var groupdocs_conversion_cloud = 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-xxxxxxxxx";
var appKey = "xxxxxxxxxxxxxxxxxxxxxxxx";
const convertDocument = async () => {
// construct Api
var convertApi = groupdocs_conversion_cloud.ConvertApi.fromKeys(appSid, appKey);
// define convert settings
let settings = new groupdocs_conversion_cloud.ConvertSettings();
let convertOptions = new groupdocs_conversion_cloud.DocxConvertOptions();
convertOptions.pageSize = groupdocs_conversion_cloud.WordProcessingConvertOptions.PageSizeEnum.Custom;
settings.convertOptions = convertOptions;
settings.filePath = 'test38.pdf'; // input file path on the cloud
settings.format = 'docx'; // output format
settings.outputPath = 'test38_gd.docx'; // output file folder on the cloud
console.log('Conerting PDF ... ');
try {
// create convert document request
let request = new groupdocs_conversion_cloud.ConvertDocumentRequest(settings);
// console.log('request', request);
// convert document
let result = await convertApi.convertDocument(request);
} catch (err) {
throw err;
}
}
convertDocument()
.then(() => {
console.log("Document converted successfully");
})
.catch((err) => {
console.log("Error occurred while converting the document:", err);
})
The issues you have found earlier (filed as CONVERSIONCLOUD-504) have been fixed in this update. This message was posted using Bugs notification tool by sergeiterentev
Hey, @tilal.ahmad
Thanks for the help but we’re still not able to convert our files successfully.
We’re using the exact same code for converting our word document but we figured the issue we are getting in uploading the PDF file to the Groupdocs storage.
We are using :
“groupdocs-conversion-cloud”: “^23.2.0”,
To upload the file to groupdocs storage we’re using this code:
const { fileBuffer, fileName } = convert_base64_to_file_buffer(params.file, params.documentName );
console.log('Uploading file to groupdocs server');
var fileApi = groupdocs_conversion_cloud.FileApi.fromConfig(conf);
var request = new groupdocs_conversion_cloud.UploadFileRequest(
fileName, //`${params.documentName}.pdf`
fileBuffer,
myStorage
);
// upload file
await fileApi.uploadFile(request).then((r) => {
if (r.uploaded[0]) {
console.log('Uploading successfully');
res.json({ msg: 'File uploaded' });
}
}).catch((err) => {
console.log(err);
console.log('err in uploading pdf to groupdocs server');
});
Specifically, We’re getting error in “fileApi.uploadFile” function, the request is not getting successful and we’re catching the error in the catch block.
We do not get this everytime, but we get this error sometime from the API call.
We have checked multiple times the PDF we’re sending as payload in upload API call, The PDF is fine always but most of the time we get error form the API call.
We’re getting this error from the File Upload API :
Groupdocs Error Image (19.4 KB)
The flow that we’re using to convert PDF to word is to
- First upload the PDF in the Groupdocs storage.
- Then call the “ConvertDocumentRequest” API to convert the upload PDF in the Groupdocs storage.
- Then download the converted file.
We suppose, we’re getting error most of the times in the first step to upload the PDF to Groupdocs storage.
If we have any way to send the PDF while calling “ConvertDocumentRequest” API, then I think we do not have to use File upload API to groupdocs server and it may work fine.
We’re attaching our code that we’re using to first upload the PDF to groupdocs server and then converting it into docx.:
async function uploadFile(params, res, next) {
console.log('Converting base64 to fileBuffer');
const { fileBuffer, fileName } = convert_base64_to_file_buffer(
params.file,
params.documentName
);
console.log('Uploading file to groupdocs server');
var fileApi = groupdocs_conversion_cloud.FileApi.fromConfig(conf);
var request = new groupdocs_conversion_cloud.UploadFileRequest(
fileName, //`${params.documentName}.pdf`
fileBuffer,
myStorage
);
// upload file
await fileApi
.uploadFile(request)
.then((r) => {
if (r.uploaded[0]) {
console.log('Uploading successfully');
res.json({ msg: 'File uploaded' });
}
})
.catch((err) => {
console.log(err);
console.log('err in uploading pdf to groupdocs server');
});
}
async function convertPdfToWord(params, callback) {
console.log('Initializing API ... ');
// initialize api
let convertApi = groupdocs_conversion_cloud.ConvertApi.fromKeys(
clientId,
clientSecret
);
// define convert settings
let settings = new groupdocs_conversion_cloud.ConvertSettings();
let convertOptions = new groupdocs_conversion_cloud.DocxConvertOptions();
convertOptions.pageSize =
groupdocs_conversion_cloud.WordProcessingConvertOptions.PageSizeEnum.Custom;
settings.convertOptions = convertOptions;
settings.filePath = `${params.documentName}.pdf`; // input file path on the cloud
settings.format = 'docx'; // output format
settings.outputPath = 'output'; // output file folder on the cloud
console.log('Conerting PDF ... ');
// create convert document request
let request = new groupdocs_conversion_cloud.ConvertDocumentRequest(settings);
// convert document
let result = await convertApi.convertDocument(request).then(() => {
console.log('Converted successfully');
});
// console.log('Document converted successfully: ' + result[0].url);
callback();
}
async function convertPdfAndDownload(params, res, next) {
convertPdfToWord(params, async () => {
// construct FileApi
var fileApi = groupdocs_conversion_cloud.FileApi.fromConfig(conf);
// create download file request
let req = new groupdocs_conversion_cloud.DownloadFileRequest(
`output/${params.documentName}.docx`,
myStorage
);
// download file
await fileApi
.downloadFile(req)
.then((r) => {
res.json({ buffer: r });
})
.catch((err) => {
console.log('err in downloading word file from groupdocs');
next(err);
});
});
}
Please let us know if there is any way we can directly upload the PDF in the "ConvertDocumentRequest’ API and get the converted docx in return or if there is any other way to fix this.
Thanks.
I am afraid I am unable to reproduce the upload file issue. You can use the ConvertDocumentDirect API method
to convert a file from the request body, without storage. Please check the following documentation for more details.
I tried using ConvertDocumentDirect API method , but getting this error
{
message: 'Internal error: Cannot convert. The file is corrupt or damaged. Pdf document reader plugin cannot be loaded. Make sure Aspose.Words.Pdf2Word.dll is referenced in your project and placed next to Aspose.Words.dll',
code: 'internalError'
}
This is our code :
const groupdocs_conversion_cloud = require('groupdocs-conversion-cloud');
let convertApi = groupdocs_conversion_cloud.ConvertApi.fromKeys(
clientId,
clientSecret
);
var { fileBuffer, fileName } = convert_base64_to_file_buffer(req.body.file,req.body.documentName);
console.log('🚀OUTPUT --> fileBuffer:', fileBuffer);
let loadOptions = new groupdocs_conversion_cloud.DocxLoadOptions();
loadOptions.format = 'docx';
let request = new groupdocs_conversion_cloud.ConvertDocumentDirectRequest(
'pdf',
fileBuffer,
undefined,
undefined,
loadOptions
);
console.log('🚀OUTPUT --> request:', request);
await convertApi
.convertDocumentDirect(request)
.then((res) => {
console.log('Converted successfully');
console.log('🚀OUTPUT --> res:', res);
})
.catch((err) => {
console.log(err);
});
I tried uploading this tes.pdf (5.3 KB) file from directory also and that also gave same error. I’m sure the file we’re passing is correct but still we’re getting this error.
Please let me know, if there is any problem with the code or anything else.
Thanks.
Please pay attention you are converting PDF to DOCX. So loadOptions should be PdfLoadOptions and format in the ConvertDocumentDirectRequest should be docx
as following. Hopefully, it will help you to accomplish the task.
const convertOptions = new GroupDocs.DocxConvertOptions();
const file = fs.readFileSync('C:/Temp/tes.pdf');
const localPath = "C:/Temp/tes.docx";
try {
let request = new GroupDocs.ConvertDocumentDirectRequest("docx",file,undefined,undefined,undefined,convertOptions);
We’ve updated the code as suggested, but still getting error from server while converting document.
It worked sometimes but then gives this error while converting.
this is the error we’re getting :
{
message: 'Error while parse server error: SyntaxError: Unexpected end of JSON input'
}
This is our updated code :
var { fileBuffer, fileName } = convert_base64_to_file_buffer(
req.body.file,
req.body.documentName
);
console.log('🚀OUTPUT --> fileBuffer:', fileBuffer);
let loadOptions = new groupdocs_conversion_cloud.PdfLoadOptions();
loadOptions.format = 'pdf';
let convertOptions = new groupdocs_conversion_cloud.ConvertOptions();
convertOptions.pageSize =
groupdocs_conversion_cloud.WordProcessingConvertOptions.PageSizeEnum.Custom;
let request = new groupdocs_conversion_cloud.ConvertDocumentDirectRequest(
'docx',
fileBuffer,
undefined,
undefined,
loadOptions,
convertOptions
);
await convertApi
.convertDocumentDirect(request)
.then((resp) => {
console.log('Converted successfully');
console.log('🚀OUTPUT --> res:', resp);
res.json({ buffer: resp });
})
.catch((err) => {
console.log(err);
console.log('err in converting file');
});
I have again tested the scenario using the following code. Please check whether you are reading the file correctly using the convert_base64_to_file_buffer method. You may also try to read the sample file from your local drive directly and check the result.
const convertDocumentOnline = async () => {
// construct Api
const api = GroupDocs.ConvertApi.fromKeys(appSid, appKey);
//const convertOptions = new GroupDocs.DocxConvertOptions();
const file = fs.readFileSync('C:/Temp/tes.pdf');
const localPath = "C:/Temp/tes.docx";
let loadOptions = new GroupDocs.PdfLoadOptions();
loadOptions.format = 'pdf';
let convertOptions = new GroupDocs.ConvertOptions();
convertOptions.pageSize = GroupDocs.WordProcessingConvertOptions.PageSizeEnum.Custom;
try {
let request = new GroupDocs.ConvertDocumentDirectRequest("docx",file,undefined,undefined,loadOptions,convertOptions);
console.log(request);
let result = await api.convertDocumentDirect(request);
//console.log(result);
fs.writeFileSync(localPath, result);
} catch (err) {
throw err;
}
}
convertDocumentOnline()
.then(() => {
console.log("Document converted successfully");
})
.catch((err) => {
console.log("Error occurred while converting the document:", err);