Which version of cpdf has the option -print-dict-entry? - pdf

cpdf manual (version 2.5, I can not find version 2.4 manual) says there is an option -print-dict-entry.
cpdf -print-dict-entry <key> in.pdf
But I don't find it in the command line.
$ cpdf -help 2>&1 | grep dict-entry
-remove-dict-entry Remove an entry from all dictionaries
$ cpdf -version
cpdf Version 2.4 (21st June 2021)
$ brew info cpdf
==> oncletom/cpdf/cpdf: stable 2.4
Coherent PDF Command-line Tools to modify PDF files
https://www.coherentpdf.com/
/usr/local/Cellar/cpdf/2.4 (3 files, 4.4MB) *
Built from source on 2022-09-07 at 08:52:47
From: https://github.com/oncletom/homebrew-cpdf/blob/HEAD/Formula/cpdf.rb
Is this option newly introduced in version 2.5? Therefore, it is not available in version 2.4?

https://github.com/coherentgraphics/cpdf-binaries/blob/master/OSX-Intel/cpdf
I find this latest version of cpdf that can be installed easily for mac which has the option.

Related

ImageMagick: How do I convert pdf to jpg? I get ERROR: no decode delegate for this image format

Problem
I need to convert a multipage pdf to jpg-files but ImageMagick keeps throwing errors that are hard to interpret.
Installing ImageMagick
At first I installed it using apt-get, but as I could read that several people had problems doing that, i ended up installing it from source.
My linux distribution (A Docker image):
>lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 10 (buster)
Release: 10
Codename: buster
Installing ImageMagick from source:
# Installing build tools and ghostscript
apt update
apt-get install -y build-essential make ghostscript
# Downloading imagemagick
wget https://www.imagemagick.org/download/ImageMagick.tar.gz
# Installing and cleaning up
tar xvzf ImageMagick.tar.gz && cd ImageMagick-7* && ./configure && make && make install && ldconfig /usr/local/lib && cd .. && rm -r ImageMagick-7*
# Checking ImageMagick version
>magick -version
Version: ImageMagick 7.0.10-60 Q16 x86_64 2021-01-25 https://imagemagick.org
Copyright: (C) 1999-2021 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC HDRI OpenMP(4.5)
Delegates (built-in): jpeg x xml zlib
Converting files
# Image to image
>convert test.jpg test.png
# PDF to image
>convert test.pdf test.jpg
convert: no decode delegate for this image format `' # error/constitute.c/ReadImage/572.
convert: no images defined `test.jpg' # error/convert.c/ConvertImageCommand/3304.
Is Ghostscript the problem?
The Ghostscript installation is a common problem for many, but Ghostscript seems to work fine and produce a jpg-file
# PDF to image with Ghostscript
gs -sDEVICE=pngalpha -sOutputFile=test.jpg test.pdf
Do I have to install more Delegates?
The error suggests that there is something off with my limited delegates, so I thought to install all dependencies up front.
# Listing dependencies
>apt update && apt build-dep imagemagick
Reading package lists... Done
E: You must put some 'source' URIs in your sources.list
This is where I got stuck.
Solution
It turned you that it was indeed the delegates that were missing. I haven't seen this well described in the documentation or anywhere else.
NOTE: Delegates should be installed before you install ImageMagick
Here is how I fixed it:
# Add source URI or uncomment source URI
## Adding URI
echo "deb-src http://deb.debian.org/debian buster main" >> /etc/apt/sources.list
apt update
## Uncommenting URI
sudo sed -Ei 's/^# deb-src /deb-src /' /etc/apt/sources.list
sudo apt update
# Installing dependencies
apt-get build-dep imagemagick
Now I can convert pdf to jpg!
My solution was to reinstall imagemagick, but following the steps in the answer of andrew.46 at https://askubuntu.com/questions/745660/imagemagick-png-delegate-install-problems/746195#746195

pandoc: xelatex not found. xelatex is needed for pdf output

