Thermal printer leaves too much blank space printing QR - qr-code

I want to print a QR in my thermal printer. I use the following command
lpr -P POS58 qr.png
As you can see my QR is a PNG image. It prints it totally fine except for the fact that before the QR the printer leaves a lot of blank paper.
How could I fix this?

The solution I found is using again the png2escpos library Link previously reducing the size of the image to ~250px wide so it fits in the paper size (I had to try a couple of times before getting it right).
You can save the binary data in a file so you can print it directly later
./png2escpos my_qr.png > my_qr.bin

Related

Changing the vector file type with inkscape causes the new vector file to have a different size

I am using inkscape to change the file type from a pdf to an emf. I noticed when I open the files in corel (to check that it was outputted correctly) that they are different sizes than each other - the pdf is the size I set it to be initially (as you'd expect), while the emf is a plain letter size (8.5 x 11).
If I am only using
inkscape 49.pdf -o 49.emf
on the command line, why is it changing the document size? Is there a way to preserve it? Has any one else had this problem? I've checked the man page for options and I haven't seen an explicit command to preserve page size (though I don't believe I should have to even do).
Thank you so much for your input!

Improve zbarimg qrcode recognition

I had a working system of scanning sheets of paper and then letting zbarimg recognize qrcodes on these sheets (while I don't know in which area the qrcode appears). Suddenly qrcode recognition got much worse and eventually stopped working at all.
The physical scanner generates PDFs from the scanned sheets of paper. I use ghostscript to convert it to a picture:
gs -sDEVICE=png16m -sCompression=lzw -r600x600 -dNOPAUSE -sOutputFile='scantest.png' scantest.pdf
This is the result:
When you try to read the qrcode with your smartphone, it will be recognized immediately. But when I run zbarimg:
zbarimg scantest.png
Zbarimg doesn't recognize anything:
scanned 0 barcode symbols from 1 images in 6,6 seconds
I tried to apply this solution:
https://stackoverflow.com/a/40609947/4654597
But without any luck, actually it destroyed the qrcode totally:
I also tried to apply a light blur filter like suggested in this post:
Decode QR-Code in scanned PDF
I used ImageMagick for this task:
convert scantest.png -blur 1x1 scantest_after_blur.png
I also tried 1x2, 1x3, 1x4, 1x6, 1x8 but nothing helped.
How could I get zbarimg to work again?
Here is what finally worked:
convert input.png +repage -threshold 50% -morphology open square:1 output.png
zbarimg output.png
Most important is probably applying morphology. I got the whole ImageMagick command from this post: QR code detection with ZBar from console fails for valid QR codes (ZBarCam from camera detects them fine)

gnuplot - How can I save a graphics file of a plot that is the same as I designed it in xterminal?

I have been making plots for some time now, and they are precisely the way I like them, on screen. The data is coming in from sensors related to solar power collection and storage.
Plotted on screen they look great so I do a screen region capture to save them.
So now I would like to automate the saving process.
Here is what I have done so far:
I set up a cron job so they would be run right at midnight, capturing the whole day and saving it as a .png file
Then it moves the "today.dat" data file to the archive named by date.
This part is all working as designed.
EXCEPT, by using .PNG the images do not look the same.
I really thought png would be the best option, but it turns out that the font used for the X-axis (HH:MM ticks) is too thick and they run together. It looks like a crayon-drawn version of my plot designs.
Can someone please give me some guidance on how to best programatically generate the plots for saving so they look like the way I designed them?
As pointed out in the comments above, the best way is probably to use a different terminal for output to an image file, and simply ignore the fact that the generated images are not identical to what you see on your screen when using the x11 terminal. However, if you really need an exact copy, there are (at least) two options:
You could automate the process of taking a screenshot. You can even do this from within gnuplot, where it might come handy that the GPVAL_TERM_WINDOWID variable contains the X Windows ID for the current plot window. You can use that to make a screenshot of the window after you made the plot:
system(sprintf("xwd -id 0x%x | convert xwd:- screenshot.png", GPVAL_TERM_WINDOWID))
Here I included a call to convert to convert the xwd file format to png.
Another option is to use the xlib terminal, which saves the sequence of commands that the gnuplot_x11 helper application turns into the window you see on the screen. For example,
set term push; set term xlib; set output "file.xlib"; replot; set output; set term pop
will create the file file.xlib that has all the information of the last plot. To later view this plot, use
gnuplot_x11 -noevents -persist < file.xlib
where you might have to specify the path to gnuplot_x11.
Similar as #user8153 suggested for x11, you can use import, which is as convert an imagemagick tool
system("import -window ".GPVAL_TERM_WINDOWID." screenshot.png")
Convenient is also a shortcut to copy the image into clipboard and paste it with Ctrl+v elsewhere:
bind Ctrl-c 'system("import -window ".GPVAL_TERM_WINDOWID." png:- | xclip -sel clip -t image/png")'
See also Show graph on display and save it to file simultaneously in gnuplot.

Output graph to a two page PDF

I am doing a forest plot and want to save it to a PDF file.
My forest plot is oversize (8in*20in). It can fit in a one page PDF like this:
dev.print(pdf, file="C:\\Work\\plot.pdf", width=8, height=20);
But then it is too long: When I print this PDF on a A4 paper, it has to be shrinked to fit the paper.
So I want to save it to a two-page PDF file (from R). Ps: it is not a question about how to set the printer.
How to do this?
So, you are able to generate an 8in x 20in == 203.2mm x 508mm == 576pt x 1440pt sized PDF showing a plot.
It is not entirely clear to me from your question what exactly you want:
Generate the PDF plot so that it is divided into two different pages from the beginning?
Take the PDF as is and during the print job setup find these settings which would print it onto two different pages by posterizing the original page?
Post-process the PDF that you created to posterize it and create a 2-page output PDF (which you can then print)?
Assuming '1.': generate PDF plot distributed over 2 pages
Sorry, I cannot help here...
Assuming '2.': print setup to print 1 PDF page on 2 sheets of paper
If you print a PDF from Adobe Acrobat or from Adobe Reader, then you'll find a setting in the print dialog named "Poster". Here you can select to print one PDF page across multiple pieces of paper. (It also lets you select if you want some overlap from piece to piece, and if you want to add cut marks and the like to the printouts).
Assuming '3.': post-process 1 PDF page to stretch over 2 A4 pages
MuPDF is a lightweight PDF (and other document formats) viewer, made by the same company that also maintains Ghostscript. MuPDF ships with an additional command line utility, mutool.
Its subcommand poster can divide PDF pages into smaller tiles and 'posterize' them. So this command will achieve what you want:
mutool poster -x 1 -y 2 input.pdf output.pdf
The output.pdf will be divided into 1 part (i.e. not divided) in x-, and into 2 equal parts in y-direction. (You could divide it into any other number of segments if you wanted). So output.pdf will have two pages, each sized 8in x 10in. A4 paper is sized 8.26in x 11.69in when measured in Inches.
When printing these, you'll still need to enable the Print to fit Page Size checkbox in the print dialog if you want to make best use of the A4 page size.
Ghostscript is a command line tool that can (amongst many other functions) be used to process PDF files (PDF in, modified PDF out). It can be (ab)used to cut PDF pages into halfs.
Here are a few previous StackOverflow answers which describe how to do it. You'll need to adapt some parameters to your specific size(s), but the principles should be clear from those examples (even though some of these split pages into left and right halves, not top/bottom as you may require):
Linux-based tool to chop PDFs into multiple pages (SuperUser)
Freeware to split a pdf's pages down the middle? (SuperUser)
Convert PDF 2 sides per page to 1 side per page (SuperUser)
How can I split a PDF's pages down the middle? (SuperUser)
Cropping a PDF using Ghostscript 9.01 (StackOverflow)
PDF - Remove White Margins (StackOverflow)
Split one PDF page into two (StackOverflow)
The method described there is more tedious and not as straight-forward as with the mutool poster method.
Maybe not the answer you are looking for but you could print it in another vectorial format (e.g. svg) and then export it as pdf on two pages with a (vectorial) image editor.
Edit: If ploting in pdf works well despite the big size of the graph there are also tools to split pdf pages. You can find some directions here:
https://superuser.com/questions/437148/how-to-split-a-pdf-onto-multiple-pages-on-command-line
Windows equivalent of pdfposter could be Rasterbator or PosteRazor, for example.

Using GhostPCL to converting PCL with images to PDF

I'm currently attempting to convert some PCL files into PDF using GhostPCL (PCL6).
For the most part this works. However, there is an odd problem with some of the conversion. For some reason, PCL6 is not converting some logos where are at the top of our documents. The logo is of the format:
^[(25XABCDEFGHIJKLMNOPQ^[(3#^M
^[(25X^[&a+1.49RRSTUVWXYZ[\]^_`ab^[(3#^M
^[(25X^[&a+1.49Rcdefghijklmnopqrs^M
when viewing the PCL file in vim. When printing the file as a PCL file, the image prints out correctly, but when converting to pdf, the following takes it's place:
ABCDEFGHIJKLMNOPQ
RSTUVWXYZ[\]^_`ab
cdefghijklmnopqrs
I recognize that the format is meant to be matched against some sort of embedded image or font, but it has been really difficult trying to find useful documentation on PCL (so I can actually figure out what these characters mean) or the conversion process.
Can anyone offer some insight on how to approach the conversion? We will need these images/logos in the converted documents since they often contain disclaimer information as part of the image.
EDIT1: I've also attempted converting to postscript and printing then and the same behavior occurs.
EDIT2: When rendering the PCL file in a viewer, the same text shows up instead of the image. But when printing, the logo does show up. Strange...
EDIT3: To clarify, sending the PCL file to a printer directly does not seem to cause the problem (i.e, the logo does print correctly). It's only when I attempt to convert it to another file format that the problem occurs.
What happens when you try rendering the PCL input with Ghostscript ? Eg to the display device. If it doesn't render its not going to end up in a PDF either.
Have you tried printing the file to a PCL printer ?
If it works to a PCL printer, but not when rendering you can open a bug against ghostpcl. If it renders but does not end up in the PDF then you can open a bug against ghostspcl with the 'pdf writer' component.
Its possible that the logo is shown using a rasterop, this is a part of the PCL imaging model which has no counterpart in PDF and so cannot be reproduced. The result of using a rasterop with the PDF device is variable, sometimes it will do what you expect, often it will not.

Resources