pdflatex: o tamanho do arquivo pdf gerado usando includepdfmerge(pdf-pages) é muito menor que includegraphics

pdflatex: o tamanho do arquivo pdf gerado usando includepdfmerge(pdf-pages) é muito menor que includegraphics

Eu tenho um arquivo pdf test.pdf. Estou regenerando o mesmo pdf usando dois métodos diferentes includepdfmergee o arquivo includegraphics. Descobri que o pdf gerado usando includepdfmergeé quase igual ao pdf original, onde o pdf gerado usando includegraphicsé 3-4 vezes maior que o arquivo original. Abaixo está o código do látex e também anexo o link para os arquivos.

MÉTODO 1: usando includepdfmerge

NOME DO ARQUIVO DE SAÍDA: test_includepdf.pdf

O script está adicionando 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 includegraphics

NOME DO ARQUIVO DE SAÍDA: test_includegraphics.pdf

O script está adicionando 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 os arquivos estão disponíveis no linkhttps://filebin.net/1498hwp3fxnngpcs Observação: o link acima expirará em 20 de setembro de 2020

Os tamanhos de arquivo que obtive são:

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

Como vemos que test_includegrahicps.pdfé significativamente maior do que o test.pdfetest_includepdf.pdf

Por que o segundo script com includegraphics produz PDFs de tamanhos grandes. Existe alguma maneira de controlar o tamanho.

Porque se eu tentar um pdf com 1000páginas, usar includepdftamanho de arquivo é 1MBe usar includegrahicpsé11MB

SOLUÇÃO TEMPORÁRIA

ATUALMENTE COM BASE EM ALGUMAS TRILHAS E ERROS, EU PODERIA FAZER O TAMANHO DO ARQUIVO MENOR USANDO a combinação de includepdfe includegraphics. Esta não é a solução certa, mas resolve até certo ponto a minha necessidade

Não consegui descobrir o motivo da minha pergunta.

Mas como eu tenho que usar includegraphics em meu projeto de látex e ao mesmo tempo não quero tamanhos de arquivo grandes, fazendo trilha e erro descobri a seguinte maneira que produzirá menos tamanho de arquivo significativamente menor

Adicione uma primeira página adicional no pdf que será chamada usando \includepdfmergee então o restante das páginas poderá ser chamado usandoincludegraphics

Então eu tentei

\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}

A seguir está a mudança:

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

Adicionado \includepdfmerge na página inicial e nas 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}%

O arquivo pdf final tem uma página extra no início

AGORA o tamanho do arquivo é 20kb. O link a seguir é o resultado final em pdf

https://filebin.net/5p2a32kdx80qmvni

Responder1

Parece ser suficiente armazenar o pdf uma vez em uma caixa temporária para acionar a otimização da fonte. É necessário apenas com pdflatex, lualatex faz isso por padrão.

\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}

Responder2

RESPOSTA PARTE 1: POR QUE O TAMANHO DO ARQUIVO É GRANDE ao usar apenas includegraphics

É devido às fontes incorporadas várias vezes

Arquivo feito usando apenasincludegraphics

$ 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

Arquivo feito usando apenasincludepdfmerge

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

ARQUIVO feito usando a primeira página includepdfmergee restante usandoincludegraphics

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

Como pode ser visto, a fonte é incorporada 5 timesquando usei apenas includegraphicsonde outros dois casos apenasonce

NENHUMA RESPOSTA ENCONTRADA PARA A PARTE 2: COMO EVITAR

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

Encontrei uma pergunta semelhante:

A mesma fonte incorporada duas vezes ao incluir gráficos criados de forma independente

Uma das respostas diz que usar látex não é possível. A única maneira é fazer isso mais tarde usandopdfsizeopt https://tex.stackexchange.com/a/83709/221200

Também tentei a solução sugerida \pdfinclusioncopyfonts=0, mas não funciona ou as fontes são incorporadas várias vezes no pdflatex

informação relacionada