pdflatex: el tamaño de archivo del pdf generado usando includepdfmerge(pdf-pages) es mucho más pequeño que el de includegraphics

pdflatex: el tamaño de archivo del pdf generado usando includepdfmerge(pdf-pages) es mucho más pequeño que el de includegraphics

Tengo un archivo pdf test.pdf. Estoy regenerando el mismo pdf usando dos métodos diferentes includepdfmergey includegraphics. Descubrí que el pdf generado usando includepdfmergees casi igual que el pdf original, mientras que el pdf generado usando includegraphicses 3-4 veces más grande que el archivo original. A continuación se muestra el código de látex y también se adjunta el enlace de los archivos.

MÉTODO 1: usar includepdfmerge

NOMBRE DEL ARCHIVO DE SALIDA: test_includepdf.pdf

El script agrega 5 páginas de test.pdf

\documentclass[version=3.21]{scrartcl}
\usepackage{pdfpages}
\usepackage[showframe]{geometry}
\usepackage[automark,headsepline=false,footsepline=false]{scrlayer-scrpage}
\pagestyle{empty}
\begin{document}
\newgeometry{layoutwidth = 432pt,layoutheight = 33.87999pt,left=0mm,right=0mm,top=0mm, bottom=0mm}
\includepdfmerge[fitpaper,templatesize={432pt}{33.87999pt}]{test.pdf, 1}
\newgeometry{layoutwidth = 432pt,layoutheight = 33.87999pt,left=0mm,right=0mm,top=0mm, bottom=0mm}
\includepdfmerge[fitpaper,templatesize={432pt}{33.87999pt}]{test.pdf, 2}
\newgeometry{layoutwidth = 432pt,layoutheight = 33.87999pt,left=0mm,right=0mm,top=0mm, bottom=0mm}
\includepdfmerge[fitpaper,templatesize={432pt}{33.87999pt}]{test.pdf, 3}
\newgeometry{layoutwidth = 432pt,layoutheight = 33.87999pt,left=0mm,right=0mm,top=0mm, bottom=0mm}
\includepdfmerge[fitpaper,templatesize={432pt}{33.87999pt}]{test.pdf, 4}
\newgeometry{layoutwidth = 432pt,layoutheight = 33.87999pt,left=0mm,right=0mm,top=0mm, bottom=0mm}
\includepdfmerge[fitpaper,templatesize={432pt}{33.87999pt}]{test.pdf, 5}
\end{document}

MÉTODO 2: usando gráficos de inclusión

NOMBRE DEL ARCHIVO DE SALIDA: test_includegraphics.pdf

El script agrega 5 páginas de test.pdf

\documentclass[parskip=full,version=3.21]{scrartcl}
\usepackage{pdfpages}
\usepackage[showframe]{geometry}
\usepackage[automark,headsepline=false,footsepline=false]{scrlayer-scrpage}
\pagestyle{empty}
\setlength{\parindent}{0pt}
\setlength{\parskip}{0pt}
\setlength{\baselineskip}{0pt}
\begin{document}
\KOMAoptions{paper=432pt:33.87999pt,DIV=calc}%
\recalctypearea%
\newgeometry{layoutwidth = 432pt,layoutheight = 33.87999pt,left=0mm,right=0mm,top=0mm, bottom=0mm}%
\includegraphics[width=\textwidth,keepaspectratio,page=1]{test.pdf}%
\KOMAoptions{paper=432pt:33.87999pt,DIV=calc}%
\recalctypearea%
\newgeometry{layoutwidth = 432pt,layoutheight = 33.87999pt,left=0mm,right=0mm,top=0mm, bottom=0mm}%
\includegraphics[width=\textwidth,keepaspectratio,page=2]{test.pdf}%
\KOMAoptions{paper=432pt:33.87999pt,DIV=calc}%
\recalctypearea%
\newgeometry{layoutwidth = 432pt,layoutheight = 33.87999pt,left=0mm,right=0mm,top=0mm, bottom=0mm}%
\includegraphics[width=\textwidth,keepaspectratio,page=3]{test.pdf}%
\KOMAoptions{paper=432pt:33.87999pt,DIV=calc}%
\recalctypearea%
\newgeometry{layoutwidth = 432pt,layoutheight = 33.87999pt,left=0mm,right=0mm,top=0mm, bottom=0mm}%
\includegraphics[width=\textwidth,keepaspectratio,page=4]{test.pdf}%
\KOMAoptions{paper=432pt:33.87999pt,DIV=calc}%
\recalctypearea%
\newgeometry{layoutwidth = 432pt,layoutheight = 33.87999pt,left=0mm,right=0mm,top=0mm, bottom=0mm}%
\includegraphics[width=\textwidth,keepaspectratio,page=5]{test.pdf}%
\end{document}

