Modifier la police uniquement des caractères Unicode spécifiques lors de l enregistrement en PDF

Exemple

La capture d’écran suivante compare les deux fichiers PDF générés par le code d’exemple ci-dessous.

L’un est généré sans définir la propriété PdfSaveOptions.IsFontSubstitutionCharGranularity et l’autre a été généré après avoir défini la propriété PdfSaveOptions.IsFontSubstitutionCharGranularity sur true.

Comme vous pouvez le voir dans le premier PDF, la police de la phrase entière a été modifiée de Times New Roman à Arial Unicode MS en raison du tiret non sécable. Tandis que dans le deuxième PDF, seule la police du tiret non sécable a été modifiée.

Premier fichier PDF
todo:image_alt_text
Deuxième fichier PDF
todo:image_alt_text

Code d’exemple

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Create workbook object
Workbook workbook = new Workbook();
// Access the first worksheet
Worksheet worksheet = workbook.Worksheets[0];
// Access cells
Cell cell1 = worksheet.Cells["A1"];
Cell cell2 = worksheet.Cells["B1"];
// Set the styles of both cells to Times New Roman
Style style = cell1.GetStyle();
style.Font.Name = "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" + Convert.ToChar(8209) + " with Non-Breaking Hyphen");
// Autofit the columns
worksheet.AutoFitColumns();
// Save to Pdf without setting PdfSaveOptions.IsFontSubstitutionCharGranularity
workbook.Save(dataDir + "SampleOutput_out.pdf");
// Save to Pdf after setting PdfSaveOptions.IsFontSubstitutionCharGranularity to true
PdfSaveOptions opts = new PdfSaveOptions();
opts.IsFontSubstitutionCharGranularity = true;
workbook.Save(dataDir + "SampleOutput2_out.pdf", opts);