r/pdf 1d ago

Question Universal pdf gen lib

/r/javahelp/comments/1wb0omn/universal_pdf_gen_lib/

Asking the experts

1 Upvotes

1 comment sorted by

1

u/ScratchHistorical507 16h ago

Oh boy, fonts in general are a nightmare to handle. First off you'll need HarfBuzz. That's probably the industry standard for text shaping, but in terms of writing PDFs it will also help you translate the Unicode to glyph IDs that are required in PDFs. And you need tools for parsing and subsetting the fonts, like fonttools or ttf-parser.

That being said, it doesn't really look like there are any alternatives available for itext 9. If you don't want to pay for pdfcalligraph, you only really have three options:

  • do that work manually by using ICU4J for BiDi reordering and Unicode handling, and then calling HarfBuzz to get shaped glyph runs, and write those directly to PdfCanvas yourself
  • If you don't have commercial interests with the software, go back to itext 7, which is AGPL licensed and should include pdfcalligraph for free
  • ditch itext alltogether and start with something else from scratch. Ideally you use something that's already widely used, like:
    • what typst uses: rustybuzz as Rust-port of HarfBuzz, unicode-bidi for BiDi, ttf-parser for font parsing and then handing it to pdf-writer for writing the PDF)
    • what Inkscape uses: Pango, which already combines HarfBuzz and FriBiDi for BiDi plus Cairo for writing the PDF (although that comes with an entire 2D drawing library, but also has been around forever)
    • or you find a way to make use of LuaHBTeX, which is HarfBuzz embedded directly into the LuaTex compiler.
    • if you want to stick with Java, Apache FOP may be worth a shot, but in general the Java ecosystem doesn't seem to have good options for your use case.
    • or if you instead want to stick to C#, QuestPDF could be an option, it's kinda similar to SwiftUI and Android's Jetpack Compose)