%20es%20mucho%20m%C3%A1s%20peque%C3%B1o%20que%20el%20de%20includegraphics.png)
Tengo un archivo pdf test.pdf
. Estoy regenerando el mismo pdf usando dos métodos diferentes includepdfmerge
y includegraphics
. Descubrí que el pdf generado usando includepdfmerge
es casi igual que el pdf original, mientras que el pdf generado usando includegraphics
es 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.pdf
es significativamente más grande que el test.pdf
ytest_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 1000
páginas, entonces usar includepdf
tamaño de archivo es 1MB
y usar includegrahicps
es11MB
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 includepdf
y 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 \includepdfmerge
y 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.
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 includepdfmerge
y 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 times
cuando la usé solo includegraphics
en 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.