قم بتغيير الخط على أحرف Unicode المحددة فقط أثناء الحفظ في PDF
لا يمكن عرض بعض أحرف Unicode بواسطة الخط المحدد من قبل المستخدم. أحد هذه الأحرف Unicode هوواصلة غير فاصلة (U + 2011) ورقم Unicode الخاص به هو 8209. لا يمكن عرض هذا الحرف معتايمز نيو رومان ، ولكن يمكن عرضها مع خطوط أخرى مثلArial Unicode MS.
عندما يحدث مثل هذا الحرف داخل بعض الكلمات أو الجمل الموجودة في خط معين مثل Times New Roman ، فإن Aspose.Cells يغير خط الكلمة أو الجملة بأكملها إلى الخط الذي يمكن أن يعرض هذا الحرف مثل Arial Unicode إلى MS.
ومع ذلك ، يعد هذا سلوكًا غير مرغوب فيه لبعض المستخدمين ويريدون فقط تغيير خط الحرف المحدد بدلاً من تغيير خط الكلمة أو الجملة بأكملها.
للتعامل مع هذه المشكلة ، يوفر Aspose.CellsPdfSaveOptions.setFontSubstitutionCharGranularity () الخاصية التي يجب تعيينهاحقيقي بحيث يتم تغيير خط الحرف المحدد غير القابل للعرض فقط ويظل خط بقية الكلمة أو الجملة كما هو.
مثال
تقارن لقطة الشاشة التالية بين ملفي PDF الناتج اللذين تم إنشاؤهما بواسطة نموذج التعليمات البرمجية أدناه. تم إنشاء واحد بدون تحديدPdfSaveOptions.setFontSubstitutionCharGranularity () الخاصية والآخر تم إنشاؤه بعد تعيينPdfSaveOptions.setFontSubstitutionCharGranularity () ملكية لحقيقي. كما ترى في أول PDF ، تم تغيير خط الجملة بأكملها من Times New Roman إلى Arial Unicode MS بسبب واصلة غير فاصلة. بينما في PDF الثاني ، تم تغيير خط Non-Breaking Hyphen فقط.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ChangeFontonspecificUnicodecharacters.class); | |
// Create workbook object | |
Workbook workbook = new Workbook(); | |
// Access the first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Access cells | |
Cell cell1 = worksheet.getCells().get("A1"); | |
Cell cell2 = worksheet.getCells().get("B1"); | |
// Set the styles of both cells to Times New Roman | |
Style 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" + (char) (8209) + " with Non-Breaking Hyphen"); | |
// Autofit the columns | |
worksheet.autoFitColumns(); | |
// Save to Pdf without setting PdfSaveOptions.IsFontSubstitutionCharGranularity | |
workbook.save(dataDir + "output.pdf"); | |
// Save to Pdf after setting PdfSaveOptions.IsFontSubstitutionCharGranularity to true | |
PdfSaveOptions opts = new PdfSaveOptions(); | |
opts.setFontSubstitutionCharGranularity(true); | |
workbook.save(dataDir + "output2.pdf", opts); | |