Commit Graph
100 Commits
Author SHA1 Message Date
EliotJones f8af7daeeb restore copy link func logic 2025-07-24 19:00:53 -05:00
EliotJones d7f0fd96d8 make link copying more tolerant when adding page
in #1082 and other issues relating to annotations we're running into
constraints of the current model of building a pdf document. currently
we skip all link type annotations, i think we can support copying of links
where the link destination is outside the current document. however the
more i look at this code the more i think we need a radical redesign of
how document building is done because it has been pushed far beyond
its current capabilities, i'll detail my thinking in the related pr in more
detail
2025-07-23 20:56:26 -05:00
EliotJones 5abdfcb96c fix test case due to field renaming 2025-07-20 20:33:46 +01:00
EliotJones 00ca268092 move last uncovered operators to switch statement
in order to remove reflection from the core content stream operators
construction we ensure all types covered by the operations dictionary
have corresponding switch statement support. this moves the remaining
2 operators to the switch statement. fix for #1062
2025-07-20 20:33:46 +01:00
EliotJones 2b11961c8c remove debug asserts causing test failures
we encountered a fence constructed in the middle of a field for an unknown
reason so we demolished it. i think this was intended to catch flaws in the
parser logic but the reality is in a pdf anything can happen so we no longer
want to catch these issues and this restores a green test run in debug mode.

fix for #915
2025-07-20 17:42:34 +01:00
EliotJones efb8c2a803 i merged a pr which broke the build, this updates the build to work
move all arguments to add page to a setting object so it can be extended
in future in a non-breaking api change
2025-07-20 17:36:19 +01:00
EliotJones 377eb507e8 when writing content to an existing page inverse any global transform #614
when adding a page to a builder from an existing document using either
addpage or copyfrom methods the added page's content stream can contain
a global transform matrix change that will subsequently change all the locations
of any modifications made by the user. here whenever using an existing stream
we apply the inverse of any active transformation matrix

there could be a bug here where if you use 'copy from' with a global transform
active, we then apply the inverse, and you use 'copy from' again to the same
destination page our inverse transform is now active and could potentially
affect the second stream, but I don't think it will
2025-07-20 00:53:03 +01:00
EliotJones 4bf746c747 add new action to run integration against common crawl corpus 2025-07-19 11:49:34 +01:00
EliotJones bffd51425d support bfrange having incorrect length in a cmap
the corpus file 0001413.pdf has an off-by-one error in its count
for cmap bfranges. here we exit early if an unexpected
endbfrange operator is encountered early. this matches the pdfbox
behavior:

