Ändra teckensnittet på bara de specifika Unicode-tecken samtidigt som du sparar till PDF

Exempel

Följande skärmdump jämför de två utgående PDF-filerna som genereras av exempelkoden nedan.

Den ena genereras utan att ställa in egenskapen PdfSaveOptions.IsFontSubstitutionCharGranularity och den andra genererades efter att egenskapen PdfSaveOptions.IsFontSubstitutionCharGranularity ställdes in på true.

Som du kan se i den första pdf-filen har teckensnittet för hela meningen ändrats från Times New Roman till Arial Unicode MS på grund av Non-Breaking Hyphen. Medan i den andra PDF-filen har bara teckensnittet för Non-Breaking Hyphen ändrats.

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

Exempelkod

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