Ändra typsnittet på endast de specifika Unicode tecknen när du sparar till PDF med Node.js via C++

Exempel

Följande skärmbild jämför de två utdata-PDF:erna som genererats av koden nedan.

En genereras utan att ställa in PdfSaveOptions.isFontSubstitutionCharGranularity egenskapen och den andra genererades efter att ha ställt in egenskapen PdfSaveOptions.isFontSubstitutionCharGranularity till true.

Som du kan se i den första PDF:en har hela meningen ändrats från Times New Roman till Arial Unicode MS på grund av icke-brytande bindestrecket. I den andra PDF:en har endast tecknet icke-brytande bindestrecket ändrats.

Första PDF-filen
todo:image_alt_text
Andra PDF-filen
todo:image_alt_text

Exempelkod

const path = require("path");
const AsposeCells = require("aspose.cells.node");

// The path to the documents directory.
const dataDir = path.join(__dirname, "data");

// Create workbook object
const workbook = new AsposeCells.Workbook();

// Access the first worksheet
const worksheet = workbook.getWorksheets().get(0);

// Access cells
const cell1 = worksheet.getCells().get("A1");
const cell2 = worksheet.getCells().get("B1");

// Set the styles of both cells to Times New Roman
let style = cell1.getStyle();
style.getFont().setName("Times New Roman");
cell1.setStyle(style);
cell2.setStyle(style);

// Put the values inside the cell
cell1.putValue("Hello without Non-Breaking Hyphen");
cell2.putValue("Hello" + String.fromCharCode(8209) + " with Non-Breaking Hyphen");

// Autofit the columns
worksheet.autoFitColumns();

// Save to Pdf without setting PdfSaveOptions.IsFontSubstitutionCharGranularity
workbook.save(path.join(dataDir, "SampleOutput_out.pdf"));

// Save to Pdf after setting PdfSaveOptions.IsFontSubstitutionCharGranularity to true
const opts = new AsposeCells.PdfSaveOptions();
opts.setIsFontSubstitutionCharGranularity(true);
workbook.save(path.join(dataDir, "SampleOutput2_out.pdf"), opts);