I have just upgraded my Macbook Pro OS to El Capitan (v10.11.4).
My attempt to export a Markdown file (created using Sublime Text 2, v2.0.2, build 2221) to pdf using pandoc is now failing, and I receive the following error:
pandoc: xelatex not found. xelatex is needed for pdf output
My output command is as follows:
pandoc doc1.md -o doc1.pdf --toc -V geometry:margin=1in --variable fontsize=10pt --variable fontfamily=utopia --variable linkcolor=blue --latex-engine=xelatex -f markdown-implicit_figures -s
Above command worked like a charm prior to installing El Capitan.
FYI - in searching for questions here I have not found one that gives a suitable answer.
For my case, add one line into ~/.bashrc solved the error:
export PATH=/Library/TeX/texbin:$PATH
Of course, the environment variable should be activated in the current term:
$ . ~/.bashrc
then run: $ make
the error disappears.
El Capitan's security features disable and remove the old symlink /usr/texbin. If you have MacTeX 2015, they should've been installed in /Library/TeX/texbin as well. You'll have to update the PATH your using to launch pandoc to include that folder. If you have a pre-2015 distribution of MacTeX, there are instructions here.
Linux Ubuntu instructions:
Tested on Ubuntu 18.04:
If you see this error on Linux Ubuntu:
pandoc: xelatex not found. xelatex is needed for pdf output
Then you need to install the texlive-xetex package like this:
sudo apt update
sudo apt install texlive-xetex
That solves it! Source where I learned this: TEX: XeLatex under Ubuntu.
In my particular case, I was trying to run this make_book.sh script to generate book.pdf, so I needed to do all of the following:
sudo apt update
sudo apt install pandoc
pip3 install MarkdownPP
sudo apt install texlive-xetex
cd path/to/repo
cd systemd-by-example
./make_book.sh
# You'll now have "book.pdf" inside directory "systemd-by-example"!
References:
https://github.com/jreese/markdown-pp - instructions to install MarkdownPP
https://tex.stackexchange.com/a/179811/168682 - instructions to install texlive-xetex

Installing GDAL with ECW support

Most (all?) information online is outdated since ECW (Hexagon Geospatial/Intergraph) has recently released new versions with breaking changes (5.0, 5.1 and 5.2).
Most instructions result in errors like:
checking for libNCSEcw.so or libecwj2... configure: error: not found in /usr/local/lib or /usr/local/bin
This works for GDAL 1.11.2, but it should work back to 1.10.0.
Download the latest version of the ECW library from here (currently 5.5):
https://download.hexagongeospatial.com
Instructions for v5.2.1, but should be similar for the latest version:
$ unzip erdas-ecwjp2sdk-v5.2.1-linux.zip
$ chmod +x ERDAS_ECWJP2_SDK-5.2.1.bin
$ ./ERDAS_ECWJP2_SDK-5.2.1.bin
Choose Desktop Read-Only and accept the license. A directory named hexagon is extracted. Copy that to /usr/local.
$ sudo cp -r hexagon/ERDAS-ECW_JPEG_2000_SDK-5.2.1/Desktop_Read-Only /usr/local/hexagon
Link the .so library for the correct architecture:
$ sudo ln -s /usr/local/hexagon/lib/(x64|x86)/release/libNCSEcw.so /usr/local/lib/libNCSEcw.so
Then configure GDAL with this command:
$ ./configure --with-ecw=/usr/local/hexagon
Before I could see ECW support in gdalinfo --formats | grep -i ecw
I also had to run sudo ldconfig.
That was in Ubuntu 14.04 Linux.

When converting PDFs to JPEGs, how do I prevent characters with french accents from disappearing?

When I use Ghostscript to convert a PDF containing french characters to a JPEG, some of characters with accents disappear in the output JPEG. What seems to be causing this problem? How can I fix it?
I’m attaching before and after screenshots to illustrate this, the debug logs, and a link to input file, and the specific command I ran.
Command:
gs -sDEVICE=jpeg -dDEBUG -dNOPAUSE -dFirstPage=1 -dLastPage=1 \
-sOutputFile=./out-1.jpg -dJPEGQ=100 -r300 corde_a_linge.pdf -c quit
before/after screenshots:
https://www.dropbox.com/sh/mtia9a993cwwvan/AAADVHe3WQv9ArZTTDMRJRGaa?dl=0
Input PDF:
http://pouremporter.communagir.org/medias/2014/09/corde_a_linge.pdf
Debug logs:
https://gist.github.com/dmlicht/c1a6a9eb02c2d6384b94
Version: GPL Ghostscript 9.15 (2014-09-22)
OS: OSX Yosemite Version 10.10.1
Please let me know if theres any more information I can provide.
I did run the exact same command as in your question, albeit on a Mavericks system.
The left result is from Ghostscript 9.10 (as distributed via the MacPorts folks).
The right result is via a "self-compiled from current Git sources" Ghostscript 9.16 GIT PRERELEASE:
(Right-click images to 'open in new tab' and you may see images in original size.)
So clearly, somewhere on the way between 9.10 (or 9.15 if we take into account your result) and current Git source code there must have happened some sort of fix to this problem.
I cannot debug further right now. Maybe KenS can contribute more thoughts once he's back from travelling.
Update:
Here is some more info.
FreeType used by MacPorts installation
kp#mbp:> otool -L /opt/local/bin/gs
/opt/local/bin/gs:
/opt/local/lib/libgs.9.10.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)
kp#mbp:> otool -L /opt/local/lib/libgs.9.10.dylib | grep -i freetype
/opt/local/lib/libfreetype.6.dylib (compatibility version 18.0.0, current version 18.1.0)
FreeType used by "self-compiled-from-Git" installation
kp#mbp:> otool -L /usr/local/bin/gs | grep -i freetype
/opt/X11/lib/libfreetype.6.dylib (compatibility version 18.0.0, current version 18.2.0)
kp#mbp:> ls -l /opt/X11/lib/libfreetype.6.dylib /opt/local/lib/libfreetype.6.dylib
-rwxr-xr-x 1 root wheel 1143056 12 Aug 2014 /opt/X11/lib/libfreetype.6.dylib
-rwxr-xr-x 1 root admin 1099796 6 Jan 13:28 /opt/local/lib/libfreetype.6.dylib
So indeed, the suspicion about FreeType being the cause has some justification!

