logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
adammckay  
#1 Posted : Thursday, July 14, 2022 10:18:51 AM(UTC)
adammckay

Rank: Newbie

Groups: Registered
Joined: 6/22/2022(UTC)
Posts: 9
United States
Location: Pennsylvania

When I use the exact same sample code from the patagames site titled "How to Create a PDF Dynamically With C#", a PDF IS produced. However, that PDF is not editable in Adobe Acrobat - you will get the message, "An unknown error has occurred.". Upon further investigation in Acrobat's Preflight, it does have a syntax error, "The required key /CapHeight is missing.". If I had to guess, when PDFium .NET inserts a text object, it is (possibly) not taking care of the Cap Height attribute of the font that it's inserting. I'm no expert though.

Thanks for your attention to this - it would be good to produce PDF files that do not generate errors in Adobe Acrobat.
Paul Rayman  
#2 Posted : Friday, July 15, 2022 7:37:32 AM(UTC)
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,035

Thanks: 5 times
Was thanked: 122 time(s) in 119 post(s)
Hello,

Could you provide the code and the resulting document?

Also you can try this
https://forum.patagames.com/posts/t454-Is-it-possible-to-create-PDF-document--using-Pdfium

But the most correct option is to use an embedded font

Here is the example
CODE2000.zip (3,775kb) downloaded 5 time(s).
test.pdf (3,757kb) downloaded 6 time(s).

Code:

public static void CreateTestFile()
{
    using (var doc = PdfDocument.CreateNew())
    {
        doc.Pages.InsertPageAt(0, 500, 500);
        float y = 480;
        byte[] data = System.IO.File.ReadAllBytes(@"e:\82\code2000.TTF");
        PdfFont font = PdfFont.CreateEmbeddedFont(doc, data, FontCharSet.UNICODE_CHARSET, false);

        for (int i = 0; i < 15; i++)
        {
            string text = "";
            Encoding enc = null;
            switch (i)
            {
                case 0: text = "Hangeul: 이것은 한국어 텍스트입니다."; break;
                case 1: text = "SHIFTJIS: これは韓国語のテキストです"; break;
                case 2: text = "Hebrew: זהו טקסט קוריאני"; break; 
                case 3: text = "Arabic: هذا هو النص الكوري"; break;
                case 4: text = "CHINESEBIG5 traditional: 這是韓文"; break;
                case 5: text = "GB2312 simplified: 这是韩文"; break; 
                case 6: text = "Russian: Это русский текст"; break;
                case 7: text = "Ansi: This is a test string"; break;
                case 8: text = "Baltic: Vienkārša testa līnija"; break;
                case 9: text = "East Europe: Jednoduchá zkušební linka"; break; 
                case 10: text = "Greek: Απλή γραμμή δοκιμής"; break; 
                case 11: text = "Johab: 간단한 테스트 라인"; break; 
                case 12: text = "Thai: สายทดสอบง่าย"; break; 
                case 13: text = "Turkish: Basit test hattı"; break;
                case 14: text = "Vietnamese: Kiểm tra đơn giản"; break;
            }

            var txt = PdfTextObject.Create(text, 10, y, font, 13);
            doc.Pages[0].PageObjects.Add(txt);
            y -= 30;
        }
        doc.Pages[0].GenerateContent();
        doc.Save(@"e:\82\test.pdf", SaveFlags.NoIncremental);
    }
}
adammckay  
#3 Posted : Friday, July 15, 2022 8:55:35 AM(UTC)
adammckay

Rank: Newbie

Groups: Registered
Joined: 6/22/2022(UTC)
Posts: 9
United States
Location: Pennsylvania

Thanks for the code, Paul. I can re-create the issue with the code above sent by you and the resulting PDF. If I open that PDF in Adobe Acrobat Pro (2017) and attempt to edit the document (Tools--> Edit PDF), I will receive an error: "Adobe Acrobat has encountered an unknown error.". On a normal PDF, Acrobat will simply show me the document with editable bounding boxes for all the text.

It is the same with the PDF linked above as well (without running any code). It cannot be edited in Adobe Acrobat. As I said, I think it is missing the Cap Height key as per preflight. I believe that key tells it how high capital letters are in an embedded font.

Edited by user Friday, July 15, 2022 8:57:42 AM(UTC)  | Reason: Not specified

Paul Rayman  
#4 Posted : Sunday, July 17, 2022 9:52:45 PM(UTC)
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,035

Thanks: 5 times
Was thanked: 122 time(s) in 119 post(s)
Could you test this file?

test-with-cap-and-bbox-fixed.pdf (3,757kb) downloaded 2 time(s).

Thanks
adammckay  
#5 Posted : Monday, July 18, 2022 7:59:23 AM(UTC)
adammckay

Rank: Newbie

Groups: Registered
Joined: 6/22/2022(UTC)
Posts: 9
United States
Location: Pennsylvania

Paul - I tested with that file and it works as expected.
Paul Rayman  
#6 Posted : Monday, July 18, 2022 9:07:42 AM(UTC)
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,035

Thanks: 5 times
Was thanked: 122 time(s) in 119 post(s)
We will add this fix in the next release, which is expected in a few days.
adammckay  
#7 Posted : Monday, July 18, 2022 1:10:31 PM(UTC)
adammckay

Rank: Newbie

Groups: Registered
Joined: 6/22/2022(UTC)
Posts: 9
United States
Location: Pennsylvania

That is great news - thank you for the quick turnaround!
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.