Search code examples
pdfitext7

iText 7 Chinese characters and merge with existing pdf template


I have to rephrase my question, basically my request is very straight forward, i want to display Asian characters in the generated pdf file from iText7.

As of now i have download the NotoSansCJKsc-Regular.otf file and assign a variable to hold the path, below is my code:

public static string FONT = @"D:\Projects\Resources\NotoSansCJKsc-Regular.otf";

PdfWriter writer = new PdfWriter(@"C:\temp\test.pdf");
PdfDocument pdfDoc = new PdfDocument(writer);
Document doc = new Document(pdfDoc, PageSize.A4);

PdfFont fontChinese = PdfFontFactory.CreateFont(FONT, PdfEncodings.IDENTITY_H);
doc.SetFont(fontChinese);

but the issue i am facing now is whenever the code runs to this section:

PdfFont fontChinese = PdfFontFactory.CreateFont(FONT, PdfEncodings.IDENTITY_H);

i am always getting this error: The request could not be performed because of an I/O device error. and this error doesn't make sense to me and I am struggling to find out the solution, could someone in here had the similar issue plz, the code is in C#.

Many thanks.


Solution

  • I can confirm that above code is working as expected, the .otf file that I was originally downloaded was corrupted, hence I got above error.