Settings

Theme

Show HN: Pryzmera – Fast PDF viewer fully rendering on the GPU

pryzmera.com

174 points by RedMindZ · 82 comments · 2 min read

Reader

In September of 2021, my father told me he was struggling to open PDFs. As part of his job, he had to view many PDFs with millions of vector paths that were generated by CAD software, and we could not find any PDF viewer that would render them at more than a few frames per second.

I thought that if we simply converted those paths into triangles the GPU could just blast through them. Today, after more than 5 years and 3 iterations in 3 different languages, I would like to share with you the 3rd iteration of my PDF viewer: Named "Pryzmera", I wrote it by hand with the goal to render those CAD PDFs at interactive frame rates, and with the intention to make every feature as fast as I could possibly imagine it to be.

When Pryzmera opens a document, it first starts by interpreting each page. As a page is interpreted, it generates small clipping & tessellation jobs that run in parallel. Clipping & tessellation is performed by Pryzmera's own tessellator and produces the initial geometry for the page. This geometry is then collected and jointly optimized to produce a final GPU representation that mostly consists of colored/textured triangles. The representation is completely static, which in turn makes rendering performance (FPS) almost static, even when the view changes (e.g. panning/zooming/rotating). Once the representation is uploaded to the GPU, rendering a page typically requires only 3-4 draw calls.

On my machine (GTX1080/i7-5820k), Pryzmera can render my father's CAD PDFs at hundreds (and sometimes thousands) of frames per second. Compared to Adobe Acrobat:

- Loading is about 2-10x faster (depending on how Acrobat is feeling on the day)

