Skip to content

feat: add ExtractTextElements and OpenFromBytes APIs#70

Merged
kolkov merged 2 commits into
mainfrom
feat/text-elements-open-bytes
May 7, 2026
Merged

feat: add ExtractTextElements and OpenFromBytes APIs#70
kolkov merged 2 commits into
mainfrom
feat/text-elements-open-bytes

Conversation

@kolkov

@kolkov kolkov commented May 7, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add Page.ExtractTextElements() and Document.ExtractTextElementsFromPage() — expose positioned text runs with X, Y, Width, Height, FontName, FontSize through the public API
  • Add OpenFromBytes(), OpenFromBytesWithPassword(), and context-aware variants for in-memory PDF opening without filesystem I/O
  • Refactor internal Reader from *os.File to io.ReadSeeker interface with cached fileSize, enabling bytes.NewReader as backend

Closes #68

Test plan

  • go fmt ./... clean
  • go vet ./... clean
  • go test ./... — 23 packages, all passing
  • golangci-lint run — no new issues
  • 30 new tests covering: ExtractTextElements field access, position consistency, OpenFromBytes success/error/parity, encrypted PDF from bytes, multipage, idempotent Close
  • No breaking changes to existing API
  • CHANGELOG, README, ROADMAP updated

kolkov added 2 commits May 7, 2026 20:02
- Add public TextElement struct with Text, X, Y, Width, Height, FontName, FontSize fields
- Add Page.ExtractTextElements() returning positioned text runs with error propagation
- Add Document.ExtractTextElementsFromPage(pageNum int) convenience method (1-based)
- Refactor internal/parser/Reader to use io.ReadSeeker + io.Closer instead of *os.File
- Cache fileSize at open time to avoid repeated Stat() calls
- Add nil guard in parseObjectAtOffset so closed readers return an error, not a panic
- Add parser.NewReaderFromBytes, OpenPDFFromBytes, OpenPDFFromBytesWithPassword
- Add public gxpdf.OpenFromBytes, OpenFromBytesWithContext, OpenFromBytesWithPassword, OpenFromBytesWithPasswordAndContext
- Add 30 tests covering ExtractTextElements, OpenFromBytes, and error paths
@codecov

codecov Bot commented May 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 65.95745% with 32 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/parser/reader.go 41.17% 22 Missing and 8 partials ⚠️
page.go 87.50% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@kolkov kolkov merged commit 7eeef13 into main May 7, 2026
8 checks passed
@kolkov kolkov deleted the feat/text-elements-open-bytes branch May 7, 2026 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Public API for positioned text extraction

1 participant