小工具集
XiaO / 2022-06-12
Flatten PDF
将 PDF 文件的多层信息压缩至一层,即所谓 Flatten
。
brew install qpdf
Automator 中设置快捷动作如下:
export PATH=/usr/local/bin:$PATH
for f in "$@"
do
file_path=${f%/*}
file=$(basename $f)
file_name=${file%.*}
qpdf --flatten-annotations=all $f $file_path/${file_name}_flattened.pdf
done
某些文件需以不可复制的方式呈现。通过如下方式生成的 PDF 文件,文件中的文字如同图片中的文字一般,不再具备拷贝复制性质,但所生成文件的体积也相对更大。
brew install ghostscript
Automator 中设置快捷动作如下
#!/bin/zsh
export PATH=/usr/local/bin:$PATH
for f in "$@"
do
file_path=${f%/*}
file=$(basename $f)
file_name=${file%.*}
pdf2ps $f - | ps2pdf - $file_path/${file_name}_Uncopied.pdf
done
中文字体转换
中文简繁转换开源项目,支持词汇级别的转换、异体字转换和地区习惯用词转换(中国大陆、台湾、香港、日本新字体)。不提供普通话与粤语的转换。
brew install opencc
使用 Alfred 的工作流 插件,则可进一步简化操作。
Inkscape SVG2PDF
Mac 上的字体包括存储在不同位置的用户字体或系统字体,而 inkscape 所能取用的字体只有用户字体。
~/Library/Fonts/SomeFont.ttc #用户字体文件夹
Automator 快捷动作设置如下:
export PATH=/usr/local/bin:$PATH
for f in "$@"
do
inkscape --pdf-poppler --export-dpi=600 --export-type=pdf "$f"
done
当使用 Inkscape 将包含某些字体信息的 SVG 转换为 PDF 时,可能遭遇字体丢失的情况。此时,只需将相应的字体,添加到用户字体即可。
万能转换工具
brew install php
Alfred 的工作流 插件使用:
- 100 us dollars in mexican pesos
- 100 canadian dollars in argentinian peso
- 100 euros to dollars
- 100 euros in dollars
- 100 euros as dollars
- 100 euros a dolares (you can also write it in your own language)
- 100 usd to mxn
- 100 usd mxn
- 100usd yen
- 100€ to $
- 100 ¥ in €
- 100¥ €
- 100eur (if no target the currency will be converted to the base currencies that you configured)
- 2 bitcoins to dollars
- 0.1 bitcoin in dollars
- 5 bitcoins in ethereum
- 1 ethereum to ¥
- 10 ethereum in mxn
- 1eth btc
- 1btc (if no target currency is provided, the configured base currency will be used)
- 100 kilometers to meters
- 100 km in meters
- 100 km m
- 100km m
- 100 miles as meters
- 100miles in meters
- 100 miles to m
- 100 ounces to kilograms
- 100oz to kg
- 100oz = kg
- 100oz kg
- 10 years to months
- 10years to seconds
- 10 years hr
- 1 year to sec
- 1hr secods
- 1hr s
- 10 days hr
- 10 días a horas (use your own language)
- 100 gigabytes in megabytes
- 100 gigas in megas
- 100 Mebibytes in Kibibytes
- 100 gb to mb
- 100gb to kb
- 100gb mb
- 400MiB in kib
- 2tb gb
- 1b kb
- 40 as a % of 50 // 40 is 80% of 50
- 20 is what % of 50 // 20 is 40% of 50
- 15% of 50 = 7.50 // 7.5 equals to 15% of 50
- 120 + 30% = 156 // 120 plus the 30% of 120
- 120 plus 30% = 156 // 120 plus the 30% of 120
- 120 - 30% = 84 // 120 minus the 30% of 120
- 120 minus 30% = 84 // 120 minus the 30% of 120
- 30 % 40 = 75% // 30 is 75% of 40
Translations and natural language can also be used
- 120 más 30% = 156
- 120 menos 10% = 108
- 40 como % de 50 = // 40 es 80% de 50
# converts the timestamp to a regular date
- time 1577836800
# gives you the time from now plus 15 days
- time +15 days
- time now plus 3 days
# gives you the time from now plus 3 working days
- time today + 3 workdays
- time now + 3 workdays
- time + 3 workdays
# number of days until specified date
- time days until 31 december
# the start date of current year
- time start of year
# the start date of specified year
- time start of 2021
# the end date of current year
- time end of year
# the end date of specified year
- time end of 2021
# it also works in your language
- time inicio de 2020
- time fin de 2020
- time dias hasta 31 diciembre
# get information about date
- time 31 December, 2021 18:00:00
- time 31/12/2021 18:00:00
- time 12/31/2021 18:00:00
# calculate the difference between two dates
- time 25 December, 2021 - 31 December, 2021
- time 31-11-2019 - 21-11-2019
- time 11/31/2019 - 11/21/2019
PDF 压缩
brew install ghostscript
Automator 添加如下代码:
export PATH=/usr/local/bin:$PATH
for f in "$@"
do
gs -q -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dEmbedAllFonts=true -dSubsetFonts=true -dColorImageDownsampleType=/Bicubic -dColorImageResolution=144 -dGrayImageDownsampleType=/Bicubic -dGrayImageResolution=144 -dMonoImageDownsampleType=/Bicubic -dMonoImageResolution=144 -sOutputFile=${f%.*}.mini.pdf $f;
done
# Summary of -dPDFSETTINGS:
# -dPDFSETTINGS=/screen lower quality, smaller size. (72 dpi)
# -dPDFSETTINGS=/ebook for better quality, but slightly larger pdfs. (150 dpi)
# -dPDFSETTINGS=/prepress output similar to Acrobat Distiller "Prepress Optimized" setting (300 dpi)
# -dPDFSETTINGS=/printer selects output similar to the Acrobat Distiller "Print Optimized" setting (300 dpi)
# -dPDFSETTINGS=/default selects output intended to be useful across a wide variety of uses, possibly at the expense of a larger output file
To list a pakage dependencies
# For all packages
brew deps --tree --installed
# For one package only
brew deps --tree --installed poppler
brew info poppler
Extracting PDF Raster Image (光栅图)
brew install poppler
General Commands
pdfattach PDF document embedded file creator (version 3.03)
pdfdetach PDF document embedded file extractor (version 3.03)
pdffonts PDF font analyzer (version 3.03)
pdfimages PDF image extractor (version 3.03) # https://www.mankier.com/1/pdfimages
pdfinfo PDF document information extractor (version 3.03)
pdfseparate PDF page extractor
pdfsig PDF digital signatures tool
pdftocairo PDF to PNG/JPEG/TIFF/PDF/PS/EPS/SVG using cairo # https://www.mankier.com/1/pdftocairo
pdftohtml program to convert PDF files into HTML, XML and PNG images
pdftoppm PDF to Portable Pixmap (PPM) converter (version 3.03)
pdftops PDF to PostScript converter (version 3.03)
pdftotext PDF to text converter (version 3.03)
pdfunite PDF page merger
Usage: pdfimages [options] <PDF-file> <image-root>
-f <int> : first page to convert
-l <int> : last page to convert
-png : change the default output format to PNG
-tiff : change the default output format to TIFF
-j : write JPEG images as JPEG files
-jp2 : write JPEG2000 images as JP2 files
-jbig2 : write JBIG2 images as JBIG2 files
-ccitt : write CCITT images as CCITT files
-all : equivalent to -png -tiff -j -jp2 -jbig2 -ccitt
-list : print list of images instead of saving
-opw <string> : owner password (for encrypted files)
-upw <string> : user password (for encrypted files)
-p : include page numbers in output file names
-q : don't print any messages or errors
-v : print copyright and version info
-h : print usage information
-help : print usage information
--help : print usage information
-? : print usage information
# List all PDF images
pdfimages -list in.pdf
pdfimages -all in.pdf out # 以 out 为前缀导出所有图片文件
Automator 添加如下代码:
export PATH=/usr/local/bin:$PATH
for f in "$@"
do
file_path=${f%/*}
file=$(basename $f)
file_name=${file%.*}
pdfimages -all $f $file_path/${file_name}
done