Nur bestimmte Unicode Zeichen während des Speicherns in PDF ändern

Beispiel

Der folgende Screenshot vergleicht die beiden Ausgabepdf-Dateien, die vom unten stehenden Beispielcode erstellt wurden.

Es gibt ein PDF ohne Einstellung der Eigenschaft PdfSaveOptions.isFontSubstitutionCharGranularity und ein anderes, nachdem diese auf true gesetzt wurde.

Wie Sie im ersten PDF sehen können, hat sich die Schriftart des gesamten Satzes von Times New Roman zu Arial Unicode MS geändert, wegen des Nicht-Brechenden Gedankenstrichs. Im zweiten PDF hat sich nur die Schriftart des Nicht-Brechenden Gedankenstrichs geändert.

Erste PDF-Datei
todo:image_alt_text
Zweite PDF-Datei
todo:image_alt_text

Beispielcode

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);