Todos los archivos están disponibles en el enlace.https://filebin.net/1498hwp3fxnngpcs Nota: El enlace anterior caducará el 20 de septiembre de 2020.

Los tamaños de archivo que obtuve son:

 test.pdf   19 kB
 test_includepdf.pdf    20 kB
 test_includegraphics.pdf   76 kB

Como vemos, test_includegrahicps.pdfes significativamente más grande que el test.pdfytest_includepdf.pdf

Por qué el segundo script con includegraphics produce archivos PDF de gran tamaño. ¿Hay alguna manera de poder controlar el tamaño?

Porque si pruebo un pdf con 1000páginas, entonces usar includepdftamaño de archivo es 1MBy usar includegrahicpses11MB

SOLUCIÓN TEMPORAL

ACTUALMENTE BASADO EN ALGUNOS RASTRO Y ERRORES, PODRÍA HACER EL TAMAÑO DEL ARCHIVO MÁS PEQUEÑO USANDO la combinación de includepdfy includegraphics. Esta no es la solución correcta pero resuelve hasta cierto punto mi necesidad.

No pude entender el motivo de mi pregunta.

Pero debido a que tengo que usar includegraphics en mi proyecto de látex y al mismo tiempo no quiero archivos de gran tamaño, al hacer seguimiento y error descubrí la siguiente manera que producirá un tamaño de archivo mucho menor.

Agregue una primera página adicional en el pdf que se llamará usando \includepdfmergey luego se podrá llamar al resto de las páginas usandoincludegraphics

así que lo intenté

\documentclass[parskip=full,version=3.21]{scrartcl}
\usepackage{pdfpages}
\usepackage[showframe]{geometry}
\usepackage[automark,headsepline=false,footsepline=false]{scrlayer-scrpage}
\usepackage{xcolor}
\color[RGB]{84,84,84}
\pagestyle{empty}
\setlength{\parindent}{0pt}
\setlength{\parskip}{0pt}
\setlength{\baselineskip}{0pt}
\begin{document}
%%%%%%%% ADDITIONAL PAGE IN THE START CALLED USING includepdfmerge
\newgeometry{layoutwidth = 432pt,layoutheight = 33.87999pt,left=0mm,right=0mm,top=0mm, bottom=0mm}
\includepdfmerge[fitpaper,templatesize={432pt}{33.87999pt}]{test.pdf, 1}
%%%%%%  LATER PAGES CALLED USING INCLUDEGRAPHICS
\KOMAoptions{paper=432pt:38.87999pt,DIV=calc}%
\recalctypearea%
\newgeometry{layoutwidth = 432pt,layoutheight = 38.87999pt,left=0mm,right=0mm,top=0mm, bottom=0mm}%
\includegraphics[width=\textwidth,keepaspectratio,page=1]{test.pdf}%
\KOMAoptions{paper=432pt:38.87999pt,DIV=calc}%
\recalctypearea%
\newgeometry{layoutwidth = 432pt,layoutheight = 38.87999pt,left=0mm,right=0mm,top=0mm, bottom=0mm}%
\includegraphics[width=\textwidth,keepaspectratio,page=2]{test.pdf}%
\KOMAoptions{paper=432pt:38.87999pt,DIV=calc}%
\recalctypearea%
\newgeometry{layoutwidth = 432pt,layoutheight = 38.87999pt,left=0mm,right=0mm,top=0mm, bottom=0mm}%
\includegraphics[width=\textwidth,keepaspectratio,page=3]{test.pdf}%
\KOMAoptions{paper=432pt:38.87999pt,DIV=calc}%
\recalctypearea%
\newgeometry{layoutwidth = 432pt,layoutheight = 38.87999pt,left=0mm,right=0mm,top=0mm, bottom=0mm}%
\includegraphics[width=\textwidth,keepaspectratio,page=4]{test.pdf}%
\KOMAoptions{paper=432pt:38.87999pt,DIV=calc}%
\recalctypearea%
\newgeometry{layoutwidth = 432pt,layoutheight = 38.87999pt,left=0mm,right=0mm,top=0mm, bottom=0mm}%
\includegraphics[width=\textwidth,keepaspectratio,page=5]{test.pdf}%
\end{document}

