Friday, December 12, 2025

Exporting scaling/high-rez PDFs from ReactFlow

This past summer I had a heck of a time getting ReactFlow to export as a PFD in the browser, especially in one step - but we got there. BUT! The result relied on rasterizing the content as a PNG - which didn't graphically scale well, and it turned out a lot of our diagrams are extremely big and detailed, so if you can't preserve clarity on zoom in, the game is kind of lost. (And also, they tended to be huuuge files, many Mbs when the corresponding SVG was tiny, like 100K)

Well, I went a little crazy trying to find different methods of getting the export to work. I learned that SVGs are kind of unevenly supported in a lot of ways in browsers and toolkits, and that many tools that will capture DOM stuff and export it as PDF do so by rasterizing it... even if you try to export an SVG, it will turn into a pixel'd mess close up.  Here is a table I made to track my progress and keep track of what permutations I had already done:

(Note, you don't see options for downloading an svg (like from html-to-image toSvg) directly as a link - that's because one absolutely firm requirement was to wrap the reactflow content in a frame, providing metadata about the content (people and place involved, company logo, etc))

So you can see this table almost makes its own little map (maybe I should have used ReactFlow to diagram it out! ) as many of the steps would have to build on previous steps.

# Method Result Notes
A KendoPDF PDFExport (wrap ReactFlow directly) PDF w/o Edge lines (also likely not zoomable)
B html-to-image toSvg => dataUrl => jsPdf.addImage Fail (unsupported image type)
C html-to-image toPng => dataUrl => jsPdf.addImage PDF (not zoomable) (also large file size)
D html-to-image toSvg => dataUrl SVG content intermediate step w/ huge content size)
E D => download .svg via link Zoomable .SVG file not desired goal file type, and large file
F E => .SVG file to browser print dialog to .PDF PDF (zoomable) also good file size… but how to automate
G E => .SVG file to various online tools and .NET approaches Fail (Many pdf/svg wranglers cannot cope with E SVG)
H D => on-page SVG SVG content Intermediate step
I H => KendoPDF PDFExport PDF (not zoomable) (seems like KendoPDF always rasterizes)
J H => jsPdf w/ svg2pdf .svg() Fail Can’t deal with D SVG (but smaller files work)
K E => >SVG file to svgo optimizer Fail “Error: Pseudo-elements are not supported by css-select”
L H => html2pdf.js PDF (not zoomable) renderizes (interestingly is wrapper to html-to-canvas and jsPdf)
M html-to-image toSvg(of Scaled Flow Elem) => dataUrl Large PNG, no frame reverting to Download Image - React Flow for scaling
N D => new window, button to open up print dialog Scalable PDF! manual steps to hit “print” and “print to pdf”

So sadly, there wasn't a perfect end result. The only thing I found that could reliably output a clean PDF was the browser's own "Print" dialog, with its save to pdf action. And that worked a treat in making a tiny PDF that was totally scalable. 

So the solution is a button that does a "print preview" mode (the frame and content) and fires off the print dialog, though we weren't able to automate past that point (adjusting scaling, destination as to PDF and not a printer, etc)

Thursday, December 11, 2025

doing SSR before it was cool

React got hacked…and it’s WAY WORSE than you think.

Again, more grist for the "old man yells at (amazon) cloud" mill... 
the drive to SSR combined with the "necessary coolness" of isomorphic code that can run browser and server side... it just sets up that complexity footprint that allows for stuff like this.

I'm not pitching a return to bad old "JSP pages that use jQuery for the fun stuff", but at least that era had clearly defined boundaries. The "UI Guy" role used to fundamentally be a server side rendering space, we spent a decade going against that as we urgently set aside the web's idiomatic way of modeling the world for trying to "feel like an app", and in trying to swing back... well... there are some ugly security misses.

Friday, December 5, 2025

better window titles in vs code

At work we have a monorepo using module federation, and often I find it expedient to open a VS Code window just on the module I'm working on, so ctrl-p and ctrl-shift-f are scoped to the problem at hand. 

(Yes for work I'm back on Windows)

One problem is that by default windows are titled first by the current open file - but you can ctrl-, or cmd-, to open up the settings, look for "window.title" then arrange the string so that rootName is first. This means the current open "folder"/app is more visible on the task bar or alt-tab window selector,

Monday, December 1, 2025

advent-ure

Years ago I had an annual tradition of making "Virtual Advent Calendars" - little toys and games that could run in the browser, one each day for Dec 1-25.

I was heartened to find out that the first years' (which I thought were lost because Java Applets are now deprecated) can be run if you use a Chrome plugin called CheerpJ.

Anyway, here are links to all 7:
2009 (Java Applet)
2011 (Java Applet)
2012 (Started remaking in JS)
2013 (Seasons)
Ed Emberly Animals (plus Santa)
2015 (Games)
2016 (Finale)

Sometimes I miss making these things! It was a fun little tradition, and nice creative outlet.

Sunday, November 23, 2025

new http method just dropped

New HTTP RESTful method just dropped, or is about to: QUERY. It's a GET, except it takes a body rather than stuff everything in the query string. Makes a lot of sense for stuff like GraphQL, where we're sending a lot of fancy queries client side (vs, say, mutations, where other RESTful verbs-with-body-content make sense)


Wednesday, November 19, 2025

an eldritch horror from 2009

 

One advantage of being a literal graybeard is remembering when you see an old problem raise its head and finding artifacts of its earlier reign....  in this case a 2009 post about the inadisability of parsing html via regex

Tuesday, November 18, 2025

smart humble design


 It's almost amusing, in a Don Norman "Design of Everyday Things" sense, how much better the old-fashioned jug is than the pretty new style container. It really makes one appreciate the elegance and cleverness of the integrated handle that easily allows for one handed pouring.


UX and Design really can make life better..