It want a PDF (or PNG) output of a Latex document on one long page, trimmed without the white borders, in minimal runtime.
The preview and standalone packages have this built in in some way and I would like to use their approach. However, both packages have been written with additional goals in mind and have unwanted side effects on paragraphs, floats, footnotes, itemizations, macros etc. which break my documents in other places.
Where do I need a hint?
I would like to extract the feature of setting the pdf page height in one Latex run at the end of this run - as it is used in standalone or preview but I fail to extract the core functionality from these packages: I am simply not good enough in reading their macros. Here I would appreciate some hint.
What else have I tried and failed with?
I used
zref-absoluteor\pdfsavepositionto write the document length to a file, read the file again in the next pdflatex run and then set the paper size as required. Works fine but needs two invocations of pdflatex, which doubles the runtime and is unwanted for my use case.I used
pdf-cropon the result. pdf-crop uses ghostscript to pick up the bounding-box (which takes very long) and it removes the PDF annotations embedded into the file, both of which is a show stopper for my use case. I need the annotations and the timing of ghostscript doubles the runtime.I used
pdf.jsandnodefor PDF->PNG rendering, detecting the bounding box in the PNG, cropping to this box (and for my processing of the annotations). Works, but is very slow.I used
mutool runand its' Javascript interface. I can process the annotations as needed, detect the boundary box, do the PDF to PNG rendering and all of this blazingly fast but I do not manage to properly implement the crop: The PNG always is too large and it looks like the mupdf - Javascript binding either has some form of bug in the implementation of the transformation matrix and did not bind to a suitable cropping method.
So there I am looking at preview and standalone code and trying to extract these probably quite short functionalities...without luck.

\usepackage[margin=0cm]{geometry}then? – Archange Nov 06 '21 at 12:43