-
Notifications
You must be signed in to change notification settings - Fork 392
Offer rendered height and width on text objects #425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
petero-dk
wants to merge
6
commits into
modesty:master
Choose a base branch
from
zealofzebras:renderedheight
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ee6bc77
Add rendered height
petero-dk 172862b
Fix vertical scaling
petero-dk 4699b3d
Add rendered w and h to the output and test script for stretched text…
petero-dk e7076d6
Update readme
petero-dk 3131c0d
fix(rw/rh): scale text dimensions by viewport factor for correct form…
petero-dk 548d6c3
fix(types): add rw and rh to Text interface
petero-dk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| const PDFParser = require('../dist/pdfparser.cjs'); | ||
| const path = require('node:path'); | ||
|
|
||
| const pdfPath = path.resolve(__dirname, 'pdf', 'h', 'hidden-action-test.pdf'); | ||
|
|
||
| const pdfParser = new PDFParser(); | ||
|
|
||
| pdfParser.on('pdfParser_dataError', (err) => { | ||
| console.error('[PDF Error]', err); | ||
| process.exit(1); | ||
| }); | ||
|
|
||
| pdfParser.on('pdfParser_dataReady', (pdfData) => { | ||
| console.log('\n========== PDF Parsed Successfully ==========\n'); | ||
|
|
||
| pdfData.Pages.forEach((page, pageIndex) => { | ||
| console.log(`\n--- Page ${pageIndex + 1} ---`); | ||
|
|
||
| if (page.Texts && page.Texts.length > 0) { | ||
| console.log(`\nText Elements: ${page.Texts.length}`); | ||
| page.Texts.forEach((text, idx) => { | ||
| console.log(` [${idx}] x=${text.x}, y=${text.y}, w=${text.w}, rw=${text.rw}, rh=${text.rh}`); | ||
| }); | ||
| } | ||
|
|
||
| if (page.Fields && page.Fields.length > 0) { | ||
| console.log(`\nFields: ${page.Fields.length}`); | ||
| page.Fields.forEach((field, idx) => { | ||
| console.log(` [${idx}] id=${field.id.Id}, type=${field.T?.Name}, w=${field.w}, h=${field.h}, x=${field.x}, y=${field.y}`); | ||
| }); | ||
| } | ||
|
|
||
| if (page.Boxsets && page.Boxsets.length > 0) { | ||
| console.log(`\nBoxsets: ${page.Boxsets.length}`); | ||
| page.Boxsets.forEach((boxset, idx) => { | ||
| console.log(` [${idx}] id=${boxset.id?.Id}`); | ||
| if (boxset.boxes) { | ||
| boxset.boxes.forEach((box, bidx) => { | ||
| console.log(` Box [${bidx}]: w=${box.w}, h=${box.h}, x=${box.x}, y=${box.y}`); | ||
| }); | ||
| } | ||
| }); | ||
| } | ||
| }); | ||
|
|
||
| process.exit(0); | ||
| }); | ||
|
|
||
| pdfParser.loadPDF(pdfPath); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fillText and strokeText violate the Canvas API contract.
The W3C/WHATWG Canvas contract defines only text, x, y, optional maxWidth; fontSize and renderedHeight
have no API meaning. The current WHATWG Canvas specification
(https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-filltext) and W3C 2D Context reference
(https://www.w3.org/2015/06/2dcontext.html) agree. Extra JavaScript arguments may be passed, but the
standard operation does not consume them; Web IDL
(https://webidl.spec.whatwg.org/#overload-resolution-algorithm) ignores trailing arguments beyond the
declared overload.