https://github.com/apache/pdfbox/blob/067d56e4dbf5817158d1e910b9602d031ab2153d/fontbox/src/main/java/org/apache/fontbox/cmap/CMapParser.java#L373
2025-07-19 11:48:04 +01:00
Eliot Jones e3388ec6b6 fix colorspace error when form xobject contains a transparency group (#1088)
* fix colorspace error when form xobject contains a transparency group

when a form xobject contains a reference to a group xobject this can only
be used to change attributes of the transparency imaging model. the old
code was setting the main colorspaces incorrectly causing errors when the
transparency component had a different number of channels. this was
causing #1071 in addition to the failure in file 0000355.pdf of the test corpus

* add master integration tests for corpus group 0000

* tidy up actions

* remove invalid reference in echo

* move new action to different branch
2025-07-19 11:46:56 +01:00
EliotJones 31658ca020 allow reading to continue if encountering an invalid surrogate pair
investigating the corpus at
https://digitalcorpora.s3.amazonaws.com/s3_browser.html#corpora/files/CC-MAIN-2021-31-PDF-UNTRUNCATED/zipfiles/0000-0999/

the input file 0000000.pdf contained a utf-16 surrogate pair in an input
defined as usc2. the approach of various parsers varies here, adobe
acrobat seems to hard crash, pdf js returns the same text we now
parse, chrome parses the intended text (2 invalid characters and
"ib exam"). we don't care too much about matching chrome exactly
so doing the same as firefox is fine here
2025-07-16 07:45:40 +01:00
EliotJones 1021729727 fall back to times-roman as standard 14 font when lenient
if parsing in lenient mode and encountering a malformed base name
(in this case 'helveticai') we fallback to times-roman as the adobe font
metrics file for a standard 14 font. this aligns with the behavior of pdfbox.
we also log a more informative error in non-lenient modes

this fixes document 0000086.pdf from the corpus
2025-07-16 07:43:49 +01:00
Eliot Jones 9503f9c137 fix off-by-one and optimize brute force xref search #1078 (#1079)
* fix off-by-one and optimize brute force xref search #1078

when performing a brute force xref search we were ending up
off-by-one, update the search to use a ring buffer to reduce
seeking and fix xref detection

* make method testable and add test coverage

* normalize test input on other platforms

* seal circular buffer class
2025-07-16 07:35:24 +01:00
Eliot Jones 016b754c5b back-calculate first char if last char and widths present (#1081)
* back-calculate first char if last char and widths present

when a truetype font has a last char and widths array in its font
dictionary the first char can be calculated #644

* fix off by 1 in last char calculation
2025-07-14 21:57:01 +01:00
Eliot Jones de3b6ac6f4 use correct bounding boxes for standard 14 glyphs #850 (#1080)
* use correct bounding boxes for standard 14 glyphs #850

previously every bounding box for type 1 standard 14 fonts was assumed
to start at 0,0 and ignored the bounding box data in the font metrics file.
now we correctly read the glyph bounding box while preserving the
existing advance width values for advancing the renderer position

* update test case for new logic
2025-07-14 21:54:42 +01:00
EliotJones b11f936f22 fix copying of sub-dictionary when keys collide
when copying from a ancestor node of a page's resource dictionary
we were incorrectly writing nested nodes of e.g. /fonts to the root
of the target dictionary, here we write to the intended target node
correctly
2025-07-10 18:32:20 +01:00
EliotJones 7fe60ff8c3 skip single letter final blocks
align with the behavior of pdfbox and c implementations where
single character final blocks are ignored rather than being written.
also makes the error more informative in case it is ever encountered
again.

add more test cases.

it is possible this is hiding the problem and will move the error elsewhere
but this matches the implementation behavior of the 2 reference
implementations. one other potential source for the error is if pdf supports
'<~' as a start of data marker which i can't find in the spec but wikipedia
says might be possible? without documents to trigger the error i think
this is the best fix for now
2025-07-09 07:33:12 +01:00
EliotJones 781991b6bf fix #670 by ignoring duplicate endstream definitions
when parsing a stream object with multiple endstream tokens
the last parsed token was selected instead of the actual stream
token so instead we just skip all following tokens if the first
is a stream and the following tokens are `endstream` operators
only
2025-07-07 20:34:26 +01:00
EliotJones daaac9350d writer util did not follow reference links #1032
when copying various dictionaries from a source document
to the builder any indirect references in the source document
would throw because the code expected the dictionary token
directly. now we follow the list of indirect references until we
find a non-indirect leaf token. also changes the exception type.
2025-07-06 07:15:35 +01:00
EliotJones f099dd5827 add test coverage to stream scanning 2025-07-06 07:13:55 +01:00
EliotJones 0586713da3 skip comments in pdf objects streams #926
the file provided in issue #926 contains the following syntax
in pdf object streams:

```
% 750 0 obj
<< >>
```

currently we read the comment token and skip the rest
however this producer is writing nonsense to the stream.
comment tokens are only valid outside streams in pdf files
so we align to the behavior of pdfbox here by skipping the
entire line containing a comment inside a stream which fixes
parsing this file.
2025-07-06 07:13:55 +01:00
Eliot Jones c46722fa26 version 0.1.9
Build and test / build (push) Has been cancelled
Run Integration Tests / build (push) Has been cancelled
2024-10-06 15:40:24 +01:00
Eliot Jones eb9a191e0d remove useless checksum check for truetype font processing
Build and test / build (push) Has been cancelled
Run Integration Tests / build (push) Has been cancelled
2024-09-29 18:17:40 +01:00
Eliot Jones 5953ca9be3 handle escaping in pdf doc encoded strings #730 2024-01-13 19:14:37 +00:00
Eliot Jones 90f7e4bda2 #710 set colorspace based on jpeg info 2024-01-13 16:59:22 +00:00
Eliot Jones 5fadf9a388 write null token to output if null encountered #743 2024-01-11 16:20:54 +00:00
Eliot Jones 33e4ead379 remove localtests 2024-01-11 16:00:46 +00:00
Eliot Jones 966bf49e58 remove unsupported feature 2024-01-11 16:00:46 +00:00
Eliot Jones d7a34c69ce handle duplicated invalid closing array/dict tokens in objects #6 2024-01-11 16:00:46 +00:00
Eliot Jones 88a148374e add script to easily target a single framework 2024-01-10 21:34:35 +00:00
Eliot Jones 96ba82ad4e allow writing custom metadata to document builder #669 (#715)
* allow writing custom metadata to document builder #669

* skip null entries
2023-10-22 10:33:06 +01:00
Eliot Jones e99fa4eef6 Merge pull request #677 from UglyToad/revert-to-nightly-in-main-package-feed
move nightly builds back to main feed
2023-08-05 16:35:11 +01:00
Eliot Jones fcf09ac6b3 move nightly builds back to main feed 2023-08-05 16:22:55 +01:00
Eliot Jones 76fc9808fc skip zero length truetype format 0 cmap table 2023-07-23 14:30:21 +01:00
Eliot Jones 954b3cee47 tidy up form stream check logic 2023-07-23 14:19:29 +01:00
Eliot Jones 6c0f8b762c Merge pull request #652 from mvantzet/PreventCorruptionWhenRemovingText-538
Prevent PDF corruption when removing text (#538)
2023-07-23 14:16:16 +01:00
Eliot Jones ae83f39e28 detail new nightly build location 2023-06-07 20:54:59 +01:00
Eliot Jones c6a6d885ff Merge branch 'master' of github.com:UglyToad/PdfPig 2023-06-06 19:37:38 +01:00
Eliot Jones 32cf25e6b7 fix typo in accursed yaml 2023-06-06 19:36:29 +01:00
Eliot Jones 129e69fdf9 Merge pull request #638 from UglyToad/pdfdocencoding
Implement PdfDocEncoding for reading string tokens
2023-06-05 22:01:25 +01:00
Eliot Jones 66248f19e4 include readme in package 2023-06-05 22:01:04 +01:00
Eliot Jones 2366d22719 move nightly builds to separate package id
while nightly builds are useful they also cause
a large amount of spam on the main project
nuget. here we try to change the package id
so that it will be hosted as a separate package
while having all the same code and namespaces
this means people can opt into the nightly builds
while keeping the version history of the released
package tidy.

no idea if this will work because actions and
yaml is my idea of hell and is impossible to
debug, but let's give it a go
2023-06-05 21:48:02 +01:00
Eliot Jones 2be4c69c16 set nightly release version
also toggles class back to public for nightly
versions #538
2023-06-05 21:37:34 +01:00
Eliot Jones 16ac297d10 version 0.1.8 2023-06-05 21:36:00 +01:00
Eliot Jones 4118ae0df4 temp hide pdftextremover #538 2023-06-05 21:09:41 +01:00
Eliot Jones 8edbd18a07 use encoding aware reader for decrypt 2023-06-04 17:02:27 +01:00
Eliot Jones 81bb6fce83 use built in encoding handling 2023-06-04 16:49:37 +01:00
Eliot Jones 6f59bed9a2 use pdfdocencoding when parsing strings 2023-06-04 16:40:43 +01:00
Eliot Jones 7fe5fc2272 add test case for armenian alphabet 2023-06-04 14:14:18 +01:00
Eliot Jones 9d2b3f914d account for skipmissingfonts in positioned text #637 2023-06-04 11:47:30 +01:00
Eliot Jones 6daa2ec192 Merge pull request #634 from UglyToad/type-2-font-hflex
Implement hflex and hflex1 operators in Type2CharStringParser (fix #558)
2023-05-28 18:05:48 +01:00
Eliot Jones 5126d28612 isolate incorrect letter test case #558 2023-05-27 16:37:53 +01:00
Eliot Jones edf99acdf4 write version from builder in xmp metadata #633 2023-05-27 13:52:28 +01:00
Eliot Jones 211b27062d support looking up in reply to value for annotation #362 2023-05-27 13:40:01 +01:00
Eliot Jones fba1cbc13c skip missing objects if skip fonts is true #298
if skip missing fonts is set we want to read the file
as much as possible so we will also skip any missing
xobjects like images, forms or postscript code
2023-05-27 10:46:29 +01:00
Eliot Jones 20d3cc9066 tidy up during investigation #600 2023-05-23 19:22:00 +01:00
Eliot Jones 11df5b520d update y if preceding letter was blank #603 2023-05-22 20:40:36 +01:00
Eliot Jones 471dca8327 amend default word extractor logic #603
default word extractor consumed words sorted
by descending y value order and had a check for
when the following letter had a value more than 0.5
units different to the current baseline (from first letter)
position. however we were checking if the new value was
more than the current baseline which it could never
be since the letter was always guaranteed to have an
equal or lower y value based on initial sort (since pdf
y dimension runs top to bottom)
2023-05-22 20:22:19 +01:00
Eliot Jones 98be67d93b Merge pull request #629 from thinkbeforecoding/fix/copyfrom
Fix: copyfrom resources collisions
2023-05-22 19:59:14 +01:00
Eliot Jones c3dd69388d normalize some line endings 2023-05-21 19:17:14 +01:00
Eliot Jones bb4c6f2f1e add capacity to glyph list dictionaries 2023-05-21 19:13:14 +01:00
Eliot Jones 976d8929a1 Merge branch 'master' of github.com:UglyToad/PdfPig 2023-05-21 14:58:45 +01:00
Eliot Jones fc2f7b9325 add intelligent error recovery for known dictionaries #511
if we're parsing a known dictionary (e.g. all keys are required
and there are no additional optional keys) and we encounter
an error we provide the possibility to recover by assuming
a dictionary end token after all required tokens are consumed
if parsing by looking for dictionary end failed due to a format
exception
2023-05-21 14:58:39 +01:00
Eliot Jones 32a562f02a address compiler warnings, swap rijndael for aes 2023-05-21 13:44:36 +01:00
Eliot Jones 0b8252e930 do not require tounicode to be valid even if present #354 #619
these issues reported that parsing was failing due to a missing
token being reference in the tounicode entry. since neither
issue included a sample file it's impossible to determine the
right fix accurately, however since the tounicode entry is
optional in the spec we can try being more lenient here, this
might just result in more errors once we try to use the font
but the logger will at least prevent parsing the entire document
failing
2023-05-21 12:34:27 +01:00
Eliot Jones 6b9c3be9f8 tidy up some small formatting issues 2023-05-21 12:20:57 +01:00
Eliot Jones 2073e036ef Merge branch 'master' of github.com:UglyToad/PdfPig 2023-05-18 20:30:20 +01:00
Eliot Jones 2a1a09d1fa handle missing optional named destinations 2023-05-18 20:30:17 +01:00
Eliot Jones fc59d1e58f try making nightly release dependent on test passing 2023-05-18 20:05:06 +01:00
Eliot Jones c68c195ea8 update package target frameworks 2023-05-18 19:59:58 +01:00
Eliot Jones 23aeb66566 bump integration test runner version 2023-05-17 20:34:10 +01:00
Eliot Jones 35ff13732e remove completely out of support net 4.5 2023-05-17 20:20:05 +01:00
Eliot Jones db0583edea Merge pull request #597 from UglyToad/BobLd-patch-1
Update run_integration_tests.yml
2023-04-11 20:46:32 +02:00
Eliot Jones 6bca81fca2 Merge pull request #596 from GiovanniNova/master
Support for full-size images without specifing size
2023-04-11 20:43:33 +02:00
Eliot Jones a5c91f00d9 remove invalid constructor 2023-03-17 22:32:22 +01:00
Eliot Jones ec5b3b551a Merge pull request #545 from UglyToad/pdf-to-image-glyph-path
Implement TryGetPath and TryGetNormalisedPath for fonts
2023-03-17 22:02:32 +01:00
Eliot Jones 5eebe9d0f9 Merge pull request #561 from mvantzet/PageSizesAndRotation
Page sizes and rotation
2023-03-17 20:48:32 +01:00
Eliot Jones cdd6a564cd Merge branch 'master' of github.com:UglyToad/PdfPig 2023-03-17 18:45:29 +01:00
Eliot Jones 4876bfbbd4 tidy up some resharper and github warnings 2023-03-17 18:45:23 +01:00
Eliot Jones 52b99b6816 Merge pull request #557 from UglyToad/functions
Implement pdf functions and add type 0, 2 and 4 function tests
2023-03-17 18:42:41 +01:00
Eliot Jones 333955881f Merge pull request #553 from DGdev91/master
Add enums for PDF/A-3 a and PDF/A-3 b conformance + optional parameter to set out builder parameters in PdfMerger
2023-03-17 18:35:20 +01:00
Eliot Jones bd48bbe536 Merge pull request #556 from fnatzke/FixIssue550
Fix for issue #550
2023-03-17 18:30:08 +01:00
Eliot Jones 68c00c9b51 Merge pull request #527 from fnatzke/Issue350-PdfPageBuilder.CopyFrom()_creates_invalid_PDF
Issue350 pdf page builder.copy from() creates invalid pdf
2023-03-17 18:15:06 +01:00
Eliot Jones 999f9ee7dc Merge pull request #551 from fnatzke/Issue549
Fix for Issue#549. Skip over Jpg segments rather than use bruce force…
2023-02-18 10:50:44 +00:00
Eliot Jones 761bce8591 Merge pull request #539 from mvantzet/ExtendLetterProperties
Added Letter properties RenderingMode, StrokeColor, FillColor and add…
2023-02-18 10:48:47 +00:00
Eliot Jones 88aaddcf26 Merge pull request #541 from fnatzke/Fix540
Fix 540 Copy page with inline image.
2023-01-16 15:25:35 -05:00
Eliot Jones 65bc754f5b remove ci unsupported syntax 2023-01-08 15:38:05 -05:00
Eliot Jones d5b196ff44 remove unsupported syntax 2023-01-08 14:18:09 -05:00
Eliot Jones d2944e14e5 change alpha version for nightly builds 2023-01-08 12:01:48 -05:00
Eliot Jones 57e9acbc12 post merge tidy up 2023-01-08 12:00:35 -05:00
Eliot Jones 7b891edb69 Merge pull request #526 from fnatzke/Issue455-Issue_extracting_unicode_from_CJK_file
Fix #455 extracting unicode from CJK file
2023-01-08 11:53:32 -05:00
Eliot Jones 37e31c40ae Merge pull request #522 from fnatzke/master
Fix #514 Print Character with ZapfDingbats font
2023-01-08 11:52:15 -05:00
Eliot Jones 982f36647a Merge pull request #525 from mvantzet/ITokenWriter
Make TokenWriter non-static, implement ITokenWriter, injection in PdfDocumentBuilder, add PdfTextRemover
2023-01-08 11:49:56 -05:00
Eliot Jones c8874c5984 #483 make skip missing fonts even more resilient to nonsense files 2022-12-11 16:18:09 -05:00
Eliot Jones 2aed996319 Merge pull request #517 from fnatzke/master
Fixes for Issue#512, 516 and 519
2022-12-09 09:39:55 -05:00
Eliot Jones 060c7bc728 Merge pull request #521 from eliotjones-roger/rotation-support-for-page-builder
add ability to rotate page by number of degrees, make builder fluent
2022-12-09 09:08:27 -05:00
Eliot Jones 6764d81958 Merge pull request #520 from mjolivet-lucca/master
Adding non regression unit test to cover PR 473
2022-12-09 08:56:22 -05:00
Eliot Jones 9c9c7c99ea ci new namespace file scope unsupported 2022-10-09 16:01:20 -04:00
Eliot Jones e2246a88bb #482 add skip missing fonts option and pass parsing options to content stream processor
this doesn't fix the reported issue since the pdf itself is corrupted on page 8 however it will
allow recovery in some scenarios where text content isn't important.

also adds more informative error when stream unintentionally passed with non zero offset
2022-10-09 13:44:05 -04:00
Eliot Jones c643facee0 #481 skip resource entry if null token 2022-10-09 13:06:04 -04:00