RVM: "sha256sum nor shasum found"

I've just installed RVM on a new machine and when switching into a directory containing a .rvmrc file (which I've accepted) I'm getting:
ERROR: Neither sha256sum nor shasum found in the PATH
I'm on OS X 10.5.8. — Probably missing something somewhere. Any ideas what's going on and how to fix this?
My OpenSSL happened to not have a sha256 enc function for some reason:
$ openssl sha256
openssl:Error: 'sha256' is an invalid command.
After some googling, I found that there is an equivalent called gsha256sum that comes with the homebrew recipe "coreutils". After installing that (brew install coreutils), I had a gsha256sum binary in /usr/local/bin, so it was just a matter of symlinking it:
$ sudo ln -s /usr/local/bin/gsha256sum /usr/local/bin/sha256sum
That fixed it for me.
ciastek's answer worked for me until I tried to run rvm within a $() in a bash script - rvm couldn't see the sha256sum function. So I created a file called sha256sum with the following contents:
openssl sha256 "$#" | awk '{print $2}'
put it in ~/bin, made it executable, and added that folder to my path (and removed the function from my .bashrc).
(Many thanks to my coworker Rob for helping me find that fix.)
Means you're missing the binary in /usr/bin or your path is somehow missing /usr/bin. Open a new shell and run echo $PATH | grep '/usr/bin' and see if its returned. Also, ls -alh /usr/bin/shasum and make sure the binary is there and executable. There is no sha256sum on OS X, just shasum.
On MacOS Sierra run
$ shasum -a 256 filename
Based on #vikas027 comment just add
alias sha256sum='shasum -a 256' to your ~/.zshrc
In my opinion Leopard just doesn't have /usr/bin/shasum.
Take a look at shasum manpage - this manpage is only for Snow Leopard. Other manpages, like ls manpage (can't link to it, not enough reputation), are for previous versions of MacOS X.
Workaround: Use OpenSSL to calculate sha256 checksums.
Leopards' OpenSSL (0.9.7) doesn't handle sha256. Upgrade OpenSSL. I've used MacPorts (can't link to it, not enough reputation). OpenSSL's dependecy zlib 1.2.5 required to upgrade XCode to 3.1. Can I get Xcode for Leopard still? is helpful.
Alias sha256sum to OpenSSL and correct the way it formats an output. I've put in my .bash_profile:
function sha256sum() { openssl sha256 "$#" | awk '{print $2}'; }
I'm on a relatively fresh install of Lion (OS X 10.7.4). In my /usr/bin/ folder I had these files:
-rw-rw-rw- 35 root wheel 807B /usr/bin/shasum
-rwxr-xr-x 1 root wheel 7.5K /usr/bin/shasum5.10
-rwxr-xr-x 1 root wheel 7.5K /usr/bin/shasum5.12
I had a shasum, it just wasn't marked as executable. A quick sudo chmod a+x /usr/bin/shasum solved the issue for me.
For mac os X 10.9.5 and you profile get /usr/bin path
date +%s | shasum | base64 | head -c 32 ; echo
And if you found yourself here in 2022 wondering what works on the latest Mac (Mac OS Big Sur). Do following.
sudo brew install coreutils
sudo ln -s /usr/bin/shasum<Version_for_your_installation> /usr/local/bin/sha256sum