Here are my files:
.
├── app.js
├── res.cls
└── res.tex
And here is the relevant contents of my app.js file:
const { spawn } = require('child_process')
const latex = spawn('pdflatex', ['res.tex'])
Running this code successfully creates a res.pdf
file in the same directory. However, rather than creating a file, I would like to get the PDF as a stream and send it as a response to the browser instead. I'm trying to avoid creating any PDF files in the server, I just want to send the generated PDF as a response immediately. Is it possible to alter this code to do this?
res.pdf
in the output directory. This works to the extent thatpdflatex
tries to write to it (without removing it), but apparently it also tries to seek in its output file, which is of course not possible in a pipe. Why not simply read the output file back in? If you do all this on an in-memory filesystem, it should be plenty fast. – Fragrant.aux
and.log
files, for instance. You still haven't clarified why you want to prevent a file being created... don't fall for the XY problem :) – Fragrant.aux
,.log
, and the other generated stuff, I'd like to avoid those as well. The only current thing I can think of is just deleting all the generated files immediately after sending the response, but this doesn't seem like great practice. – Neelyneeoma.tex
file needs to use things like.cls
files with it or font files. I could be wrong though, any help about that would be greatly appreciated. – Neelyneeoma