El siguiente es el cambio:

\newgeometry{layoutwidth = 432pt,layoutheight = 33.87999pt,left=0mm,right=0mm,top=0mm, bottom=0mm}
\includepdfmerge[fitpaper,templatesize={432pt}{33.87999pt}]{test.pdf, 1}

Se agregó \includepdfmerge en la página inicial y en las páginas posteriores usandoincludegraphics

\KOMAoptions{paper=432pt:38.87999pt,DIV=calc}%
\recalctypearea%
\newgeometry{layoutwidth = 432pt,layoutheight = 38.87999pt,left=0mm,right=0mm,top=0mm, bottom=0mm}%
\includegraphics[width=\textwidth,keepaspectratio,page=1]{test.pdf}%

El archivo pdf final tiene una página extra al principio.

Ahora el tamaño del archivo es 20kb. El siguiente enlace es el resultado final en pdf.

https://filebin.net/5p2a32kdx80qmvni

Respuesta1

Parece ser suficiente almacenar el pdf una vez en un cuadro temporal para activar la optimización de la fuente. Sólo es necesario con pdflatex, lualatex lo hace de forma predeterminada.

\documentclass{article}
\usepackage{graphicx}
\pagestyle{empty}
\makeatletter
\setbox\@tempboxa=\hbox{\includegraphics{example-image-a4-numbered}}% font is included only once
\makeatother
\begin{document}

\includegraphics[width=\textwidth,keepaspectratio,page=1]{example-image-a4-numbered}%
\newpage
\includegraphics[width=\textwidth,keepaspectratio,page=2]{example-image-a4-numbered}%
\newpage
\includegraphics[width=\textwidth,keepaspectratio,page=3]{example-image-a4-numbered}%
\newpage
\includegraphics[width=\textwidth,keepaspectratio,page=4]{example-image-a4-numbered}%
\newpage
\includegraphics[width=\textwidth,keepaspectratio,page=5]{example-image-a4-numbered}%
\end{document}

Respuesta2

RESPUESTA PARTE 1: POR QUÉ EL TAMAÑO DEL ARCHIVO ES GRANDE cuando solo se usan gráficos de inclusión

Se debe a las fuentes incrustadas varias veces.

Archivo creado utilizando únicamenteincludegraphics

$ pdffonts test_includegraphics.pdf 
name                                 type              encoding         emb sub uni object ID
------------------------------------ ----------------- ---------------- --- --- --- ---------
ABCDEE+ScaGoudy                      TrueType          WinAnsi          yes yes no       9  0
ABCDEE+ScaGoudy                      TrueType          WinAnsi          yes yes no      19  0
ABCDEE+ScaGoudy                      TrueType          WinAnsi          yes yes no      31  0
ABCDEE+ScaGoudy                      TrueType          WinAnsi          yes yes no      41  0
ABCDEE+ScaGoudy                      TrueType          WinAnsi          yes yes no      51  0

Archivo creado usando soloincludepdfmerge

$ pdffonts test_includepdf.pdf 
name                                 type              encoding         emb sub uni object ID
------------------------------------ ----------------- ---------------- --- --- --- ---------
ABCDEE+ScaGoudy                      TrueType          WinAnsi          yes yes no      12  0

ARCHIVO realizado usando la primera página includepdfmergey el resto usandoincludegraphics

$ pdffonts test_mix.pdf       
name                                 type              encoding         emb sub uni object ID
------------------------------------ ----------------- ---------------- --- --- --- ---------
ABCDEE+ScaGoudy                      TrueType          WinAnsi          yes yes no      15  0

Como puede verse, la fuente está incrustada 5 timescuando la usé solo includegraphicsen otros dos casos.once

NO SE ENCONTRÓ RESPUESTA PARA LA PARTE 2: CÓMO EVITARLA

But now the question is how can we avoid font getting embedded mutliple times when made using only includegraphics

Encontré una pregunta similar:

La misma fuente incrustada dos veces al incluir gráficos creados de forma independiente

Una de las respuestas dice que no es posible usar látex. La única manera es hacerlo más tarde usandopdfsizeopt https://tex.stackexchange.com/a/83709/221200

También probé la solución sugerida \pdfinclusioncopyfonts=0, pero no funciona o las fuentes se incrustan varias veces en pdflatex.

información relacionada