0

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.

Andie
  • 23
  • 8
  • sorry to ask again, but has anyone had the similar issue on iText7 pleas. – Andie Jun 09 '20 at 06:34
  • Hi, please consult with this sample: https://github.com/itext/i7js-examples/blob/develop/src/main/java/com/itextpdf/samples/sandbox/fonts/NotoExample.java – Alexey Subach Jun 10 '20 at 22:17
  • thanks a lot mate, i had looked into that but got the error that i edited in this post. – Andie Jun 12 '20 at 10:22
  • to make sure the error is not on iText side (or to prove that it is), try first to read the font file into byte array with `File.ReadAllBytes` and then feed that byte array into `PdfFontFactory.CreateFont`. If the exception will be on `File.ReadAllBytes` line, then the problem is not in iText – Alexey Subach Jun 14 '20 at 20:23
  • thanks a lot Alexey, i think it is more on my work station side, i have tried another pdf library (FreeSpire.PDF.6.2.0), it initially had the same error, but when i moved my source code to a more powerful workstation, it was able to generate the pdf with Asian characters. I will try iText7 later on that work station and see. – Andie Jun 16 '20 at 03:02
  • 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. – Andie Jun 18 '20 at 06:57

1 Answers1

0

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.

Andie
  • 23
  • 8