Fonts not matching the Web viewer and NodeJS SDK

Product:
Webviewer and @pdftron/pdfnet-node

Trying to Convert xlsx file to PDF using nodejs ‘@pdftron/pdfnet-node’.
When I Convert the file using the demo env ‘Convert MS Office To PDF with JavaScript Demo | Apryse WebViewer’ The font which is showing different from what I converted using the nodejs SDK . When I downloaded the pdf file which is converted using the demo env of apryse , that downloaded file also changed to the font which I converted using nodejs SDK . Why there is discripancy while showing the file in the UI and download itself. I want the format of the file UI and converted file to be uniform across since we are using for annotation.
Attached the code reference as well as the diff in UI and converted PDF. Can you please let us know how to embed the fonts so that it can be uniform across the UI and conversion



1 Like

Hi Selvamani,

You can serve your custom fonts in the UI as you do for the Node-JS package.
Here is a guide for that:

Best Regards,
Ahmad Moaaz
Software Developer
Apryse

1 Like

Even I tried to create the docx file with the xlsx content and stored with the embedded fonts using word. Then I have provided the doc file as “PDFNet.AddResourceSearchPath()” and via “OfficeToPDFOptions.SetResourceDocPath()” Tried both . Its also not converting the PDF as it is .
Is “pdftron_smart_substitution.plugin” available for nodejs , if available can you please let me where to get the plugin for this.

Docx file with embedded fonts.
Followed this approach : Apryse Documentation | Documentation
Sample Excel :
Sample excel (3).xlsx (32.2 KB)

const resourceDocPath = '/Users/selvamani.g/Desktop/workspace/development/POC/pdftron/ts-office-to-pdf-converter/resources/FIL2.docx'

const flexibleDocxConvert = async (inputFilename, outputFilename) => {
  try{
    const pdfdoc = await PDFNet.PDFDoc.create();
    // Downloaded the font from https://pdftron.s3.amazonaws.com/downloads/SelfServeWebFontsV2.zip
    // Font is extracted and stored in the local
   
    const options = new PDFNet.Convert.OfficeToPDFOptions();
    options.setResourceDocPath(resourceDocPath)
    // options.setEnableExternalMediaDownloads(true)
    const conversion = await PDFNet.Convert.streamingPdfConversionWithPdfAndPath(
       pdfdoc , inputPath + inputFilename, options);
  
    while (await conversion.getConversionStatus() === PDFNet.DocumentConversion.Result.e_Incomplete) {
      await conversion.convertNextPage();  
      console.log('Status: ' + await conversion.getProgress() * 100 + '%, '
        + await conversion.getProgressLabel());
    }
  
    if (await conversion.getConversionStatus() === PDFNet.DocumentConversion.Result.e_Success) {
      const num_warnings = await conversion.getNumWarnings();
  
      for (let i = 0; i < num_warnings; ++i) {
        console.log('Conversion Warning: ' + await conversion.getWarningString(i));
      }
  
      await pdfdoc.save(outputPath + outputFilename, PDFNet.SDFDoc.SaveOptions.e_remove_unused);
      console.log('Saved ' + outputFilename);
    }
    else {
      console.log('Encountered an error during conversion: '
        + await conversion.getErrorString());
    }
  }catch(err){
    console.log(err)
  }

}
const main = async () => {
  try {  
    await PDFNet.initialize(PDFTronLicense)
    await PDFNet.addResourceSearchPath(resourceDocPath)

    // await PDFNet.WebFontDownloader.setCustomWebFontURL(`file://${fontPath}`)
    await flexibleDocxConvert('input_2.xlsx', 'Sample output embedded font new.pdf');

  } catch (err) {
    console.log(err);
  }

  console.log('Done.');
};

PDFNet.runWithCleanup(main, PDFTronLicense).catch(function (error) {
  console.log('Error: ' + JSON.stringify(error));
}).then(function () { return PDFNet.shutdown(); });
1 Like

Attaching the Output PDF we have received
output.pdf (136.6 KB)

1 Like

Hi Selvamani,

The only way to truly guarantee that the font will be preserved in by embedding the font directly. Unfortunately, MS Excel does not explicitly support embedding fonts. The following article explains why this is the case and proposes a workaround:

That said, without using some workaround to embed fonts within Excel, we cannot guarantee the proper font will be used.

1 Like

Hi,

According to the following documentation - Apryse Documentation | Documentation - Calling WebFontDownloader.setCustomWebFontURL and WebFontDownloader.enableDownloads allows the converter to download the fonts if the fonts are not available on the system where Excel to PDF conversion is being done using PDFNet SDK. Even if we call the APIs before calling the office2PDFBuffer API - the fonts are not downloaded and used. Is this expected behavior?

Just FYI - for webviewer - we are using Core.setCustomFontURL API passing the exact path as we pass to the WebFontDownloader.setCustomWebFontURL mentioned above and it is able to download the font and render the Excel correctly.

1 Like

The fonts files we are using are true type font file (TTF) not web open font format (WOFF) files.

1 Like

Hi there,

You mentioned above that you tried creating the DOCX file with XLSX content and stored the embedded fonts.
Instead, could you please try substituting the fonts with the DOCX file and then make the conversion to PDF?
Here is a forum post with a similar issue:

Best regards,
Kevin Kim

1 Like