ฉันต้องใส่ข้อมูลรายการของฉันลงในตารางในไฟล์ pdf ข้อมูลของฉันมีคำภาษาอาหรับบางคำ เมื่อไฟล์ PDF ของฉันถูกสร้างขึ้น คำภาษาอาหรับจะไม่ปรากฏขึ้น ฉันค้นหาและพบว่าฉันต้องการ itext7.pdfcalligraph ดังนั้นฉันจึงติดตั้งลงในแอปของฉัน ฉันพบรหัสนี้เช่นกัน https://itextpdf.com/en/blog/technical-notes/displaying-text-different-languages-single-pdf-document และพยายามทำสิ่งที่คล้ายกันเพื่อให้มีคำภาษาอาหรับในตารางของฉัน แต่ฉันคิดไม่ออก ออก.
นี่คือรหัสทดลองใช้ก่อนที่ฉันจะนำไปใช้กับรายการจริงของฉัน:
var path2 = global::Android.OS.Environment.ExternalStorageDirectory.AbsolutePath;
filePath = System.IO.Path.Combine(path2.ToString(), "myfile2.pdf");
stream = new FileStream(filePath, FileMode.Create);
PdfWriter writer = new PdfWriter(stream);
PdfDocument pdf2 = new iText.Kernel.Pdf.PdfDocument(writer);
Document document = new Document(pdf2, PageSize.A4);
FontSet set = new FontSet();
set.AddFont("ARIAL.TTF");
document.SetFontProvider(new FontProvider(set));
document.SetProperty(Property.FONT, "Arial");
string[] sources = new string[] { "يوم","شهر 2020" };
iText.Layout.Element.Table table = new iText.Layout.Element.Table(2, false);
foreach (string source in sources)
{
Paragraph paragraph = new Paragraph();
Bidi bidi = new Bidi(source, Bidi.DirectionDefaultLeftToRight);
if (bidi.BaseLevel != 0)
{
paragraph.SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT);
}
paragraph.Add(source);
table.AddCell(new Cell(1, 1).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER).Add(paragraph));
}
document.Add(table);
document.Close();
ฉันอัปเดตโค้ดและเพิ่ม arial.ttf ลงในโฟลเดอร์ทรัพย์สินของฉัน ฉันได้รับข้อยกเว้นต่อไปนี้:
System.InvalidOperationException: 'FontProvider และ FontSet ว่างเปล่า ไม่สามารถแก้ไขชื่อตระกูลฟอนต์ได้ (ดู ElementPropertyContainer#setFontFamily) โดยไม่ต้องเตรียมใช้งาน FontProvider (ดู RootElement#setFontProvider) และฉันก็ยังคิดไม่ออก มีความคิดอะไรบ้าง? ขอบคุณล่วงหน้า
tableItems
ที่ไม่ได้กำหนด เช่นเดียวกับรหัสความคิดเห็นที่ซ้ำซ้อนtextView
,Toast
,Rsultitem
- person Alexey Subach   schedule 07.09.2020FontProvider and FontSet are empty.
ตรวจสอบค่าส่งคืนของset.AddFont("ARIAL.TTF")
- ตามเอกสารประกอบ วิธีการส่งคืนtrue
ในกรณีที่เพิ่มแบบอักษรสำเร็จ และfalse
มิฉะนั้น - person Alexey Subach   schedule 08.09.2020set2.AddFont("C:\\Windows\\Fonts\\Arial.TTF");
แต่ก็ยังเหมือนเดิม ฉันควรทำอย่างไรดี? - person rana hd   schedule 08.09.2020new File("C:\\Windows\\Fonts\\Arial.TTF").exists()
คืนค่าจริงหรือเท็จ - person Alexey Subach   schedule 10.09.2020