تغيير نوع الخط على أحرف يونيكود محددة عند الحفظ إلى PDF باستخدام Python.NET
بعض أحرف يونيكود غير قابلة للعرض بواسطة الخطوط المحددة من قبل المستخدم. أحد هذه الأحرف هو الشرطة غير المتماسكة (U+2011) برقم يونيكود 8209. لا يمكن عرض هذا الحرف مع Times New Roman ولكن يمكن عرضه مع خطوط مثل Arial Unicode MS.
عندما تظهر مثل هذه الأحرف في نص منسق باستخدام خط معين (مثل Times New Roman)، يقوم Aspose.Cells تلقائيًا بتغيير خط الكلمة/الجملة بأكملها إلى خط متوافق (مثل Arial Unicode MS). للمستخدمين الذين يرغبون في تغيير خط الحرف غير القابل للعرض فقط، نوفر تحكمًا دقيقًا من خلال الخاصية PdfSaveOptions.is_font_substitution_char_granularity.
مقارنة أمثلة
تعرض لقطات الشاشة أدناه المخرجات مع إعدادات مختلفة. يُظهر ملف PDF الأول استبدال الخط الكامل للنص، بينما يغير الملف الثاني خط الحرف المحدد فقط.
الاستبدال الكامل للنص | الاستبدال على مستوى الحرف |
---|---|
![]() |
![]() |
خطوات التنفيذ
لتمكين استبدال الخط على مستوى الحرف:
- إنشاء كائن Workbook
- الوصول إلى خلايا ورقة العمل باستخدام خاصية Worksheet.cells
- تعيين قيم الخلايا التي تحتوي على رموز يونيكود خاصة
- تكوين PdfSaveOptions مع:
is_font_substitution_char_granularity = True
- حفظ ملف العمل بامتداد PDF
import os
from aspose.cells import Workbook, PdfSaveOptions
# For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
current_dir = os.path.dirname(os.path.abspath(__file__))
data_dir = os.path.join(current_dir, "data")
if not os.path.exists(data_dir):
os.makedirs(data_dir)
# Create workbook object
workbook = Workbook()
# Access the first worksheet
worksheet = workbook.worksheets[0]
# Access cells
cell1 = worksheet.cells.get("A1")
cell2 = worksheet.cells.get("B1")
# Set the styles of both cells to Times New Roman
style = cell1.get_style()
style.font.name = "Times New Roman"
cell1.set_style(style)
cell2.set_style(style)
# Put the values inside the cell
cell1.put_value("Hello without Non-Breaking Hyphen")
cell2.put_value("Hello" + chr(8209) + " with Non-Breaking Hyphen")
# Autofit the columns
worksheet.auto_fit_columns()
# Save to Pdf without setting PdfSaveOptions.is_font_substitution_char_granularity
workbook.save(os.path.join(data_dir, "SampleOutput_out.pdf"))
# Save to Pdf after setting PdfSaveOptions.is_font_substitution_char_granularity to true
opts = PdfSaveOptions()
opts.is_font_substitution_char_granularity = True
workbook.save(os.path.join(data_dir, "SampleOutput2_out.pdf"), opts)
مفتاح التكوين
استخدم مكونات واجهة برمجة التطبيقات الأساسية التالية:
- فئة PdfSaveOptions لإعدادات عرض PDF
- خاصية is_font_substitution_char_granularity لاستبدال الخطوط على مستوى الأحرف
- طريقة Workbook.save لإنشاء المخرجات
is_font_substitution_char_granularity
) بدلاً من PascalCase المستخدمة في .NET.