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!
- 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.
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.
I hope it can serve others as well!
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
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.
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!
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.
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.
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.
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.
Also on a safety note, are you excluding the exploit vulnerable parts of PDF support?
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.
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!
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.