Can't print pdf document

Hi,
I’m using puppeteer to create a PDF file and then using pdf-to-printer (GitHub - artiebits/pdf-to-printer: Print PDF files from Node.js and Electron.) to print it to a default printer. Code:

                const browser = await puppeteer.launch({
                          args: ['--no-sandbox', '--disable-setuid-sandbox'],
                 });
                const page = await browser.newPage();
                const content = await compile('order', data);
                const document = {
                    path: './public/images/' + getOrderPdf.id + 'order.pdf',
                    format: 'A4',
                    printBackground: true
                };
                await page.setContent(content);
                await page.emulateMediaType('screen');
                await page.pdf({...document});
                await browser.close();

                const options = {
                    unix: ["-o fit-to-page"],
                    win32: ['-print-settings "fit"'],
                  };
                ptp
                    .print(document.path, options)
                    .then(print => {
                        console.log
                        fs.unlinkSync(document.path);
                    })
                    .catch(console.error);

And when I try this on localhost it works just fine but, when I try it on my glitch web app, I get this error:

/bin/sh: 1: lp: not found\in
command failed lp

I couldn’t find anything on the internet that could help solve this, so I got the idea that it might be something about glitch or Linux that is doing this.

I hope I’m clear about this issue.You can ask me anyways.

Thanks!

Hi @facumartinn, welcome to the forum :slight_smile:

It appears to me that this bit of code has a dependency on the lp Linux command. So I suspect this command doesn’t exist on Glitch containers because they have no reason to print (physically!)

I wonder if you can find another tool or way to export to PDF without using the print command?

Let us know :slight_smile:

2 Likes

Hi @SteGriff , thanks for the reply!

I thought it was something about that. What I don’t understand is that the OS is linux in glitch, so why this won’t work?

The thing is that I need to automatically print without opening a new tab with the pdf file, but maybe that’s the only way.

What you are trying to achieve here? Do you want to print from Glitch to your home printer using something like ipp? Why no just save the document and print it on your computer?

1 Like

I believe it’s “printing” it to PDF (from image/HTML)

1 Like

It’s a picking app, the employee picks up products for an order and when he finishes, the pdf is created with all the order data and prints it to the printer in the warehouse automatically.

for the sake of not rewriting a lot of stuff I copied some stuff from an older post.

So your glitch application runs on a another specialized variant of a computer designed to run for long periods of time called a server (it runs linux if you’re curious so that’s why you have the lp thing). This server does not have any access to the devices on your personal network unfortunately like printers, so unfortunately your program will only work if it’s on a computer on the same network as your printer. The reason we can load glitch websites in the browser is because there you are explicitly letting the glitch server connect to your home network temporarily to send you a website.

2 Likes

I imagine it wouldn’t be impossible (or too difficult) to run a small app on your company server that accepts .pdf files and routes them to your printer. Your Glitch-hosted app would “send” the file to that app (securely of course) which gets the file onto your company network while still under your control.

There are probably even some ready-made service apps you could use. It needs to be scriptable as when files arrive they must be acted upon.

1 Like

Yes, I think the fastest solution might be to generate the PDF via puppeteer and save it in public folder, and then a click event opens that file in a new tab and make the printing manually.