Convert dvi-file to a4-sized pdf-file
Convert a TeX DVI-file to a4-sized pdf-file using ghostscript and dvips
dvipdf -sPAPERSIZE=a4 file.dvi file.pdf
Convert dvi-file to a4-sized ps-file
Convert a TeX DVI-file to a4-sized postscrip-file
dvips -t a4 file.dvi file.ps
Convert ps-file to a4-sized pdf-file
Convert a ps-file to a4-sized pdf-file using ps2pdf
ps2pdf -sPAPERSIZE=a4 file.ps file.pdf
Convert ps-file to eps-file
Convert a ps-file to epsi-file using ps2epsi
ps2epsi file.ps file.epsi
Remove bitmap preview
Remove bitmap preview image using perl
perl -ne 'print unless /^%%BeginPreview/../^%%EndPreview/' < file.epsi > file.eps
Convert eps file to pdf file
Convert a eps-file to pdf-file while and embedding the all the fonts (requires epstopdf v2.9.9 or later)
epstopdf --embed file.eps
Convert pdf files to pdf files
Convert all pdf files in the folder to eps files.
Save the the following shell script to, e.g., pdftoeps.sh and change the permissions as
chmod +x pdftoeps.sh
#!/bin/bash
for f in *.pdf
do
TARGET=${f%.pdf}.eps
echo "pdftops -eps ${1} - | ps2eps > ${TARGET}"
pdftops -eps ${f} - | ps2eps > ${TARGET}
echo "ps2eps stdout redirected to: ${TARGET}"
done
Embed fonts in a PDF using pdf2ps and ps2pdf (for IEEE PDF eXpress)
Convert pdf file into a postscript file with pdf2ps, and then turn it back into a pdf while embedding the fonts
pdf2ps file.pdf - | ps2pdf -dPDFSETTINGS=/prepress - file_embedded.pdf
Embed fonts in a PDF using ghostscript
gs -dSAFER -dNOPLATFONTS -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sPAPERSIZE=letter -dCompatibilityLevel=1.4 -dPDFSETTINGS=/printer -dCompatibilityLevel=1.4 -dMaxSubsetPct=100 -dSubsetFonts=true -dEmbedAllFonts=true -sOutputFile=file_embedded.pdf -f file.pdf
Extracting pages from the pdf-file
Extract pages from the PDF file using Ghostscript by specifying the first page (m) and the last page (n) that you want in the output file:
gs -sDEVICE=pdfwrite -dNOPAUSE -dQUIET -dBATCH -dFirstPage=m -dLastPage=n -sOutputFile=output.pdf input.pdf
Extract pages from the PDF file by using pdftk:
pdftk input.pdf cat m-n output output.pdf
Merging pdf-files
Merge file1.pdf and file2.pdf to form file12.pdf using ghostscript
gs -sDEVICE=pdfwrite -dNOPAUSE -dQUIET -dBATCH -sOutputFile=file12.pdf file1.pdf file2.pdf
Merge file1.pdf and file2.pdf using pdfjoin
pdfjoin file1.pdf file1.pdf
Replacing spaces in filenames
For filenames containing spaces, rename files replacing spaces with underscores:
for file in *[[:blank:]]*
do
mv "$file" ${file// /_}
done
Reducing the margin of the pdf files
Increase the page content of the A4-sized pdf-file by 10 percent. Here, the size of the DIN A4 page is 595×842 pps and the page is shifted 5 percent of it (−29.75, −42.1) in order to center the scaled page.
gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dSAFER -dCompatibilityLevel="1.3" -dPDFSETTINGS="/printer" -sPAPERSIZE=a4 -sOutputFile="out.pdf" -c "<</BeginPage{1.1 1.1 scale -29.75 -42.1 translate}>> setpagedevice" -f in.pdf
Fitting the pdf file with custom page size to A4 paper size
gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dSAFER -dCompatibilityLevel="1.3" -dPDFSETTINGS="/printer" -sPAPERSIZE=a4 -dPDFFitPage -sOutputFile="out.pdf" -f in.pdf
Converting the booklet with multiple pages into single pages
First get the page size of the original pdf file
pdfinfo -f 1 -l 1000 -box Example.pdf
This will give you the page size in point as follows:
Page 1 size: 595 x 842 pts (A4)
Now each page can be splitted into 421×595-point pages using the pdfwrite steps given below (the sizes has to multiplied by ten to obey the pdfwrite’s resolution of 720 dpi)
gs -o out%03d_A.pdf -sDEVICE=pdfwrite -g4210x5950 -sPAPERSIZE=a4 -dPDFFitPage -c "<</PageOffset [0 0]>> setpagedevice" -f Example.pdf
gs -o out%03d_B.pdf -sDEVICE=pdfwrite -g4210x5950 -sPAPERSIZE=a4 -dPDFFitPage -c "<</PageOffset [-421 0]>> setpagedevice" -f Example.pdf
Finally the resulting single-page pdf files has to be combined, e.g., using the pdftk as follows
pdftk out*_?.pdf cat output combined.pdf
pdftk can be installed in KDE using
pkcon install pdftk
Batch processing of matlab figures using inkscape from matlab
Inscape can be called from matlab, e.g., for converting svg figures to pdf format as follows:
name = 'Example'; ext = 'svg';
system([inkscape ' [name '.' ext] ' --export-pdf ' [name '.pdf 2>/dev/null']])
Here error messages are directed to /dev/null.
Under matlab on windows, the system call has to be modified to following
name = 'Example'; ext = 'svg';
system(['(inkscape.exe ' [name '.' ext] ' --export-pdf ' [name '.pdf) 2>nul']]);
In order to use inkscape from matlab on windows, inkscape has to added to seach path. This can be achieved from control panel, e.g., by searching for “Edit environment variables for your account” and then adding inkscape folder to your path.