View Single Post
Old 08-15-2020, 05:11 PM   #2
orebmur
Veteran Linux user
orebmur ought to be getting tired of karma fortunes by now.orebmur ought to be getting tired of karma fortunes by now.orebmur ought to be getting tired of karma fortunes by now.orebmur ought to be getting tired of karma fortunes by now.orebmur ought to be getting tired of karma fortunes by now.orebmur ought to be getting tired of karma fortunes by now.orebmur ought to be getting tired of karma fortunes by now.orebmur ought to be getting tired of karma fortunes by now.orebmur ought to be getting tired of karma fortunes by now.orebmur ought to be getting tired of karma fortunes by now.orebmur ought to be getting tired of karma fortunes by now.
 
Posts: 150
Karma: 1000000
Join Date: Mar 2017
Location: Barcelona/Spain
Device: Boyue Likebook Note & Mimas, Hisense A5, hopefully soon a PineNote
It probably all depends on the specific properties of the PDF file in question. File size in itself is not necessarily an issue, but rendering unnecessarily big image files might be one.

Opening a 203 MB sized PDF file with more than 12.000 pages but no graphics at all works like a charm here.

Maybe it helps to recompress the PDF in question.

If you happen to use Linux and have ghostscript installed, this script might help a bit:

Code:
# cat /usr/local/bin/pdfresize
#!/bin/bash

PDFINPUT="${1}"

if [ "${PDFINPUT}" != "" ] && [ -f "${PDFINPUT}" ]
then
    PDFOUTPUT=$(basename "${PDFINPUT}" .pdf)_resized.pdf
    if [ ! -f "${PDFOUTPUT}" ]
    then
        echo "Input size is:"
        /usr/bin/du -b "${PDFINPUT}" 
        echo "Reconverting input file with GhostScript..."
        /usr/bin/gs -o "${PDFOUTPUT}" \
            -sDEVICE=pdfwrite \
            -dCompatibilityLevel=1.4 \
            -dSAFER -dNOPAUSE \
            -sPAPERSIZE="" -dBATCH \
            -dPDFSETTINGS=/prepress \
            "${PDFINPUT}" &> /dev/null
    else
        echo "${PDFOUTPUT} already exists"
    fi
    if [ -f "${PDFOUTPUT}" ]
    then
        if [ "$(/usr/bin/du -b "${PDFOUTPUT}" | awk '{print $1}')" -lt "$(/usr/bin/du -b "${PDFINPUT}" | awk '{print $1}')" ]
        then
            /bin/mv "${PDFOUTPUT}" "${PDFINPUT}"
            /usr/bin/du -b "${PDFINPUT}"
        else
            echo "Recompressed pdf is equal or larger than input file:"
            /usr/bin/du -b "${PDFINPUT}" "${PDFOUTPUT}"
            echo "Removing pointless output file..."
            rm -f "${PDFOUTPUT}"
        fi
    fi
else
    echo "Usage: $(basename "${0}") <file.pdf>"
fi
Another approach based on pdftk instead of ghostscript:

Code:
# cat /usr/local/bin/pdfrecompress 
#!/bin/bash

if [ "$(command -v pdftk)" = "" ]
then
    echo "Please first install pdftk in order to use $(basename "${0}")"
    exit 1
fi

PDFINPUT="${1}"

if [ "${PDFINPUT}" != "" ] && [ -f "${PDFINPUT}" ]
then
    PDFOUTPUT=$(basename "${PDFINPUT}" .pdf)_fixed.pdf
    if [ ! -f "${PDFOUTPUT}" ]
    then
        #echo "Uncompressing ${PDFINPUT}"
            pdftk "${PDFINPUT}" output uncompressed.pdf uncompress && \
        echo "Recompressing modified document..."
            pdftk uncompressed.pdf output compressed.pdf compress && \
                mv compressed.pdf "${PDFOUTPUT}"
                rm -f uncompressed.pdf
    else
        echo "${PDFOUTPUT} already exists"
    fi
    if [ -f "${PDFOUTPUT}" ]
    then
        if [ "$(/usr/bin/du "${PDFOUTPUT}" | awk '{print $1}')" -lt "$(/usr/bin/du "$(basename "${PDFOUTPUT}" _fixed.pdf)".pdf | awk '{print $1}')" ]
        then
            /bin/mv "${PDFOUTPUT}" "$(basename "${PDFOUTPUT}" _fixed.pdf)".pdf
        else
            echo "Discarding recompressed pdf larger than input file:"
            /usr/bin/du -sk "${PDFOUTPUT}" 
            rm -f "${PDFOUTPUT}"
        fi
    fi
else
    echo "Usage: $(basename "${0}") <file.pdf>"
fi
Be careful to not apply this to your precious original PDF file as it will be overwritten, but rather try this on a differently named copy of it.
orebmur is offline   Reply With Quote