- Rendering is about 1200-5700x faster (depending on Pryzmera's graphics settings)

- Text search is about 100x faster (although it's hard to measure Acrobat's performance here)

- And this trend continues...

If you would like to test the performance yourself, you can press F8 to bring up the render stats, including FPS and VRAM usage breakdown; You can try this stress-test file I made that is rather representative of the PDFs generated by CAD software: https://pryzmera.com/stress_test.pdf

And if you are curious about any of the technical details, or anything else, ask away!

21 threads
kphorn

I love that you built this and wish you luck. I do CAD and hardware engineering and am no stranger to big PDFs. As a benchmark, I have been using PDF XChange editor as it has a few great features that I rely on. - Fast - I was albe to load the stress test in about 15 seconds and can zoom. I looked and task manager doesnt report GPU usage but does show about 2-3% CPU on a 16c23t AMD Zen5 cpu - Annotations - I can do engineering annotations on it - add text, call outs, clouds, etc. A critical feature set for practicing engineers. Civil and landscaping especially have high need for annotations AND large pdfs. - Text editing/modifications - that's also built in so it's a nice addition.

- There's plenty of competition: NitroPDF, PDF Xchange and others are probably your primary competition. Adobe is the gorilla but I avoid Adobe at all costs unless there's specifically a DRM'd PDF that requires acrobat with a plugin.

I would certainly be interested in the GPU acceleration and getting more out of that.

  • kphorn

    Ok pretty cool, you're saturating my RTX5080m on a workstation laptop and rendering at 500+ fps as I zoom on the stress test pdf. I'd say that's super cool but also maybe cap FPS to 60hz so my GPU can do other things! nice work and very smooth scrolling

    • RedMindZOP

      Thank you!

      Currently the framerate is uncapped to minimize input latency. If Pryzmera doesn't receive any input it stops rendering, so it shouldn't waste system resources (except RAM) while you are not using it. You should be able to see the FPS freeze and CPU/GPU utilization go to zero if you stop moving your mouse (it could take a few seconds). If that is not the case for you, there might be something in your system that makes Pryzmera keep rendering while idle (this happens to me when task manager is open), or there might be a bug I should fix.

      I already got multiple requests to add annotation editing, I know its really important in the field, but this is a deep complexity pit and Pryzmera is already very complicated, so it's going to be a major challenge to implement. I hope I will manage to solve that as well, but that would probably be in the distant future.

      • kphorn

        Yes I can see that it pauses as expected! Moving the mouse is like 1500 fps and just translating the page was 800 fps and with no movement was 0 fps. I’ll reach out via the website so if you need any Blackwell testing I can offer it.

  • avrionov

    Task manager reports GPU usage, if you don't see it right click on the column headers to enable it.

fnordsensei

I think this is great. A good example of classic hacker culture: you (or someone nearby) had a problem, and you wrote a solution. Kudos!

maxloh

What do you use for conformance and regression testing? How much of a real-world PDF test suite can it render accurately?

For a PDF viewer, fidelity matters much more than rendering speed. Imagine using it to open CAD PDFs as you suggested, only to realize a few months later that sections of some files silently failed to render, by which point the ship has sailed.

Relying on a renderer maintained by a single person or even a small team carries significant risks. There are too many things that can go wrong.

For example, pdf.js (which powers Firefox) uses a test suite with 1,579 files and growing: https://github.com/mozilla/pdf.js/tree/master/test/pdfs

  • RedMindZOP

    To test rendering correctness I use my own suite of about 100 PDFs that is a mix of research papers, proprietary CAD drawings from different people my father works with, technical specs, books, and few others. I compare rendering results from Pryzmera to MuPDF, and when the PDF doesn't contain a feature Pryzmera doesn't support, rendering is basically equal up to anti-aliasing differences. On my test suite nearly all PDFs render correctly, with a few that have minor differences (for example, images don't look identical at all zoom levels due to sampling, but the content is the same).

    As for visual features Pryzmera currently doesn't support, the biggest one is probably shading; it's very rare in my test suite, but I will probably add support in the future, I just haven't got to it yet. Other visual features like paths, images, text, image masks and transparency are fully supported.

    Lastly, I would like to add that fidelity is not absolutely everything: when you can't open a PDF, it doesn't help that it will eventually render correctly. Effectively you are not getting any render at all. Pryzmera does its best to render as close to the spec as possible, but is willing to sacrifice some visual fidelity (for example, by flattening curves into multiple line segments) in order to achieve orders of magnitude better performance. And if something does fail to render, it should appear in the logs, excluding bugs of course.

    • darkwater

      Out of curiosity, how do you compare your rendering output to the ground truth rendering? It's probably a naive question but I have zero knowledge on this domain and I'm curious to learn!

      • RedMindZOP

        Very reasonable question!

        On Pryzmera's side, the same way it renders to the window, it can render to an image file instead (PNG). On the "ground truth" side, I use mutool (based on MuPDF) to render the same PDF into another image file. Both renders are configured to use the same resolution, and then they can be compared pixel-by-pixel. Pixels are simply 3 numbers, representing the intensity of the red, green, and blue colors in the pixel. Each one of those can be directly compared to the same color in the other pixel by simply calculating their absolute difference (AKA |red1 - red2|). You can also use other functions here, like squared distance and such. All of the differences are summed to give you the error for each pixel, and then you can measure different metrics, like the pixel with the biggest error in the image, or the average pixel error for the image.

        One note about "ground truth": When it comes to PDF rendering, the specification is incredibly long and complicated, which means there is basically not a single renderer that renders PDFs 100% correctly, even Acrobat likely has bugs. Thus, the output for each renderer is usually slightly different, especially around weird edge cases. For that reason, "whatever Acrobat does" has often times become the effective specification.

        And if you have any other questions, please don't hesitate to ask!

mminer237

It looks very impressive. I mainly use simple PDFs, but Acrobat is indeed frustratingly slow just starting up without even rendering anything. I count six seconds to just open it on my computer without even opening a file. (Versus SumatraPDF, which is well under a single second.)

I'm glad people are still trying to make things better. It's a great irony that as computers get faster and faster, software still manages to get slower and slower.

  • RedMindZOP

    Thank you!

    I believe all the software we use can be great, and Pryzmera is my one contribution towards that. Whether it is great or not is left up to everyone's judgement, but its the best I can do.

angry_octet

I stopped caring about fast pdf viewing some time ago. Now I only care about secure parsing and rendering. Signing and signature verification with something other than Acrobat would also be great.

illiac786

I can’t test it right now but what do you use to render JPEG2000? I work with OCR’d documents stored as searchable pdfs, and the image layer is jpeg2000. Good compression ratio, horribly laggy in most pdf viewer I have used so far.

  • RedMindZOP

    Pryzmera doesn't use anything special to render JPEG2000 or any other type of image. It decompresses all images at their full resolution, packs them into as many texture atlases as necessary (1 is usually sufficient), and renders them with textured triangles. Hence, rendering performance is independent of the image types used in the document.

    The video on the website that showcases the "Image Viewer" capabilities is rendering an image with a resolution of 63360x35640 (that is 2.2 billion pixels, or 9GB uncompressed) on my 8GB VRAM GPU at about 1100-1200 FPS, bottlenecked by the CPU. Images have a near-zero impact on rendering performance, so Pryzmera should handle your JPEG2000 documents well.

chaechoi

This looks great! Any plans to make the renderer available as a package for web apps?

  • RedMindZOP

    Thank you!

    I never thought about that. Rendering uses the 'wgpu' crate under the hood, so in theory it should be simple to run it in a web app with WebGPU; At the same time, I am not sure what would be the value of the renderer without the tessellation pipeline that populates it, because other than transparency, rendering is mostly very simple; for example, rendering colored triangles is done with a shader that is 10 lines long, and 8 of those lines aren't even executable code. And on the technical side, the renderer's code is rather entangled with the application, so pulling it out could get difficult.

    Do you have a use in mind for Pryzmera's renderer? If you do, let me know, I might be able to guide you to a solution that would better fit your needs.

ashkankiani

You mention mupdf (which is what I use as the basis for my wrapper around it) that you use as the comparison for testing. How does it compare to that?

Also on a safety note, are you excluding the exploit vulnerable parts of PDF support?

  • RedMindZOP

    When you ask about a comparison to MuPDF, it depends on the dimension you are talking about.

    If you refer to the accuracy of rendering, it is effectively identical on my test suite up to minor differences in anti-aliasing and such; I gave a more detailed answer in another comment.

    If you refer to rendering performance (FPS), then it is hundreds to thousands of times faster, although I don't have exact benchmarks; I talked about it some more in the comment asking about SumatraPDF.

    As for safety, I have to be honest and say that I have not paid much attention to it specifically. I am using Rust, and I utilize the type system as much as I can to ensure all cases are handled and there are no panics or memory corruptions. Only MuPDF directly interfaces with the PDF, so I hope that given its age it has patched most vulnerabilities. I have also disabled JS in the MuPDF build and I assume that is where most vulnerabilities would be. If there is something else I should be aware of, let me know.

emmilevesque

1200x faster PDF rendering than Acrobat is a compelling reason to switch - nice work

Waraqa

I was excited to learn about your software and to read this discussion. When I opened your website, I didn't expect it to be Windows-only. Do you have plans to release it for other operating systems?

  • RedMindZOP

    I would love to release both a Mac and a Linux version in the future, it will just take me more time.

    For now, there is a portable version on the downloads page (https://pryzmera.com/downloads/), and one of my friends ran it on ubuntu with wine, and it seemed to work fine. As for Mac, another friend tested with wine on Mac and it didn't work at all; Maybe it would work with CrossOver? But I don't know anything about Windows emulation on Mac.

    If you are interested in trying it on a non-windows system, I would love to hear if it works well for you!

    • blakeashleyjr

      Would buy instantly for Linux! Please consider it on your roadmap. There are open-source options but it is shocking how poor PDF readers perform and behave considering the ubiquity of PDFs.

      • RedMindZOP

        Thank you!

        Linux is certainly on the roadmap! I hope I can get to it in the relatively near future, but I don't have an exact timeline. In the meantime, if you are willing, I would encourage you to try the portable version with wine and report back your experience. Wine might perform sufficiently well until I publish a native Linux version.

        I am honestly not surprised at the poor behavior you see from many PDF viewers; Calling the PDF spec "ridiculous" is a major understatement. Even though PDFs are everywhere, processing them requires an immense engineering effort, and hence it's understandable why many projects end up with some undesirable behavior.

balaji_ingole

How do you handle text selection and search once everything is triangles on the gpu

  • RedMindZOP

    When a page gets interpreted, the small jobs that are generated also extract text from the page, which is later collected and combined to produce both a search index and a spatial index. The search index can answer text-search queries in time that is basically linear to the total number of matches, and the spatial index can answer queries like "is there a glyph at these coordinates?" and "what is the closest glyph to these coordinates?" in logarithmic time. In addition, the quads that bound each glyph are also stored in order to generate highlights over text, for example when selecting text. So while triangles are used for rendering, there are additional data structures that store the required data for interacting with the document, and those are processed on the CPU.

ohmyYY

This looks really cool brother. Best of luck!

herf

The kerning (or inter-character spacing) looks a little rough compared to most viewers - is there more you could do to improve this?

  • RedMindZOP

    That's interesting, Pryzmera gets all of its text already positioned by MuPDF, so it could be a low level bug where the glyphs are rendered in a slightly different position inside their bounding box than where I expect them to be. If the text you are looking at is small, this could also be the result of text anti-aliasing being different in Pryzmera compared to other viewers. It's hard for me to speculate further without seeing your exact document.

    I did my best to tune text rendering to look as good as it can be, but it's certainly not perfect. You can try raising the text rendering quality from the graphics settings (lets say to 64), reload the document with F5, and see if it looks better.

jimjimjim

Does this use the MuPDF toolkit for pdf reading and processing? Is it opensource?

  • RedMindZOP

    Currently closed source.

    It does currently use a modified version of MuPDF to parse PDFs, but everything past parsing (e.g. translating graphics primitives to a GPU representation) is done by Pryzmera. In the future, I would like to replace MuPDF with my own code.

    • EgoIncarnate

      Isn't MuPDF AGPL?

      • RedMindZOP

        It's only AGPL if you don't pay them.

        I did sign a contract with them, which is also the reason why the number of activations per license is limited. My next objective is to replace MuPDF with my own code to remove this limitation and to significantly improve loading performance.

aledamasmx

Adobe Digital Editions to read PDF and EPUB

rootlocus

What language did you settle on and why?

  • RedMindZOP

    The short version is Rust, for its performance and type system.

    Initially, in January of 2022, I wrote the first iteration in Python to prove the idea. After about 2 weeks, I had a working prototype, but it could take 30 minutes to convert a single file into gltf, it didn't support anything other than vector paths, and it was simply terrible; but it did work.

    To make it more practical to use, I started working on a C# version in March of 2022, which was much more practical to use: It rendered into its own window instead of converting to gltf, and could load the same documents in about 10 seconds. I chose C# because I was very comfortable with it at the time, it was way faster than python, and also didn't require me to deal with all the many pains of C. It took me about 3 months to make it usable, and another 3 months to round it out. It was good enough for my father to use it, but it was getting difficult to continue developing it and my most extreme document would still take 4 minutes to load.

    Around the beginning of 2023, I started hearing about Rust and got really excited about it: It had the performance of C with an amazing type system and without manual memory management, and I thought it would be both fun to use, and could make the software much better. So in April of 2023 I started first by implementing the tessellator in Rust, and after 4.5 months it was ready for use and about 4x faster than Clipper2 while producing less geometry and supporting more complex operations. Fast forward another 3 years, and we ended up with the current-day Pryzmera, which opens that same document that took C# 4 minutes in 6 seconds, and renders it about 15x faster.

nathell

How does this compare to SumatraPDF?

  • RedMindZOP

    Depends on the dimension you are asking about:

    If you are talking about performance, while I haven't benchmarked SumatraPDF specifically, it is using MuPDF under the hood both for parsing and rendering. I actually modified my MuPDF to load significantly faster in specific situations, so Pryzmera and SumatraPDF should be competitive on loading speed. For rendering performance, I am familiar with MuPDF's rendering performance and would confidently estimate that Pryzmera renders hundreds or thousands of times faster compared to SumatraPDF. Sadly I don't have exact benchmarks, so I hope my best estimate will suffice here.

    If you are talking about other features, I am frankly not sure, I don't use SumatraPDF and only have a rough idea of what it offers, so I regrettably cannot inform you there.

layer8

> Activations are permanent and tied to a specific computer, and therefore cannot be transferred between computers.

Sorry, but that is not acceptable for a perpetual license.

  • RedMindZOP

    Why not? For an individual license, you get 5 activations, which I think should suffice for a while. And as I said in other comments, the 5 activations restriction is something I would like to lift once I replace MuPDF.

    And regardless, as far as I know, it is mathematically impossible to implement both an offline license that never calls to the server and transferable activations. The reason being that if you never verify the license with the server, someone could take a snapshot of the machine, transfer the license, then roll back the machine, which would yield an infinite number of activations.

    It was far more important to me that Pryzmera would keep working permanently even if one day me and the server disappeared. This is software that is completely independent of the server and will keep running indefinitely, which means it also works in air-gapped systems.

    If you have a better suggestion for how to implement licensing, please let me know.

    • layer8

      It means that I don’t own the copy of the software that I bought.

      And if you allow offline activation, I don’t see how you can control the number of activations anyway.

      I would be borderline willing to purchase a PDF viewer for 50€ if it is really good (it’s already a steep price) despite being limited in terms of updates. But being limited in how many PCs I can use it on over time because you don’t trust your paying customer to not give it away is too off-putting for me.

      • RedMindZOP

        My intention certainly is to make it software that you truly own, hence why it should keep working long after I'm gone. There is definitely a tradeoff here between working forever VS working on any computer. I chose the "working forever" option.

        The way offline activation works is by enabling you to reach the server from a different computer that does have an internet connection, but it is mostly orthogonal to not requiring checking in with the server after activation. After activation is performed, Pryzmera has a local license that never requires it to check in with the server, which is why it is not transferrable.

        The issue is not that I don't trust my paying customers, it's that in all likelihood someone will abuse the system and will resell a single key as many times as they can. Maybe I worry too much about this option, but for now this path seems reasonable to me.

        • blakeashleyjr

          I think you should consider biting the bullet on the risk, especially at the price. If it was $10 or something, I'd understand.

          Even in your wildest dreams, it will be a niche product for professionals and HN-type nerds.

          • RedMindZOP

            I will certainly consider it. It will take me more time to come to a conclusion.

wewewedxfgdf

Is PDF performance a problem?

  • RedMindZOP

    Normally, no. But in the CAD world it is a huge problem. You can try opening the stress test PDF I linked in the text body (https://pryzmera.com/stress_test.pdf), it is a decent representation of the problem architects and related field deal with.

    • sourweasel

      GIS is another field with lots of complex slow-rendering PDF files. I would recommend trying some USGS topo maps for your stress testing.

      Sample Link (West Mt. Rainier 7.5min): https://prd-tnm.s3.amazonaws.com/StagedProducts/Maps/USTopo/...

      Source: https://apps.nationalmap.gov/downloader/

      • RedMindZOP

        Thank you for the additional test case!

        This PDF is mainly composed of a large image (around 1GB uncompressed, very close to my stress test) and relatively few vector paths, Pryzmera renders it at about 300FPS on my machine.

    • wewewedxfgdf

      >> Normally, no. But in the CAD world it is a huge problem.

      Perhaps then you should market it as "Fast PDF for people who love CAD" or something. Then you might catch the attention of the people for whom this solves a problem

      Aiming generally at everyone, certainly I'm like "meh, PDF seems fast enough".

      • RedMindZOP

        Thanks for the input. While it is mostly a problem in the CAD fields, I don't wanna limit it just to CAD, I think it has a few other applications (like searching long text documents or viewing large images), and for me it also just feels really good to use, so I don't wanna push away other people who might find value in it.

        • wewewedxfgdf

          >> I don't wanna push away other people who might find value in it

          If you market to everyone, you market to no one.

          Perhaps discuss the marketing and target market and segmentation of this product with your local LLM.

          You have described to me a pain point for the construction and design industry that presumably has at least some money to spend on better tools.

  • uint8_t

    It is a huge problem for some people. Consider building construction, where all trades collaborate on producing a detailed model in e.g. Revit. The design coordination model will have thousands of small 3D models - every lighting and plumbing fixture, all the HVAC and electrical, often every piece of furniture.

    To produce the architectural plans, illustrations are made by taking section cuts, each of which effectively duplicates and flattens all the 3D model geometry into PDF linework. This is a hideously inefficient process that usually does not simplify the model geometry.

    For a commercial building these drawing sets stretch into the hundreds, sometimes thousands of pages long. If your job is to study and review a 382 page PDF, and each page takes 5 to 20 seconds to render, it could take over two hours just to say you've seen it.

    To the author: please keep up this righteous fight. The final boss will be Bluebeam.

  • cyral

    Acrobat is a laggy mess, at least on Mac. Like sub 10-fps often times

    • magicalhippo

      Windows too gor what it's worth. 9800X3D and a 5090 and Acrobat is a slideshow even on very badic PDFs. SumatraPDF flies on the same files.

p1mrx

$60 for a closed source PDF viewer, with 1 year of updates.

I wish you good luck finding customers.

  • deburo

    Yeah unfortunately there's already a few options for fast PDF rendering, at similar prices, with plenty more features since they are mature.

    PDF X-Change comes to mind. It handles the linked stress PDF pretty well.

    EDIT: I wonder if OP is an handmade hero guy? There's been a bunch of pretty cool products from that community: Zeiger, Blick, FilePilot, ...

    • tecleandor

      although it still works, note that the X-Change Viewer is discontinued, and they haven't upgraded it since 2018. The new software, X-Change Editor, is €59 for the regular version and €75 for the "Pro".

    • RedMindZOP

      Can you share your CPU? I am also wondering if X-Change works well for you when zooming?

      And yes, I am quite fond of the handmade network :)

    • koziserek

      even my embedded PDF previewer in my vibecoded file manager 'ffss' handles the stress test, taking somewhere between 500 and 1000ms ..

      https://github.com/koziserek/ffss - saying so, because this feature landed exatly today ;)

cvadict

> https://pryzmera.com/stress_test.pdf

the stress test renders in < 3 seconds on my m5 max in pdfcraft (which is open source). Not sure I would ever pay $60 for a closed-source app to "speed it up," especially given how contrived that stress-test PDF is.

> GTX1080/i7-5820k

Yeah, there's your problem. Computers have gotten substantially faster in the last dozen years. I can't say I've felt that a PDF (regardless of how complex) has been slow during that time.

  • tecleandor

    You're complaining about a $60 app from a computer that maybe was $4K or $5K. Even on my M2 Max 32GB, it takes around 10 seconds just to load the stress test file and navigating trough it is extremely laggy. Apple Preview just hangs.

    If I had an older computer, and my field of work required me to open extremely complex PDFs and my two options were 1) buying a $60 software 2) dropping $5K in a new computer... I think I'd chose the first.

  • RedMindZOP

    At what frame rate does it render? Can you easily zoom in without lag?

    And as far as my hardware is concerned, not everyone has the latest hardware. But even old hardware is so incomprehensibly fast, there is no reason it shouldn't render everything at least at 60 FPS or higher.

    If you don't struggle with slow PDFs, that's great; Pryzmera is probably not for you, but in architecture and related fields this is a huge problem.

  • WhitneyLand

    I think it’s a nice piece of engineering.

    Three seconds can get to be a real pain if you do it a lot.

    Always room for things to go faster.

  • zokier

    high end computers have gotten substantially faster. That decade old system is still pretty competitive against your typical average $400 basic laptops that are way too common

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection