Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Why GlyphRectangle bounding box not correct for letter g? #850

Open
hjy1210 opened this issue Jun 17, 2024 · 1 comment
Open

Why GlyphRectangle bounding box not correct for letter g? #850

hjy1210 opened this issue Jun 17, 2024 · 1 comment
Labels
bug document-reading Related to reading documents

Comments

@hjy1210
Copy link

hjy1210 commented Jun 17, 2024

I have a sample pdf file helloworld.pdf, which have one single line "Hello, good morning!".

Use the following code to draw bounding box of each letter.

            using (var document = PdfDocument.Open("helloworld.pdf"))
            {
                var builder = new PdfDocumentBuilder { };
                for (var pageNumber = 1; pageNumber <= document.NumberOfPages; pageNumber++)
                {
                    var pageBuilder = builder.AddPage(document, pageNumber);
                    pageBuilder.SetStrokeColor(128, 128, 128);
                    var page = document.GetPage(pageNumber);
                    
                    var letters = page.Letters; 
                    foreach (var letter in letters)
                    {
                        if (letter != null)
                        {
                            pageBuilder.DrawLine(letter.GlyphRectangle.BottomLeft, letter.GlyphRectangle.BottomRight, 0.3);
                            pageBuilder.DrawLine(letter.GlyphRectangle.BottomRight, letter.GlyphRectangle.TopRight, 0.3);
                            pageBuilder.DrawLine(letter.GlyphRectangle.TopRight, letter.GlyphRectangle.TopLeft, 0.3);
                            pageBuilder.DrawLine(letter.GlyphRectangle.TopLeft, letter.GlyphRectangle.BottomLeft, 0.3);
                        }
                    }
                }
                byte[] fileBytes = builder.Build();
                File.WriteAllBytes("helloworld-letterbox.pdf", fileBytes); 
            }

Result is:
helloworld

Note: the bounding box do not include the descent part of letter g.

@EliotJones EliotJones added bug document-reading Related to reading documents labels Sep 29, 2024
@EliotJones
Copy link
Member

This definitely looks like a bug, not sure when I'd have time to look so unfortunately it'll probably be stuck like this for a good-while.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug document-reading Related to reading documents
Projects
None yet
Development

No branches or pull requests

2 participants