Repository navigation
Print PDF link URLs next to their text when supported #15 - #16
Closed
diegocostares wants to merge 1 commit into
Closed
diegocostares wants to merge 1 commit into
diegocostares wants to merge 1 commit into
Conversation
diegocostares
force-pushed
the
feat/pdftotext-urls-option
branch
from
September 17, 2026 23:55
801504f to
7ebe80e
Compare
diegocostares
force-pushed
the
feat/pdftotext-urls-option
branch
2 times, most recently
from
September 18, 2026 00:38
655b8f1 to
d37018f
Compare
poppler 26.09.0 added `pdftotext -urls`, which prints each link's URL next to its link text, e.g. `link text [https://example.com/]`. Wire it into PdfHandler so those URLs become part of the extracted text. The option is passed automatically when the configured pdftotext supports it; the probe result is cached per binary. Older binaries are detected and left untouched, so extraction keeps working unchanged on poppler < 26.09.0. `pdftotext_urls: false` opts out, `true` forces it on. -urls is added only when applicable: the command must be an array using the file placeholder, without -urls already or a mode that rejects it (-bbox, -bbox-layout, -tsv, -htmlmeta). These cheap checks run before the version probe, so an odd command (empty, a string, no placeholder) is left alone rather than spawning a process or raising while every handler is built.
diegocostares
force-pushed
the
feat/pdftotext-urls-option
branch
from
September 18, 2026 00:44
d37018f to
225530d
Compare
diegocostares
marked this pull request as ready for review
September 18, 2026 00:45
Member
|
Thank you for this, however I'd rather not add a toggle for this. Overriding the pdftotext:
- /usr/bin/pdftotext
- -enc
- UTF-8
- -urls
- __FILE__
- '-'Repeating the binary path and |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Related issues
Implements #15.
Problem
pdftotext— and therefore this gem — extracts only the visible text of a PDF. The URLs behind links live in the document's link annotations, not in the text stream, so they never make it into the output. Recovering them meant reaching for a second tool (pdfinfo -url), a second output format, and losing the association between a URL and the text that links to it.What this does
poppler 26.09.0 added
pdftotext -urls, which prints each link's URL next to its link text, e.g.link text [https://example.com/]. This PR wires that intoPdfHandler:-urls, it is passed automatically, so link URLs are part of the extracted text out of the box. Support is probed once per binary (pdftotext -h) and cached.poppler-utilscurrently onubuntu-latestin CI.pdftotext_urls: falseopts out;pdftotext_urls: trueforces the flag on for a binary that is not auto-detected (that binary must actually support it, otherwise pdftotext errors out and no text is extracted).-urlsis skipped for a command that already carries it, or that uses a mode pdftotext rejects it with (-bbox,-bbox-layout,-tsv,-htmlmeta) — those exit non-zero and would silently yield empty text. A configured command without the__FILE__placeholder no longer raises while the handler is built.Default behaviour of every other handler is unchanged.
How to test
Unit specs cover the command assembly without needing poppler (they stub the capability probe), so they run in CI regardless of the installed version:
They assert
-urlsis added by default when supported, omitted withpdftotext_urls: false, forced withtrue, skipped for incompatible/duplicate commands, and that a command without__FILE__does not raise.With poppler >= 26.09.0 installed, an integration example additionally extracts the fixture
spec/fixtures/files/text-with-url.pdf(a link over the word "website") and asserts the URL is appended. On older poppler that one example is skipped, so the suite stays green there too.Manual check:
Open question
I made it on-by-default when the binary supports it, since the URL belongs with the text it annotates. This does mean the extracted text of a given PDF can change when the OS pdftotext is upgraded across the 26.09.0 boundary, without the gem itself changing — I noted it in the CHANGELOG as a behaviour change. If you'd rather keep it strictly opt-in (off unless
pdftotext_urls: true), that's a one-line change in `urls_wanted?`; happy to flip it.