VahidN / iTextSharp.LGPLv2.Core

iTextSharp.LGPLv2.Core is an unofficial port of the last LGPL version of the iTextSharp (V4.1.6) to .NET Core
Other
615 stars 154 forks source link

cp862 for hebrew #68

Closed guymalka closed 3 years ago

guymalka commented 3 years ago

Summary of the issue

i try to use this with Hebrew text and fail i dont find cp862 for Hebrew , if i use 28598 the program fails

Environment

windows 10

iTextSharp.LGPLv2.Core version: 1.7
.NET Core SDK version: 3.1
IDE: vs2019

Example code/Steps to reproduce:

var stream = new FileStream(@"D:\Test9.Pdf", FileMode.Create); var document = new Document(PageSize.A4);

        PdfWriter.GetInstance(document, stream);
        document.Open();
        BaseFont bf = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, "Cp862", BaseFont.EMBEDDED);
        document.Add(new Paragraph(
                $" : עם אנקודינג:"
            ));
        document.Close();
        stream.Dispose();
paste your core code

Output:

Exception message:
Full Stack trace:
VahidN commented 3 years ago

For Hebrew you should use Identity-H + RTL tips.

guymalka commented 3 years ago

here is the code, very similar to the code in the example you sent i get empty rectangle

var pdfDoc = new Document(PageSize.A4);
            var fileStream = new FileStream(@"D:\Test90.Pdf", FileMode.Create);
            PdfWriter.GetInstance(pdfDoc, fileStream);
            pdfDoc.Open();
            var table = new PdfPTable(numColumns: 1)
            {
                RunDirection = PdfWriter.RUN_DIRECTION_RTL,
                ExtendLastRow = true
            };

            var pdfCell = new PdfPCell(new Phrase("טקסט בעברית", new Font(0, 10)))
            {
                RunDirection = PdfWriter.RUN_DIRECTION_RTL
            };
            table.AddCell(pdfCell);
            pdfDoc.Add(table);

            pdfDoc.Close();
            fileStream.Dispose();
VahidN commented 3 years ago

Change the new Font(0, 10) to

var tahomaFont = TestUtils.GetUnicodeFont("Tahoma", TestUtils.GetTahomaFontPath(), 10, Font.NORMAL, BaseColor.Black);

And this is how you should create and cache a Unicode font.

guymalka commented 3 years ago

the only way is to write "tahoma" font and use the ttf file ?

VahidN commented 3 years ago

Yes. This is how BaseFont.IDENTITY_H encoding works.

guymalka commented 3 years ago

thanks , worked