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

pryzmera.com
RedMindZ
2 days ago
172points
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!

69 comments

Comments

kphorn•2 days ago
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•2 days ago
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
RedMindZ•2 days ago
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•2 days ago
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.
RedMindZ•yesterday
Thanks for testing! Looking forward to hearing from you!
avrionov•2 days ago
Task manager reports GPU usage, if you don't see it right click on the column headers to enable it.
fnordsensei•2 days ago
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!
RedMindZ•2 days ago
Thank you! <3

I hope it can serve others as well!

maxloh•2 days ago
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

RedMindZ•2 days ago
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•2 days ago
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!
RedMindZ•2 days ago
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!

hygeoworks•2 days ago
[dead]
mminer237•2 days ago
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.

RedMindZ•2 days ago
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•2 days ago
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•yesterday
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.
RedMindZ•yesterday
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•2 days ago
This looks great! Any plans to make the renderer available as a package for web apps?
RedMindZ•yesterday
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•2 days ago
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?

RedMindZ•2 days ago
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•2 days ago
1200x faster PDF rendering than Acrobat is a compelling reason to switch - nice work
RedMindZ•2 days ago
Thank you!
Waraqa•2 days ago
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?
RedMindZ•2 days ago
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•2 days ago
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.
RedMindZ•yesterday
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.