Skip to content

Backport/pdfimport pdfbox - #525

Open
leginee wants to merge 8 commits into
trunkfrom
backport/pdfimport-pdfbox
Open

leginee wants to merge 8 commits into
trunkfrom
backport/pdfimport-pdfbox

Conversation

@leginee

@leginee leginee commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

This updates the pdf import to be used with Apache PDF-Box. It needs java to be installed on the machine.
Simple documents are great, complex with fancy fonts work mediocre.
But it works.

If build it is packaged with the installer and distributed at install.


Why PDF-Box?
The Java interface is stable and a safe move.
PDFium needs C++20 and probably consequent update cycle. Without a working extension site i thought it is better to stick with the Java Version. PDFium has ,quite a dependency list on its own. so I deferred it for now.
hayro is another alternative, but need Rust integration. Maybe also something nice to investigate in future.

Other libraries do not contain features we need, means more code on our side to maintain, which I wanted to avoid at this point in time.

leginee and others added 8 commits November 21, 2026 15:03
Backport of the source half of the PDFBox PDF import work, which is running on
the Bazel branch.  Source only: this compiles nothing new on trunk yet, and the
dmake wiring is deliberately not included -- see below.

PDF import has never worked on Windows.  The only backend, xpdfimport, links
poppler (GPLv2), which may not be linked into an Apache-licensed soffice.bin,
so configure.ac gates the whole extension off by default and no stock build has
ever shipped it.  Rather than modernise against poppler -- whose API this code
has drifted about ten years behind, and whose licence keeps the result
unshippable -- the backend becomes pluggable and a second one is added that is
Apache-2.0.

The seam is a process boundary and a wire protocol, not a C++ interface:
pdfimport.uno.dll links no engine's headers, libraries or licence.  A PDF is
untrusted input, and a fault in the parser should cost one document rather than
the session.  PROTOCOL.md is that contract, written down for the first time.

Two defects this avoids that the poppler backend has: it sends
getTransformedFontSize(), which already includes Tm's scale, alongside the raw
Tm, so a document with its scale in Tm is scaled twice; and it emits hyperlink
rectangles in points where the consumer stores page coordinates in 1/7200 inch,
100x too small to contain any text.

Still required before this builds or runs under dmake:
  - wrapper/makefile.mk: pdfbackend.obj is not in any SLOFILES list;
  - a build for pdfboxwrapper, and a way to obtain the four PDFBox 3.0.8 jars
    (pdfbox, pdfbox-io, fontbox, commons-logging) -- trunk has no mechanism to
    fetch them;
  - configure.ac: --enable-pdfimport still also demands --with-system-poppler;
  - packaging: the jar has to land where pdfbackend.cxx probes.

The type change in filter/.../pdf_Portable_Document_Format.xcu is the one hunk
that is only correct once the above lands: it names a detect service and
preferred filter that do not exist until the extension is built.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CH5PJJyJfirMStqJEZTxBD
Completes the backport: the extension now builds and packages under dmake, and
the poppler backend is removed rather than kept alongside.

configure.ac
    --enable-pdfimport no longer also demands --with-system-poppler, which was
    a gate nothing could satisfy in an Apache release -- poppler is GPLv2, so
    the else-branch switched the extension back off and no release build ever
    shipped PDF import.  The backend is Apache-2.0 now, so the extension is on
    by default and follows Java instead, since the helper needs a JDK to build
    and a JRE to run.  --with-system-poppler and the POPPLER_* substitutions
    are gone.

external_deps.lst
    The four PDFBox 3.0.8 jars, conditional on ENABLE_PDFIMPORT: pdfbox,
    pdfbox-io, fontbox and commons-logging, which is the complete non-optional
    runtime closure.  BouncyCastle is deliberately absent -- PDFBox marks it
    optional and only public-key encrypted PDFs reach it.

