Unix & Linux Stack Exchange
Q&A for users of Linux, FreeBSD and other Unix-like operating systems
Latest Questions
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
1
votes
2
answers
2540
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
2
votes
2
answers
2794
views
Using Ghostscript to extract every nth page from PDF
I don't know if this can be done, I'm just learning ghostscript. Say I have multiple PDF files each about 500 Pages in length. Can I setup ghostscript to go extract every 100 pages from each document and save each as a separate PDF file? So I have FileA.pdf, 500 Pages in Length. So I'd now want **Fi...
I don't know if this can be done, I'm just learning ghostscript. Say I have multiple PDF files each about 500 Pages in length. Can I setup ghostscript to go extract every 100 pages from each document and save each as a separate PDF file?
So I have FileA.pdf, 500 Pages in Length. So I'd now want **FileA_0001.pdf FileA_0002.pdf FileA_0003.pdf FileA_0004.pdf FileA_0005.pdf**
I've managed to write a script that will split files and merge them based on my interval, I'm having trouble trying to rename files properly. The issue I've run into is after it finishes splitting and merging after the first file it will rename it as **FileA_0001.pdf FileA_0002.pdf FileA_0003.pdf FileA_0004.pdf FileA_0005.pdf**
However the problem is once it begins the process for FileB, it does this **FileB_0006.pdf FileB_0007.pdf** I've tried a few different ways, but each have failed, advice? Can someone assist?
for file in /mnt/bridge/pdfsplit/staging/*.[pP][dD][fF]
do
echo $file
#Splits All the Files
gs -q -dNOPAUSE -sDEVICE=pdfwrite -o tmp_%04d.pdf $file
#Removes Last File in List; Ghostscript creates a blank file everytime it splits
find /mnt/bridge/pdfsplit/ -name "tmp*" | tail -1 | while read filename ; do rm $filename; done
pageCount=$(find . -name "tmp*" | wc -l)
documents=$(((pageCount / 998) + (pageCount % 998 > 0)))
pages=$(((pageCount/documents) + (pageCount % documents > 0 )))
for ((i=1; i/dev/null | head -$pages)
count=$(ls -1 tmp* 2>/dev/null| wc -l)
gs -q -dNOPAUSE -sDEVICE=pdfwrite -o $(basename $file .pdf )_Part_$(printf %04d $i).pdf -dBATCH $list
rm -f $list
if [[ $count -eq 0 ]]; then
echo "Done"
break
fi
done
#Removes Last File in List; Ghostscript is creating a blank file
mv *.pdf /mnt/bridge/pdfsplit/splitFiles/
find /mnt/bridge/pdfsplit/splitFiles/ -name "*.pdf" | tail -1 | while read filename ; do rm $filename; done
done
Josh Adams
(83 rep)
Mar 20, 2019, 07:20 PM
• Last activity: May 24, 2025, 08:05 AM
1
votes
0
answers
49
views
With ghostscript, how to upscale a PDF file that is wider than taller so that the new width matches the width of a portrait A4 sheet of paper?
Let's take a PDF file that is slightly wider than taller, e.g., https://we.tl/t-iihJ3gMsrA : pdfinfo input.pdf | grep "Page size" Page size: 397.349 x 378.153 pts Let's try to upscale it so that the new width matches that of a portrait A4 sheet, i.e., 210 mm or 595 pt. How to do this with `gs` only?...
Let's take a PDF file that is slightly wider than taller, e.g., https://we.tl/t-iihJ3gMsrA :
pdfinfo input.pdf | grep "Page size"
Page size: 397.349 x 378.153 pts
Let's try to upscale it so that the new width matches that of a portrait A4 sheet, i.e., 210 mm or 595 pt. How to do this with
gs
only? So far, we tried
gs -o output.pdf -sDEVICE=pdfwrite -dFIXEDMEDIA -dPDFFitPage -dAutoRotatePages=/None -dDEVICEWIDTH=5950 -dCompatibilityLevel=1.4 -dNOPAUSE -dBATCH input.pdf
and variations thereof, but the output came out rotated counterclockwise 90° :-(. Any adjustment to the command so that the output comes out upright?
AlMa1r
(1 rep)
Apr 19, 2025, 07:37 PM
• Last activity: Apr 21, 2025, 12:47 PM
14
votes
2
answers
6790
views
How to make ghostscript not wipe PDF metadata
Ghostscript wipes the PDF metadata like `author, title, subject` etc. How can I tell ghostscript not to touch the metadata? I invoke it as follows: gs \ -dBATCH \ -dNOPAUSE \ -sOutputFile= \ -sDEVICE=pdfwrite \ -dPDFSETTINGS=/ebook \
Ghostscript wipes the PDF metadata like
author, title, subject
etc. How can I tell ghostscript not to touch the metadata? I invoke it as follows:
gs \
-dBATCH \
-dNOPAUSE \
-sOutputFile= \
-sDEVICE=pdfwrite \
-dPDFSETTINGS=/ebook \
Marco
(34188 rep)
Oct 10, 2012, 02:17 PM
• Last activity: Feb 17, 2025, 04:00 AM
2
votes
1
answers
638
views
How to stop Ghostscript from adding "Producer" metadata to PDF files
I processed a PDF file using Ghostscript: ```sh gs -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pdfwrite -q -o output.pdf input.pdf ``` When I used a text/binary editor to look into the output PDF, I noticed that Ghostscript has added "Producer" metadata to the PDF. Ghostscript added `/Producer(GPL Ghostscrip...
I processed a PDF file using Ghostscript:
gs -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pdfwrite -q -o output.pdf input.pdf
When I used a text/binary editor to look into the output PDF, I noticed that Ghostscript has added "Producer" metadata to the PDF. Ghostscript added /Producer(GPL Ghostscript 10.00.0)
to the PDF information dictionary, and also added `` to the XMP metadata. How do I stop Ghostscript from adding this metadata?
Flux
(3238 rep)
Jan 11, 2024, 05:28 PM
• Last activity: Feb 17, 2025, 03:56 AM
10
votes
5
answers
7114
views
How can I convert a scanned PDF with OCRed text to one without OCRed text?
I have [a scanned PDF file][1], with low-quality OCRed text. I would like to have a PDF file without the OCRed text. How can I convert a scanned PDF with OCRed text to without OCRed text? I am thinking about what ways can recover the original scanned PDF file before OCR as much as possible, without...
I have a scanned PDF file , with low-quality OCRed text.
I would like to have a PDF file without the OCRed text.
How can I convert a scanned PDF with OCRed text to without OCRed text?
I am thinking about what ways can recover the original scanned PDF file before OCR as much as possible, without changing the width and height of each page in pixels, and without changing the pixels per inch of each page?
Is some kind of rasterization again help? Will rasterization again loose the image quality?
Several attmepts:
1. I use the print to file in Evince, which I think uses
cups-pdf
, it
doesn't remove OCRed text.
2. Following command using gs
doesn't remove OCRed text either (I think I haven't found out how to use gs
properly):
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 \
-dNOPAUSE -dQUIET -dBATCH -sOutputFile=out.pdf toc.pdf
Tim
(106420 rep)
Dec 7, 2014, 12:30 PM
• Last activity: Nov 21, 2023, 08:16 PM
31
votes
4
answers
28139
views
How do I insert a blank page into a PDF with ghostscript or pdftk?
I have a PDF file that needs a blank page inserted into it every so often. The pattern is unpredictable, so I need a command that will allow me to fit one in wherever necessary. How can i do this?
I have a PDF file that needs a blank page inserted into it every so often. The pattern is unpredictable, so I need a command that will allow me to fit one in wherever necessary.
How can i do this?
ixtmixilix
(13520 rep)
Jul 2, 2011, 11:49 PM
• Last activity: Nov 7, 2023, 11:08 AM
2
votes
0
answers
319
views
Combine PDFs to new PDF with filenames as bookmarks
I have a directory *foo* containing .pdf files named with pattern *X01, X02, ...*, each two pages long. I want to combine them to a new .pdf, named "_all_YY-MM-DDTHHMMSS.pdf_" that will contain the file names as bookmarks. I used these two commands. While the first one works well, $ gs -dBATCH -dNOP...
I have a directory *foo* containing .pdf files named with pattern *X01, X02, ...*, each two pages long. I want to combine them to a new .pdf, named "_all_YY-MM-DDTHHMMSS.pdf_" that will contain the file names as bookmarks.
I used these two commands. While the first one works well,
$ gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -dAutoRotatePages=/None -sOutputFile=all_$(date +"%FT%H%M%S").pdf X*.pdf
the second one, based on [this answer](https://unix.stackexchange.com/a/72457/372935) fails.
$ pdftk all_2023-07-12T094706.pdf update_info {ls | grep X*} output out.pdf
grep: X}: No such file or directory
grep: output: No such file or directory
grep: out.pdf: No such file or directory
Done. Input errors, so no output created.
I was trying to
grep
the ls
for the filenames starting with _X*_, in order to exclude the new combined .pdf names _all..._.
How do I get this to work, preferably by adding update_info
to the first command?
I'm aware of solutions like [this](https://unix.stackexchange.com/a/709643/372935) , but they look rather tedious.
jay.sf
(237 rep)
Jul 12, 2023, 08:13 AM
3
votes
1
answers
7249
views
gs can't find the proper font
I am running the following command to add bookmarks to a pdf file. The file `bookmarks.txt` contains bookmarks in Chinese characters and in pdfmarks format. The output of `gs` shows that there seem to be some problem with the font. Is there some way to solve the problem? Thanks in advance! $ gs -dBA...
I am running the following command to add bookmarks to a pdf file. The file
bookmarks.txt
contains bookmarks in Chinese characters and in pdfmarks format. The output of gs
shows that there seem to be some problem with the font. Is there some way to solve the problem? Thanks in advance!
$ gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=out.pdf note.pdf bookmarks.txt
GPL Ghostscript 9.05 (2012-02-08)
Copyright (C) 2010 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 102.
Page 1
Substituting font Times-Bold for Times New Roman,Bold.
Loading NimbusRomNo9L-Medi font from /usr/share/fonts/type1/gsfonts/n021004l.pfb... 2889932 1499918 3254752 1759198 3 done.
Substituting font Times-Roman for Times New Roman.
Loading NimbusRomNo9L-Regu font from /usr/share/fonts/type1/gsfonts/n021003l.pfb... 2993796 1627069 4166144 2692107 3 done.
Page 2
Substituting font Times-Roman for Times New Roman.
Page 3
Substituting font Times-Roman for Times New Roman.
Page 4
Can't find (or can't open) font file /usr/share/ghostscript/9.05/Resource/Font/Arial-BoldMT.
Can't find (or can't open) font file Arial-BoldMT.
Can't find (or can't open) font file /usr/share/ghostscript/9.05/Resource/Font/Arial-BoldMT.
Can't find (or can't open) font file Arial-BoldMT.
Querying operating system for font files...
Loading Arial-BoldMT font from /usr/share/fonts/truetype/msttcorefonts/arialbd.ttf... 3073992 1671962 5497244 3026723 3 done.
Loading ArialMT font from /usr/share/fonts/truetype/msttcorefonts/Arial.ttf... 3074368 1692578 5853472 3515223 3 done.
Substituting font Times-Roman for Times New Roman.
Page 5
Substituting font Times-Roman for Times New Roman.
Page 6
Substituting font Times-Roman for Times New Roman.
Page 7
Page 8
Loading Arial-BoldMT font from /usr/share/fonts/truetype/msttcorefonts/arialbd.ttf... 3074180 1679830 4371296 2897061 3 done.
Substituting font Times-Roman for Times New Roman.
Page 9
Substituting font Times-Roman for Times New Roman.
Substituting font Times-Bold for Times New Roman,Bold.
Loading Arial-BoldMT font from /usr/share/fonts/truetype/msttcorefonts/arialbd.ttf... 3073992 1671819 4631712 2938526 3 done.
Loading ArialMT font from /usr/share/fonts/truetype/msttcorefonts/Arial.ttf... 3073992 1672099 4987940 3383317 3 done.
Page 10
Loading ArialMT font from /usr/share/fonts/truetype/msttcorefonts/Arial.ttf... 3094652 1711038 3749692 2384326 3 done.
The font map files of my GhostScript is under /usr/share/ghostscript/9.05/Resource/Init
, and can be viewed here
[Fontmap](https://dl.dropboxusercontent.com/u/13029929/fonts/Fontmap) and
[Fontmap.GS](https://dl.dropboxusercontent.com/u/13029929/fonts/Fontmap.GS) .
I have installed ttf-mscorefonts-installer
, and
$ ls /usr/share/fonts/truetype/msttcorefonts/
Andale_Mono.ttf Georgia.ttf
andalemo.ttf georgiaz.ttf
arialbd.ttf impact.ttf
arialbi.ttf Impact.ttf
Arial_Black.ttf timesbd.ttf
Arial_Bold_Italic.ttf timesbi.ttf
Arial_Bold.ttf timesi.ttf
Arial_Italic.ttf Times_New_Roman_Bold_Italic.ttf
ariali.ttf Times_New_Roman_Bold.ttf
arial.ttf Times_New_Roman_Italic.ttf
Arial.ttf Times_New_Roman.ttf
ariblk.ttf times.ttf
comicbd.ttf trebucbd.ttf
Comic_Sans_MS_Bold.ttf trebucbi.ttf
Comic_Sans_MS.ttf Trebuchet_MS_Bold_Italic.ttf
comic.ttf Trebuchet_MS_Bold.ttf
courbd.ttf Trebuchet_MS_Italic.ttf
courbi.ttf Trebuchet_MS.ttf
Courier_New_Bold_Italic.ttf trebucit.ttf
Courier_New_Bold.ttf trebuc.ttf
Courier_New_Italic.ttf Verdana_Bold_Italic.ttf
Courier_New.ttf Verdana_Bold.ttf
couri.ttf verdanab.ttf
cour.ttf Verdana_Italic.ttf
Georgia_Bold_Italic.ttf verdanai.ttf
Georgia_Bold.ttf verdana.ttf
georgiab.ttf Verdana.ttf
Georgia_Italic.ttf verdanaz.ttf
georgiai.ttf webdings.ttf
georgia.ttf Webdings.ttf
***********************************
updated
The error is that in [the generated pdf file](https://dl.dropboxusercontent.com/u/13029929/fonts/out.pdf) , the bookmarks are not Chinese characters but unrecognizable (if you view it in evince, click side pane and then index). I suspect the substitution is the reason (or do I misunderstand the cause of the problem?)
Here is the updated [Fontmap.GS](https://dl.dropboxusercontent.com/u/13029929/fonts/Fontmap.GS) , after adding the font files for the four types of Times New Roman fonts
Here is [the output of running the above command using gs
](https://dl.dropboxusercontent.com/u/13029929/fonts/output_gs.txt)
user66259
Apr 26, 2014, 11:21 PM
• Last activity: May 22, 2023, 05:06 PM
0
votes
2
answers
1374
views
How can you compress images in a PDF (via a GUI, not batch or CLI util)?
While there's similar questions on how to compress a PDF using a command-line tool like ghostscript, is there a GUI experience to compress a PDF file's images? Previously on macOS I used tools like PDFPen to do this.
While there's similar questions on how to compress a PDF using a command-line tool like ghostscript, is there a GUI experience to compress a PDF file's images?
Previously on macOS I used tools like PDFPen to do this.
Vivek Gani
(233 rep)
Jan 20, 2023, 08:56 PM
• Last activity: Jan 21, 2023, 02:01 AM
2
votes
0
answers
605
views
How do I rotate the orientation in the ghostscript plot for ps file?
I am plotting the (postscript) ps file using the ghostscript in the terminal. When I use the command"gs file.ps", it always gives the portrait orientation like following [![enter image description here][1]][1] do you know how could I rotate the plot with 90 degrees with landscape orientation? thanks...
I am plotting the (postscript) ps file using the ghostscript in the terminal.
When I use the command"gs file.ps", it always gives the portrait orientation like following
do you know how could I rotate the plot with 90 degrees with landscape orientation? thanks a lot.

徐世博
(21 rep)
Mar 20, 2019, 05:40 PM
• Last activity: Sep 21, 2022, 10:53 AM
0
votes
0
answers
945
views
Using gs (Ghostscript) to extract fonts from PDF
I;m tried to use Ghostscript to extract fonts from PDF file. GPL Ghostscript 9.53.3 (2020-10-01) I downloaded extractFonts.ps tool and put it in same folder with PDF file. I also set permissions for extractFonts.ps: 'Allow this file to run as program'. Tried to extract, but got error: ~/Downloads/He...
I;m tried to use Ghostscript to extract fonts from PDF file. GPL Ghostscript 9.53.3 (2020-10-01) I downloaded extractFonts.ps tool and put it in same folder with PDF file. I also set permissions for extractFonts.ps: 'Allow this file to run as program'. Tried to extract, but got error:
~/Downloads/Helvetica/test$ gs \
-q -dNODISPLAY \
/home/labocomp/Downloads/Helvetica/test/extractFonts.ps \
-c "(/home/labocomp/Downloads/Helvetica/test/10.pdf) extractFonts quit"
Error: /invalidfileaccess in --file--
Operand stack:
(/home/labocomp/Downloads/Helvetica/test/10.pdf) (r)
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval--
Dictionary stack:
--dict:730/1123(ro)(G)-- --dict:0/20(G)-- --dict:78/200(L)--
Current allocation mode is local
Last OS error: Permission denied
GPL Ghostscript 9.53.3: Unrecoverable error, exit code 1
Tried also command:
gs -q -dNODISPLAY extractFonts.ps -c "(10.pdf) extractFonts quit
>
>
doesn't extract anything.
Where is a problem?
Lexx Luxx
(1463 rep)
Jul 29, 2022, 12:18 PM
• Last activity: Jul 29, 2022, 02:56 PM
25
votes
7
answers
52385
views
How to convert a color pdf to black-white?
I'd like to transform a pdf with some coloured text and images in another pdf with only black&white, in order to reduce its dimensions. Moreover, I would like to keep the text as text, without transforming the pages elements in pictures. I tried the following command: convert -density 150 -threshold...
I'd like to transform a pdf with some coloured text and images in another pdf with only black&white, in order to reduce its dimensions. Moreover, I would like to keep the text as text, without transforming the pages elements in pictures.
I tried the following command:
convert -density 150 -threshold 50% input.pdf output.pdf
found in another question, [a link](https://unix.stackexchange.com/questions/84709/how-can-i-convert-a-pdf-file-from-gray-scale-to-black-white) , but it does what I don't want: the text in the output is transformed in a poor image and is no longer selectable.
I tried with Ghostscript:
gs -sOutputFile=output.pdf \
-q -dNOPAUSE -dBATCH -dSAFER \
-sDEVICE=pdfwrite \
-dCompatibilityLevel=1.3 \
-dPDFSETTINGS=/screen \
-dEmbedAllFonts=true \
-dSubsetFonts=true \
-sColorConversionStrategy=/Mono \
-sColorConversionStrategyForImages=/Mono \
-sProcessColorModel=/DeviceGray \
$1
but it gives me the following error message:
./script.sh: 19: ./script.sh: output.pdf: not found
Is there any other way to create the file?
BowPark
(5155 rep)
Oct 7, 2013, 04:46 PM
• Last activity: Jul 25, 2022, 01:06 PM
14
votes
5
answers
7947
views
Extract even-numbered and odd-numbered pages of a PDF into two separate PDFs
I have a PDF that consists of several hundred pages of bilingual text. Since I need to use OCR on each language separately, I want to grab the even and odd pages and make two separate PDFs, using `convert` or `ghostscript`. The language I want to do first is on the odd-numbered pages. What `convert`...
I have a PDF that consists of several hundred pages of bilingual text. Since I need to use OCR on each language separately, I want to grab the even and odd pages and make two separate PDFs, using
convert
or ghostscript
. The language I want to do first is on the odd-numbered pages. What convert
or ghostscript
command can I use to grab these and write them to a new file?
ixtmixilix
(13520 rep)
Jun 26, 2011, 01:47 PM
• Last activity: May 8, 2022, 04:33 AM
0
votes
1
answers
187
views
Trouble installing GS from source
I'm trying to install Ghostscript 9.23 from source, and getting some errors I'm not familiar with. I'm using CentOS. $ cat /proc/version Linux version 2.6.9-67.ELsmp (brewbuilder@ls20-bc1-14.build.redhat.com) (gcc version 3.4.6 20060404 (Red Hat 3.4.6-8)) #1 SMP Wed Nov 7 13:58:04 EST 2007 After `./...
I'm trying to install Ghostscript 9.23 from source, and getting some errors I'm not familiar with. I'm using CentOS.
$ cat /proc/version
Linux version 2.6.9-67.ELsmp (brewbuilder@ls20-bc1-14.build.redhat.com) (gcc version 3.4.6 20060404 (Red Hat 3.4.6-8)) #1 SMP Wed Nov 7 13:58:04 EST 2007
After
./configure
I run make
and get the following errors...
./lcms2art/include/lcms2art.h:146:10: warning: "ULLONG_MAX" is not defined
./lcms2art/include/lcms2art.h:153:10: warning: "LLONG_MAX" is not defined
./lcms2art/src/cmsplugin.c: In function `_cmsReadFloat32Number':
./lcms2art/src/cmsplugin.c:195: warning: implicit declaration of function `fpclassify'
./lcms2art/src/cmsplugin.c:195: error: `FP_ZERO' undeclared (first use in this function)
./lcms2art/src/cmsplugin.c:195: error: (Each undeclared identifier is reported only once
./lcms2art/src/cmsplugin.c:195: error: for each function it appears in.)
./lcms2art/src/cmsplugin.c:195: error: `FP_NORMAL' undeclared (first use in this function)
make: *** [obj/cmsplugin.o] Error 1
What does that mean? How do I fix it?
I wrestled a bear once.
(189 rep)
Aug 9, 2018, 07:16 PM
• Last activity: May 5, 2022, 06:09 AM
0
votes
0
answers
64
views
Script portability to MacOS
Context === Catalina (zsh) & Homebrew: man pages return successfully for `pdftk` & `ps2pdf` The goal is to execute: [pdfBatesStamp.sh][1] as described in [https://unix.stackexchange.com/a/115537/182280][2] I changed the first line of the script to: `#!/bin/zsh -` Observations === Preliminary test re...
Context
===
Catalina (zsh) & Homebrew: man pages return successfully for
The error:
UPDATE: said error is remedied by placing a # at the start of the line.
Line 132:
Questions
===
1. What exactly is causing said errors?
2. What is the remedy?
3. Is there any reason that this script will NEVER run in said context?
For jsbillings
===
user@JUPITER pdfBatesStamp % ./pdfBatesStamp.sh Exhibits_ActivityReport.pdf
./pdfBatesStamp.sh:59: command not found: ^M
./pdfBatesStamp.sh:132: parse error near `elif'
user@JUPITER pdfBatesStamp %
user@JUPITER pdfBatesStamp % sh pdfBatesStamp.sh Exhibits_ActivityReport.pdf
pdfBatesStamp.sh: line 132: syntax error near unexpected token `elif'
'dfBatesStamp.sh: line 132: `elif [ $# -eq 2 ]; then
Ubuntu 16.04 Test results:
user@azimuth:~/Desktop/BatesStamp$ cp pdfBatesStamp.sh test.sh
user@azimuth:~/Desktop/BatesStamp$ dos2unix test.sh
dos2unix: converting file test.sh to Unix format ...
user@azimuth:~/Desktop/BatesStamp$ ls
Exhibits_ActivityReport.pdf pdfBatesStamp.sh test.sh
user@azimuth:~/Desktop/BatesStamp$ ls -l
total 11384
-rw------- 1 user user 11589045 Nov 23 18:00 Exhibits_ActivityReport.pdf
-rwxrwxr-x 1 user user 32764 Nov 23 22:24 pdfBatesStamp.sh
-rwxrwxr-x 1 user user 32764 Nov 23 22:26 test.sh
user@azimuth:~/Desktop/BatesStamp$ ./test.sh Exhibits_ActivityReport.pdf
Input File = "/home/user/Desktop/BatesStamp/Exhibits_ActivityReport.pdf" (origSize=11,589,045)
(standard_in) 1: syntax error
(standard_in) 1: illegal character: M
(standard_in) 1: syntax error
(standard_in) 1: syntax error
(standard_in) 1: syntax error
./test.sh: line 384: [: too many arguments
*** Can't find page size
user@azimuth:~/Desktop/BatesStamp$ mac2unix test.sh
mac2unix: converting file test.sh to Unix format ...
user@azimuth:~/Desktop/BatesStamp$ ./test.sh Exhibits_ActivityReport.pdf
Input File = "/home/user/Desktop/BatesStamp/Exhibits_ActivityReport.pdf" (origSize=11,589,045)
(standard_in) 1: syntax error
(standard_in) 1: illegal character: M
(standard_in) 1: syntax error
(standard_in) 1: syntax error
(standard_in) 1: syntax error
./test.sh: line 384: [: too many arguments
*** Can't find page size
pdftk
& ps2pdf
The goal is to execute: pdfBatesStamp.sh as described in https://unix.stackexchange.com/a/115537/182280
I changed the first line of the script to: #!/bin/zsh -
Observations
===
Preliminary test returned:

: command not foundine XX:
are lines with no commands / comments. Screenshot shows lines 104,105,109,111 are null:


gatorback
(1522 rep)
Nov 24, 2021, 02:08 AM
• Last activity: Nov 24, 2021, 03:30 AM
1
votes
1
answers
2089
views
Cannot open X display `(null)'. **** Unable to open the initial device, quitting
input: gs myPSFile.ps output: GPL Ghostscript 9.50 (2019-10-15) Copyright (C) 2019 Artifex Software, Inc. All rights reserved. This software is supplied under the GNU AGPLv3 and comes with NO WARRANTY: see the file COPYING for details. GPL Ghostscript 9.50: Cannot open X display `(null)'. **** Unabl...
input:
gs myPSFile.ps
output:
GPL Ghostscript 9.50 (2019-10-15)
Copyright (C) 2019 Artifex Software, Inc. All rights reserved.
This software is supplied under the GNU AGPLv3 and comes with NO WARRANTY:
see the file COPYING for details.
GPL Ghostscript 9.50: Cannot open X display `(null)'.
**** Unable to open the initial device, quitting.
why?
I have windows 10.
I'm using git bash to ssh into my school's internal tux server.
What I tried:
I saw 3 or 4 other duplicate questions on many other sites. I have no idea what is going on.
solidwaterslayer
(11 rep)
Sep 21, 2021, 06:15 PM
• Last activity: Sep 21, 2021, 06:33 PM
1
votes
1
answers
2096
views
How to scale down PDF file (in pixels and in cm)?
I need to automatically convert my pupils' solutions which are photos and scans of various orientations, resolution, quality and file format into a single PDF with fitting dimensions. The dimensions in cm should be approximately A4 such that Xournal++, which I use for annotating the PDFs, uses a sui...
I need to automatically convert my pupils' solutions which are photos and scans of various orientations, resolution, quality and file format into a single PDF with fitting dimensions.
The dimensions in cm should be approximately A4 such that Xournal++, which I use for annotating the PDFs, uses a suiting pen thickness, see https://github.com/xournalpp/xournalpp/issues/2424
The dimensions in pixels should be such that the content is not blurry on one hand but Xournal++ is not hanging because of too large file size on the other hand.
Currently, I scale down PDF files with ps2pdf if they are larger than 5MB and individual image files (which later are merged into a PDF) if they are larger than 1,5MB. Also I set the size in cm to A4 (see link above).
However, some of the files are still too large in terms of pixels, though the file size and the dimensions in cm are fine, so Xournal++ hangs a lot on them.
I tried to set the DPI to 120 (155 would be A4 width on 1280px) but still get pages with 3000x4000 px. Here is my complete script: https://pastebin.com/jHxhUJvN
What did I mess up? Thanks for any input!
Photon
(119 rep)
Feb 28, 2021, 11:25 AM
• Last activity: Feb 28, 2021, 07:03 PM
0
votes
1
answers
1743
views
methods of PDF compression
# The Problem I have a lot of old books that I want to scan and digitize. For this, I use some flatbed scanner, `xsane` and `GImageReader`, which works great. Back a few years ago, when I was still using Windows for such things, I used `ABBY Fine Reader`, which I was also very happy with, but which...
# The Problem
I have a lot of old books that I want to scan and digitize. For this, I use some flatbed scanner,
xsane
and GImageReader
, which works great.
Back a few years ago, when I was still using Windows for such things, I used ABBY Fine Reader
, which I was also very happy with, but which is not available on Linux.
Now, comparing the PDFs I create now and the ones I created back in the day, I see that the files are much larger today.
With ABBY, I used to get PDFs with 50-60 pages with file sizes between 10-50 MB, which I find acceptable.
Nowaydays, I have PDFs with 50-60 pages with file sizes of 150+ MB, which is not very usable when reading them on a smartphone for example.
I use the same settings for scanning, namely:
- A4 pages
- jpg
compression
- 300 dpi
- color scans for the covers
- greyscale scans for all interior pages
I assume that the size difference is related to ABBY using some commercial magic to be smart about image compression, which GImageReader doesn't have. Perhaps they identify non-empty areas (illustrations and text blocks) and save them at a higher quality, while aggressively compressing the "background image" or something like that - or maybe they are simply able to identify that some pages are greyscale while others are colored, a distinction which might be lost on GImageReader
. I don't know, really, and I'd love to understand it.
# What I have tried
Since then, I have played a bit with various methods of PDF compression. Most online guides suggest using gs
or pdftk
, both of which I have tried. In my specific case, I observe the following:
- Option 1: gs
for pdf->pdf
. The /printer
and /prepress
settings do not reduce the file size at all, the /screen
and /ebook
settings lead to notable degradation of image quality.
- Option 2: gs
for pdf->ps
and then ps->pdf
. This leads to a notable reduction in filesize (I don't understand why this is any different from Option 1 but whatever) and I was happy with that option, until I noticed that apparently the glyphs of the text get lost in translation. When I copy&paste text segments from the PDF, the result is some wingdings-type gibberish, where I was able to copy&paste text from the original PDF, so this is a no-no.
- Option 3: pdftk
for pdf->pdf
. This does not seem to reduce the filesize at all.
# What to do now
I'm a bit lost as to how it is possible that the PDF compression techniques yield such vastly different results. I am looking for a tool that runs under linux (preferably FOSS, but I'd settle for an affordable commercial product as well) and provides significant PDF compression of scanned & OCRd PDFs without notable loss of quality against a 300dpi A4 JPG.
carsten
(375 rep)
Jan 3, 2021, 10:05 AM
• Last activity: Jan 3, 2021, 04:21 PM
Showing page 1 of 20 total questions