Sample Header Ad - 728x90

Unix & Linux Stack Exchange

Q&A for users of Linux, FreeBSD and other Unix-like operating systems

Latest Questions

1 votes
2 answers
716 views
How to generate full-page QR code from command line?
I'd like to generate a full-page QR code from the command line. The following command sort of accomplishes this: qrencode -o- https://example.net | convert png:- -gravity center -units pixelsperinch -density 300 -resize 2551x3295 -extent 2551x3295 qrcode.pdf Unfortunately, the resulting QR code is q...
I'd like to generate a full-page QR code from the command line. The following command sort of accomplishes this: qrencode -o- https://example.net | convert png:- -gravity center -units pixelsperinch -density 300 -resize 2551x3295 -extent 2551x3295 qrcode.pdf Unfortunately, the resulting QR code is quite blurry, as though imagemagick is doing some sort of unwanted antialiasing. Is there a way to make the code completely crisp, or just a better/simpler approach to generating a PDF file with a full-page QR code?
user3188445 (5539 rep)
Apr 3, 2024, 06:13 PM • Last activity: Aug 6, 2025, 02:43 PM
0 votes
0 answers
33 views
Relinking OCR data to downscaled images
I have a PDF consisting of scanned pages with OCR done by `tesseract`. I want to downscale the images (by around 4x) and retain the OCR. What would be an automatic way to relink the OCR data to the new coordinates on the pages? --- Original question (*Sudden surge in the size of PDF generated by Gho...
I have a PDF consisting of scanned pages with OCR done by tesseract. I want to downscale the images (by around 4x) and retain the OCR. What would be an automatic way to relink the OCR data to the new coordinates on the pages? --- Original question (*Sudden surge in the size of PDF generated by Ghostscript 9.55.0*): I have a large PDF and am unsuccessfully trying to reduce its size. (The file is copyrighted material, so I cannot post it; I am doing this for personal use. It must be a common problem, though: I had the same experience earlier with other files from different sources.) The file is a scan of a book with 1500 B&W A4 pages of text, no pictures at all. The individual pages were mogrify-ed into PNG images of equal height (around 1000px) and cleaned up via scantailor-advanced. Then each of the pages (now in TIFF) was tesseracted. The results were pdfunited into a 200MB file. This is way too large for this kind of book. I would like to be able to shrink it to around 30MB, perhaps 50. (The total text size extracted by pdftext is 9MB.) Most of the PDF compression methods I found on StackExchange and other sites boil down to gs with varying parameters. On my machine they all behave in a very similar way. I start gs in the terminal and switch to a GUI file manager. The size of the output file grows slowly and steadily from 0 to around 15MB (no matter the settings), and then it gallops in the last split second, as if gs gives up and just dumps the input into the output verbatim. (I attributed this to memory shortage, but the program also exhibits similar behavior on a relatively small, 100-page, part of this file.) If gs is not told to change the DPI (300), the output file becomes as large as the input was. If the DPI is changed to 72, the file becomes 70MB; this is still too much for such a loss in image quality. Is there an explanation of this surge? Should I perhaps use some other toolchain on the raw scans, or a different optimization tool? pdfsizeopt is very slow and seems to lead to 10% reduction. tiff2pdf -j 50 saves 5% (which will be re-added during OCR).
Dilettante (101 rep)
Jul 25, 2025, 07:17 PM • Last activity: Jul 26, 2025, 07:19 PM
39 votes
8 answers
37250 views
Is there a way to flatten a .pdf image from the command line?
In GIMP, I can import a PDF, and use the GUI to flatten it (if it was made with many layers) by selecting `Flatten Image` in the `Image` dropdown menu. I can then export the PDF with a new filename. I would like to automate this. Is there some way to do it via the terminal?
In GIMP, I can import a PDF, and use the GUI to flatten it (if it was made with many layers) by selecting Flatten Image in the Image dropdown menu. I can then export the PDF with a new filename. I would like to automate this. Is there some way to do it via the terminal?
generic_user (637 rep)
Oct 19, 2014, 12:20 AM • Last activity: Jul 26, 2025, 01:31 PM
1 votes
1 answers
69 views
Crop pdf removing content cropped away
I do have a pdf that contains a drawing, a part of which I would like to extract. I am able to open the pdf in inkscape. However, it contains a group with 150k items. As far as I see, there are no subgroups that I could select as entity. Now just trying to select the parts that I would like to delet...
I do have a pdf that contains a drawing, a part of which I would like to extract. I am able to open the pdf in inkscape. However, it contains a group with 150k items. As far as I see, there are no subgroups that I could select as entity. Now just trying to select the parts that I would like to delete does not work (inkscape still has 100% CPU load after 3 hours). Is there a command line tool that would allow me to crop the pdf *and* to delete the elements that are outside the cropped area? This would then allow me to further edit the extracted section using inkscape.
user52366 (221 rep)
Jul 5, 2025, 01:12 PM • Last activity: Jul 5, 2025, 01:43 PM
2 votes
1 answers
3738 views
Ubuntu Linux - Slow printing with lp command
I asked here some months ago how to print and check results with lp command (CUPS) in Ubuntu. After few working around, I was able to print normal text files. I was able to print selecting some options (double sided print, media size, paper tray input, etc.) I got the linux drivers here (PPD files):...
I asked here some months ago how to print and check results with lp command (CUPS) in Ubuntu. After few working around, I was able to print normal text files. I was able to print selecting some options (double sided print, media size, paper tray input, etc.) I got the linux drivers here (PPD files): https://www.openprinting.org/download/PPD/ Now I have a little problem: When I send a .pdf file to the printer (Ricoh MP Aficio 1106 EX connected by TCP-IP), the print goes slow, getting +30 seconds to send the file to the printer. The .txt files print at the moment I send them. Do you have any idea how to solve it? I tryied change the socket of the machine to 9100 port, but that only generates errors. EDIT1: I tryied using LPR command, instead LP: lpr -sPrinterIP /absolute/path/to/file.pdf But works slowly too. EDIT2: I installed qz-tray, a kind of print server/API. When I try PDF demo, it prints slow too. EDIT3: I tryied now with default PDF viewer (EVINCE) because I though I have a lack of memory and printed the same file. It worked well, at normal speed. EDIT4: I tyied some other drivers (generic and recomended by the printer maker ones), same speed. EDIT5: I found this link: https://en.opensuse.org/SDB:Using_Your_Own_Filters_to_Print_with_CUPS But cannot understand if filtering is "f..king me off", because my printer is a PCL one (and i am using a pxl driver...). Could anyone explain me this? EDIT 6: Found the origin of the problem: When I print a text-only-pdf file, it works like a charm. But when I send an image-pdf file, the print enters in a pre-print process (I cannot completely assure this) and get +30seconds to send any package to printer (this checked with wireshark). I can asume that PPD file (driver file provided by Ricoh Support) has anything in the code that send any order to process the file. I found this in the PPD file. I think is the root of this slowing problem: *%========== Ghostscript Command line ========== *FoomaticRIPCommandLine: "(printf '\033%%-12345X@PJL\n@PJL JOB\n@PJL SET COPIES=&copies;\n'%G|perl -p -e "s/\x26copies\x3b/1/" (gs -q -dBATCH -dPARANOIDSAFER -dNOPAUSE -dNOMEDIAATTRS -dNOINTERPOLATE %B%A%C %D%E | perl -p -e "s/^\x1b\x25-12345X//" | perl -p -e "s/\xc1\x01\x00\xf8\x31\x44/\x44/g" (printf '@PJL\n@PJL EOJ\n\033%%-12345X&apos" *End Found this article https://lists.linuxfoundation.org/pipermail/printing-foomatic/2012/002791.html taht confirms my ideas: the ppd driver is rendering all files with ghostcript. EDIT 7: Ricoh support told me that "lp" printing command may be using "default PDF viewer" to process the file, and slow the print process. I don't know how to check it. Thanks a lot.
Barragán Louisenbairn (43 rep)
May 26, 2017, 05:50 PM • Last activity: Jul 3, 2025, 09:06 AM
10 votes
2 answers
2528 views
How to convert a pdf to 4-up in landscape mode (ideally using ghostscript)?
I have pdf slides in landscape mode and would like to create a new pdf file containing the slides 4-up (in landscape mode again) like this: ----------------- | 1 | 2 | ----------------- | 3 | 4 | ----------------- I know that there is `pdfjam` (which can be used like this `pdfjam --fitpaper true --n...
I have pdf slides in landscape mode and would like to create a new pdf file containing the slides 4-up (in landscape mode again) like this: ----------------- | 1 | 2 | ----------------- | 3 | 4 | ----------------- I know that there is pdfjam (which can be used like this pdfjam --fitpaper true --nup 2x2 --delta '1mm 1mm' --scale 0.98 infile.pdf), but it does not preserve hyperlinks -- gs does, though. I am wondering how one could use gs to achieve the task (?) Alternatively, I mainly use 4-up to print slides. I couldn't manage to use lpr for achieving this. If someone has an idea for that, this would be interesting as well.
mathlete (480 rep)
Apr 26, 2013, 08:53 PM • Last activity: Jun 28, 2025, 09:05 AM
2 votes
1 answers
68 views
Redirect `rtf` output to file
### System Info ``` alinuxchap@libertus-desktop:/usr/share/X11/xkb $ uname -a Linux libertus-desktop 6.12.25+rpt-rpi-v8 #1 SMP PREEMPT Debian 1:6.12.25-1+rpt1 (2025-04-30) aarch64 GNU/Linux alinuxchap@libertus-desktop:/usr/share/X11/xkb $ ``` ### Cmd ``` cd /home/alinuxchap/Documents/shared/dat/EDS/...
### System Info
alinuxchap@libertus-desktop:/usr/share/X11/xkb $ uname -a
Linux libertus-desktop 6.12.25+rpt-rpi-v8 #1 SMP PREEMPT Debian 1:6.12.25-1+rpt1 (2025-04-30) aarch64 GNU/Linux
alinuxchap@libertus-desktop:/usr/share/X11/xkb $
### Cmd
cd /home/alinuxchap/Documents/shared/dat/EDS/it
echo "" > output.txt
while read author; do
	echo $author
	pdfgrep "$author" *.pdf |& tee -a output.txt
done 
### Problem - grep outputs text matches in bold and red - I don't want to use grep -p as I also need to see the 'snippet' of context the term is being used in It's useful for archiving command output as 'logs'; the same problem arises with copy and paste, as that doesn't preserve rtf either.
Signor Pizza (25 rep)
Jun 17, 2025, 05:35 PM • Last activity: Jun 20, 2025, 08:02 PM
7 votes
4 answers
3714 views
Tool for mirroring PDF-file?
There are plenty of tools that can rotate a PDF. Is there a tool that can mirror it, too? I am not looking for a solution that first converts to a bitmap, then mirrors and then converts the bitmap to PDF, but for a tool that can do the mirroring with no loss of quality. So in PostScript terms I am l...
There are plenty of tools that can rotate a PDF. Is there a tool that can mirror it, too? I am not looking for a solution that first converts to a bitmap, then mirrors and then converts the bitmap to PDF, but for a tool that can do the mirroring with no loss of quality. So in PostScript terms I am looking for 1 -1 scale 0 -height transform.
Ole Tange (37348 rep)
Jan 14, 2018, 01:38 PM • Last activity: Jun 18, 2025, 02:08 PM
4 votes
1 answers
1913 views
Preview Pane for PDF Documents in File Manager
Is there a program (e.g., file manager or PDF viewer) that provides a split view having a folder view and preview pane for PDF documents (ideally with the ability to scroll through the document like the preview pane in Windows 7)? I have 100's of PDF documents that I need to preview rapidly. The fil...
Is there a program (e.g., file manager or PDF viewer) that provides a split view having a folder view and preview pane for PDF documents (ideally with the ability to scroll through the document like the preview pane in Windows 7)? I have 100's of PDF documents that I need to preview rapidly. The file names are not helpful because they are auto-generated. I have used various file managers that generate thumbnails of the first page, but the thumbnails are too small to distinguish between documents. Additionally, it is often desirable to display subsequent pages in the same document. I have tried batch opening the files in Foxit, but the number and size of files typically causes the program to crash. I have tried Krusader, which spawns an external preview Krviewer window. This is not sufficient because it requires opening and closing the Krviewer for every file (similar to simply doing "open with..." an external program), which is slow. Another StackExhange answer appears to show the desired behavior, but it does not appear to function in the installed version for Ubuntu 18.10 (Konqueror Version 5.0.97). See Konqueror and https://www.donationcoder.com/forum/index.php?topic=44064.0
user2514157 (225 rep)
Mar 8, 2019, 07:07 PM • Last activity: Jun 11, 2025, 01:06 PM
3 votes
3 answers
5814 views
Regex search in PDF reader
I am using zathura, as I enjoy its minimalist approach, but I would also switch to mupdf or anything else if this would solve my problem. I need to highlight every word (in PDF and epub documents) one by one from start to finish because I can concentrate better on the text if I have some kind of mot...
I am using zathura, as I enjoy its minimalist approach, but I would also switch to mupdf or anything else if this would solve my problem. I need to highlight every word (in PDF and epub documents) one by one from start to finish because I can concentrate better on the text if I have some kind of motion in it. My approach would have been to perform a regex search that matches every word, but neither zathura nor mupdf support regex in searches. Is there a way to do this? I would try to fork zathura but to be honest I don't really want to spend that amount of time if there is another minimal Gnu/Linux compatible document viewer that does what I need. And if there is any way to use terminal tools like pdfgrep for highlighting the results in zathura that would also do the job.
luca (152 rep)
Mar 29, 2020, 03:38 PM • Last activity: Jun 6, 2025, 09:30 AM
1 votes
2 answers
2119 views
Converting a TXT file to PDF from the command line using a custom font
I want to convert a UTF-8 txt file to PDF for printing with CUPS. The problem I'm facing is that all tools I've tried have either failed to format the PDF (resulting in a fully white document with no text) or ignored font options. I have also tried converting my text file to PostScript 1st (as sugge...
I want to convert a UTF-8 txt file to PDF for printing with CUPS. The problem I'm facing is that all tools I've tried have either failed to format the PDF (resulting in a fully white document with no text) or ignored font options. I have also tried converting my text file to PostScript 1st (as suggested in some previous answers to similar topics) but have faced issues with then printing the PostScript files with the added fonts. What I have tried: text2pdf (creates blank document when custom font specified) unoconv (fails to run with network error) LibreOffice CLI (no font parameters) enscript (initial PostScript conversion works however when then printing that PS or converting it to PDF the font reverts to courier) paps (PostScript conversion succeeds but font parameter seemingly ignored as file is the same regardless of what font you specify or whether or not it exists) pandoc (font options ignored)
psvg200 (11 rep)
Jun 26, 2023, 08:02 PM • Last activity: Jun 3, 2025, 02:04 AM
1 votes
1 answers
480 views
How to include an image in multiple PDF files at once in Linux?
I have to sign a lot of PDF documents that have a standard layout. My signature would be included on the same place in every pdf file. That is, I received a lot of PDFs that I have to sign one by one. I would like to automate the task. Is there any good alternative to do this? Best regards.
I have to sign a lot of PDF documents that have a standard layout. My signature would be included on the same place in every pdf file. That is, I received a lot of PDFs that I have to sign one by one. I would like to automate the task. Is there any good alternative to do this? Best regards.
Zaratruta (111 rep)
Aug 24, 2021, 08:05 PM • Last activity: May 29, 2025, 04:51 PM
3 votes
1 answers
2445 views
Change PDF page size without re-scaling a content (CLI)
## Question I have a PDF with a non-standard page size. I would like to change PDF canvas size to A4 without re-scaling the content. I can receive the expected result with Printing to PDF (picture below, original content is a black rectangle). However, I would like to achieve the same result using L...
## Question I have a PDF with a non-standard page size. I would like to change PDF canvas size to A4 without re-scaling the content. I can receive the expected result with Printing to PDF (picture below, original content is a black rectangle). However, I would like to achieve the same result using Linux CLI. What I would like to receive How can I change PDF page size **without** rescaling the content, using the Linux command line? ## Investigation I have tried to use pdfjam: pdfjam --outfile out.pdf --paper a4paper in.pdf. Unfortunately, it scales to fit in.pdf and thats unacceptable for me. Also I tried cpdf: cpdf -scale-page a4portrait in.pdf -o out.pdf scales content to the page size. Moreover, found PdfScale . However it can only scale content or change page size with fitting the content. The similar problem has been described here , but the author used GUI application (not CLI)
Toliak (131 rep)
Nov 14, 2021, 07:10 PM • Last activity: May 29, 2025, 03:04 AM
0 votes
3 answers
331 views
How do I extract some pages of a PDF into another PDF file?
I have a PDF file with multiple pages, and I want to write a command which extracts some of these pages into a new, separate PDF file; and the pages of interest are not necessarily a contiguous range. How do I do that? Notes: * It has to be a command I can put in a (shell) script, not a GUI applicat...
I have a PDF file with multiple pages, and I want to write a command which extracts some of these pages into a new, separate PDF file; and the pages of interest are not necessarily a contiguous range. How do I do that? Notes: * It has to be a command I can put in a (shell) script, not a GUI application I can interact with to achieve this effect. * The pages to be extracted do not necessarily form a contiguous range. * If you want a concrete example, let's assume I want to extract pages 1 through 4 and page 6 of input file foo.pdf, with the result placed in bar.pdf.
einpoklum (10753 rep)
May 26, 2025, 11:10 AM • Last activity: May 27, 2025, 03:01 AM
1 votes
2 answers
2539 views
Extract Part of a Single PDF Page from Bash
In order to extract a part of a PDF page on a Gnu/Linux machine I use the following command: gs -sDEVICE=pdfwrite -o out.pdf -g2300x2300 input.pdf The `-g...x...` option lets me choose coordinates on the input PDF. So, here is my question: 1. How do I shift the coordinates so that any rectangle on t...
In order to extract a part of a PDF page on a Gnu/Linux machine I use the following command: gs -sDEVICE=pdfwrite -o out.pdf -g2300x2300 input.pdf The -g...x... option lets me choose coordinates on the input PDF. So, here is my question: 1. How do I shift the coordinates so that any rectangle on the input PDF might be chosen? and extending that question: 2. Is there any graphical interface that allows choosing the coordinates I want? (so far it's trial and error.) ---- I do not want to extract whole pages from the input PDF. The output format should again be PDF. I am not looking for extraction of text or images. A similar question had been asked on askubuntu.org , but the answers only deal with extracting whole pages or page ranges. I know I can do that with pdftk. A yet more specific question similar to this on was asked here before , but remained unanswered. On a Mac this whole affair is absolutely simple: The program preview has a function for exactly that. How do I snapshot a part of a single PDF page to output format PDF?
user332450
Jan 27, 2019, 09:43 AM • Last activity: May 26, 2025, 02:01 PM
10 votes
2 answers
8609 views
Remove page or page range from pdf with qpdf
I've been growing fond of [qpdf's simplicity](https://unix.stackexchange.com/questions/394065/command-line-how-do-you-rotate-a-pdf-file-90-degrees/634882#634882) and speed. Is there a way to use qpdf to remove a page or page range from a pdf document using qpdf? Say I want to remove pg 2. Say I want...
I've been growing fond of [qpdf's simplicity](https://unix.stackexchange.com/questions/394065/command-line-how-do-you-rotate-a-pdf-file-90-degrees/634882#634882) and speed. Is there a way to use qpdf to remove a page or page range from a pdf document using qpdf? Say I want to remove pg 2. Say I want to remove pg 4-7.
mcp (827 rep)
Feb 8, 2022, 10:02 PM • Last activity: May 26, 2025, 12:08 PM
5 votes
4 answers
869 views
Eliminate duplicate pages from pdf
I have a pdf document with over 200 duplicate pages among the total 900 of the document. When there is a duplicate, it appears immediately after the original. Maybe with `pdftk` the job can be done, but I need some way to find out the duplicates...
I have a pdf document with over 200 duplicate pages among the total 900 of the document. When there is a duplicate, it appears immediately after the original. Maybe with pdftk the job can be done, but I need some way to find out the duplicates...
fich (340 rep)
Jun 20, 2021, 07:50 PM • Last activity: May 25, 2025, 05:25 AM
0 votes
1 answers
41 views
Spliting PDF while keeping index in the new file
I have got a PDF file with many tomes in it. Because it contains a lot (>5,000) of pages I want to split it. I have used `pdftk` like this: ```bash pdftk input.pdf cat 487-2987 output second_tome.pdf ``` It works, but somehow `pdftk` doesn't put index in the output file. Because the content has many...
I have got a PDF file with many tomes in it. Because it contains a lot (>5,000) of pages I want to split it. I have used pdftk like this:
pdftk input.pdf cat 487-2987 output second_tome.pdf
It works, but somehow pdftk doesn't put index in the output file. Because the content has many chapters I would like it to keep index, so I could quickly skip to a chapter in my PDF viewer. I tried gs, but it behaves similar to pdftk: it doesn't write index. And works very slow. I tried qpdf, which **do** keep the index, but it puts the *entire* index of the input PDF, which results in the output file having information of all old contents. Also, if (like in the example above) I want to separate a range of pages, the "first" page in the output PDF will not start from 1. Is there any way to do a split with an index?
Felix.leg (103 rep)
May 24, 2025, 10:35 AM • Last activity: May 24, 2025, 12:54 PM
0 votes
2 answers
1914 views
img2pdf batch script
I currently have over 10K folders. Each folder has .png and .jpg images that need to be turned into .pdf files. Files are numerically in order already. I am looking for speed. I can currently cd into each folder and run img2pdf * -o out.pdf And I get a perfectly created out.pdf in less than a second...
I currently have over 10K folders. Each folder has .png and .jpg images that need to be turned into .pdf files. Files are numerically in order already. I am looking for speed. I can currently cd into each folder and run img2pdf * -o out.pdf And I get a perfectly created out.pdf in less than a second, even with several hundred images. My end goal is to automate this in a shell script that can be invoked, so each folder is basically turned into a .pdf file with the filename the same as the old directory like so Directory001/img001.jpg img002.jpg img003.jpg OtherDirectory/img1.png img2.png img3.png becomes Directory001.pdf OtherDirectory.pdf while only use img2pdf to do this, as it is by far the fastest way create the pdfs. I have some simple bash experience, but only with simple one liners (like turning all directories to zips). I know this can be done, but have no idea where to begin.
lolimans (1 rep)
Feb 17, 2019, 03:00 PM • Last activity: May 22, 2025, 11:07 AM
13 votes
5 answers
81335 views
How do I extract the colours from a PDF?
I have a PDF and I want to verify the colours being used (check that they match our corporate colour scheme for instance). Specifically, I want to check that the correct CMYK colours are being used. How could I go about doing that?
I have a PDF and I want to verify the colours being used (check that they match our corporate colour scheme for instance). Specifically, I want to check that the correct CMYK colours are being used. How could I go about doing that?
Alex Chamberlain (2090 rep)
Oct 17, 2012, 10:02 AM • Last activity: May 20, 2025, 11:34 AM
Showing page 1 of 20 total questions