sdext
    New pdfboxwrapper module builds the helper jar and stages the four
    downloaded jars beside it, because the extension's packaging rule copies
    every CONVERTER_FILE out of $(BIN).  The helper is started as `java -jar`,
    so it finds them through the Class-Path in its own manifest, which means
    all five must land in one directory -- they do, in the extension, which is
    also where pdfbackend.cxx probes.

    CONVERTER_FILE was the poppler helper executable and is now those jars;
    the extension manifest no longer declares an executable member.
    wrapper/ gains pdfbackend.obj.  xpdfwrapper/ and xpdftest/ are deleted.

    Note for anyone reading build.lst: wrapper/ builds a library called
    xpdfwrapper.lib -- that is ours, it is only the TARGET name in
    wrapper/makefile.mk.  The poppler helper lived in xpdfwrapper/, a different
    directory.  Removing the wrong one links a DLL with no wrapper in it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CH5PJJyJfirMStqJEZTxBD
Uses the ant framework in solenv/ant rather than dmake's JAVAFILES/JARTARGET,
matching how every other Java component here is built (connectivity/java/*,
swext/mediawiki).  It also removes hand-rolled work: externals.xml already
resolves a third-party jar to $(OUTDIR)/bin and onto the compile classpath, so
the module no longer has to assemble a classpath itself.

  solenv/ant/externals.xml
      The four PDFBox jars, declared like every other external.  They are
      always internal: these are official ASF release artifacts fetched by
      external_deps.lst, and there is no system-pdfbox configure switch, so
      system-test can never match.

  pdfboxwrapper/build.xml
      Imports aoo-ant.xml.  jar.classpath becomes the Class-Path of the helper
      jar, which is how `java -jar` reaches the four alongside it in the
      extension; main.classpath is the compile-time equivalent.

  pdfboxwrapper/src -> src/main/java
      aoo-ant.xml expects the Maven layout.

  pdfboxwrapper/makefile.mk
      Drives ant, and places the downloaded jars twice over -- once in
      $(OUTDIR)/bin, where externals.xml points the compile classpath, and once
      in $(BIN), which is where the extension packaging in ../makefile.mk
      copies from.  Neither is optional and they are not the same directory.

  pdfboxwrapper/manifest.mf
      Main-Class only; aoo-ant.xml contributes Class-Path from jar.classpath.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CH5PJJyJfirMStqJEZTxBD
Four fixes, each found by running the build rather than reading it.

  set_soenv.in
      Still expanded @SYSTEM_POPPLER@, @POPPLER_CFLAGS@ and @POPPLER_LIBS@.
      With the AC_SUBSTs gone those placeholders survive verbatim into
      set_soenv, where perl reads "@SYSTEM_POPPLER" as an array and dies:
      "Global symbol requires explicit package name".  Removing an AC_SUBST
      means removing its consumer.

  makefile.mk
      Includes ant.mk, not antsettings.mk.  ant.mk pulls in settings.mk and
      target.mk itself and is what defines the ANTBUILD target; antsettings.mk
      only sets variables and belongs to the BUILD_ACTION/tg_ext.mk route that
      unpacks a source tarball first, which apache-commons needs and this does
      not.

  build.xml
      Places the four jars, instead of dmake doing it.  $(OUTDIR) and
      $(TARFILE_LOCATION) are absolute and begin "C:", and dmake reads that
      colon as its rule separator, so neither can appear as a target or a
      prerequisite: it fails with "Multiply defined recipe for target C".
      $(BIN) is relative and survives, so it is passed through -D and the copy
      happens in ant, which has no such trouble.

      The sources are also named by checksum on disk, as "<md5>-<name>", the
      convention TARFILE_MD5 follows in solenv/inc/tg_ext.mk, so the four MD5s
      are spelled out here.

Verified: the module builds, and the resulting jar runs against
test/testinput.pdf producing byte-identical output to the Bazel-built helper.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CH5PJJyJfirMStqJEZTxBD
Two build failures, both mine.

  makefile.mk SHL1LIBS
      I had put comment lines inside the backslash-continued macro, which dmake
      cannot parse: "Expecting macro or rule defn, found neither".  Moved above
      the block, where they belong anyway.

  makefile.mk SHL1STDLIBS, prj/build.lst
      pdfbackend.cxx calls jfw_getSelectedJRE and jfw_freeJavaInfo so that the
      helper starts under the JRE the office is configured with -- the one the
      user picked in Tools - Options - Java -- rather than whatever PATH
      offers.  Nothing linked jvmfwk, so the DLL failed with LNK2019 on both.
      Added $(JVMFWKLIB), and jvmfwk to the module's dependency line so it is
      ordered as well as linked.

Result: sdext builds clean, and pdfimport.oxt is 4.0 MB containing
pdfimport.uno.dll, the helper jar and the four PDFBox jars.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CH5PJJyJfirMStqJEZTxBD
PDF import now builds by default, but nothing packaged it: sdext delivers
pdfimport/pdfimport.oxt into the solver and no installer step picked it up,
so an installed office had no PDF import filter at all and could not open
a PDF.

Add it to extensions.lst as a pre-registered file:// extension, the same
mechanism the presenter screen and the presentation minimizer used before
they moved into the core.  It is guarded by ENABLE_PDFIMPORT=YES, so a
--disable-pdfimport build, or one without Java, packages nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Extensions listed with a file:// URL in extensions.lst were unpacked into
share/prereg/bundled.  Setup's "unopkg sync" registers them there and the
first start copies that registration into the user profile, but the
office's "bundled" repository lists only what is in $BUNDLED_EXTENSIONS,
i.e. share/extensions.  The result was half an extension: its services and
configuration were registered, so its filters appeared, but the extension
itself was unknown.  It did not show up in the Extension Manager, and
XPackageInformationProvider::getPackageLocation() returned nothing for it.

PDF import is hit by this directly: it finds its helper inside the
extension through getPackageLocation(), so with no location it reports
that no import backend is available and every PDF fails with a general
input/output error.

Unpack them into share/extensions/<name> instead, where the bundled
repository picks them up on first start.  PDF import is the only file://
entry in extensions.lst.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
46c69c8 turned OOdbcManagement::m_pProcessWait from an auto_ptr into a
unique_ptr but kept its NULL initialiser.  With MSVC, NULL is the integer
literal 0, which converts equally well to the pointer constructor and to the
nullptr_t constructor, so the call is ambiguous and the file does not compile
(C2668).  GCC's NULL is __null, which resolves to the nullptr_t constructor,
so the break shows only in the Windows build.

A default-constructed unique_ptr is already empty, so drop the initialiser.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 96f62dbe3a41d4a82db20e031ceab4c8fdd03396)
@pgiffuni

Copy link
Copy Markdown
Contributor

Huge thanks for doing this! Other than the license, the older PDFIMPORT never caught up with newer poppler >= 0.7x.

I think I can setup the compiler in the compilers-101 branch to C++20 for PDFium, my concern is if the Windows compiler supports it.

@pgiffuni

Copy link
Copy Markdown
Contributor

I found an AOO specific improvement :
pdfbox/pdmodel/font/FontMapperImpl.java, defines the replacement fonts, including Liberation Fonts, which we replaced with the metrically compatible Google croscore fonts:
• Arimo: Sans-serif, metric-compatible with Arial and Helvetica.
• Tinos: Serif, metric-compatible with Times New Roman and Times.
• Cousine: Monospace, metric-compatible with Courier New and Courier
And we also have the crosextra fonts:
Caladea metric-compatible with Cambria
Carlito metric-compatible with Calibri

@leginee

leginee commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

we do not use pdfbox/pdmodel/font/FontMapperImpl.java, defines the replacement fonts.
We need pdfbox, plumium or any other library to read the PDF document and the reengineer the layout information.
Basically PDF-Box gives us the text as letters plus the font. Then we put together an ODF draw file and render that.
The interface established is hopefully in a way that we can swap libraries with little work.

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.

2 participants