Convert Microsoft Word to PDF in Nodejs with Embedded Fonts

Hi, How are you?
I have used libre-office to convert my docx files to pdf in nodejs app and it has some limitations, so I need to find another way to convert docx files.
I found this api and I think that it would be perfect for the docx conversions.
Now I have some problems with the pdf result.
Some of content(for example specific font) can not be converted as origin docx file, but instead it is converted with different font.
I attached the original docx file.
The converted pdf file must be same as origin docx file since this is for commercial purpose.
I would like to know if you can resolve this and also available for the further issues.

Thank you.bad.docx (42.6 KB)

@danyded

It seems you are using some custom fonts in DOCX to PDF conversion those are not available on our server. Please note when you convert Microsoft Word to PDF in Node.js with embedded fonts using GroupDocs.Converter Cloud API, you need to upload your custom fonts to a folder in the cloud storage and pass the folder path in the FontPath parameter.

You may follow these simple steps to convert Word to PDF without changing font in Node.js with GroupDocs.Converter Cloud API.

Steps to Convert Microsoft Word to PDF with Custom Fonts in Node.js

  1. Sign up with groupdocs.cloud and get the credentials
  2. Install GroupDocs.Conversion Cloud SDK for Node.js from NPM
  3. Create a script file for Node.js code
  4. Load the GroupDocs.Conversion Cloud SDK for Node.js module
  5. Upload your input DOCX file to cloud storage
  6. Upload your custom fonts to a cloud folder
  7. Initialize ConvertAPI with your credentials
  8. Create a ConvertSettings object and set the required parameters along with fontsPath parameter. Set it with the cloud folder path
  9. Create ConvertDocumentRequest object with the ConvertSettings
  10. Finally, call the convertDocument API method to convert the output PDF document on Cloud Storage with embedded fonts

Code to Convert Microsoft Word to PDF with Custom Fonts in Node.js


// load the module

var GroupDocs = require('groupdocs-conversion-cloud');

// get your clientId and clientSecret at https://dashboard.groupdocs.cloud (free registration is required).

var clientId = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx";

var clientSecret = "xxxxxxxxxxxxxxxxxxxxxxxxx";

// convert DOCX to PDF with custom fonts

const convert = async () => {

const convertApi = GroupDocs.ConvertApi.fromKeys(clientId, clientSecret);

const settings = new GroupDocs.ConvertSettings();

settings.filePath = "02_pages.docx";

settings.format = "pdf";

settings.outputPath = "02_pages.pdf";

settings.fontsPath = "font/ttf";

try {

const request = new GroupDocs.ConvertDocumentRequest(settings);

await convertApi.convertDocument(request);

} catch (err) {

throw err;

}

}

convert()

.then(() => {

console.log("document converted successfully");

})

.catch((err) => {

console.log("Error occurred while converting the document:", err);

})

Hopefully, it will help you to accomplish the task and feel free to contact us for any assistance in this regard.

Hi @tilal.ahmad

Thank you very much for your reply. I am using convertDocumentDirect method to convert docx files and in this case, how could I handle the options for specific fonts?

@danyded

Thanks for your feedback. I am afraid currently GroupDocs.Conversion Cloud does not support the use of custom fonts in ConvertDocumentDirect API method. We have logged a ticket CONVERSIONCLOUD-460 for your requirement. We will notify you as soon as it is resolved.

Hi, @danyded,
If we add an option, that will allow to use custom fonts in ConvertDocumentDirect method, but with requirement that font files must be uploaded to cloud storage, like in regular ConvertDocument method, would this be suitable for you?