pdflatex: includepdfmerge(pdf-pages)를 사용하여 생성된 PDF의 파일 크기는 그래픽을 포함하는 것보다 훨씬 작습니다.

pdflatex: includepdfmerge(pdf-pages)를 사용하여 생성된 PDF의 파일 크기는 그래픽을 포함하는 것보다 훨씬 작습니다.

PDF 파일이 있습니다 test.pdf. 두 가지 다른 방법을 사용하여 동일한 PDF를 다시 생성하고 있습니다 includepdfmerge. includegraphics나는 를 사용하여 생성된 PDF가 includepdfmerge원본 PDF와 거의 동일하다는 것을 발견했습니다. 여기서 를 사용하여 생성된 PDF는 includegraphics원본 파일보다 3-4배 더 큽니다. 아래는 라텍스 코드이며 파일 링크도 첨부되어 있습니다.

방법1: includepdfmerge 사용

출력 파일명: test_includepdf.pdf

스크립트는 test.pdf에서 5페이지를 추가합니다.

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

방법2: includegraphics 사용

출력 파일명: test_includegraphics.pdf

스크립트는 test.pdf에서 5페이지를 추가합니다.

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

모든 파일은 링크에 있습니다https://filebin.net/1498hwp3fxnngpcs 참고: 위 링크는 2020년 9월 20일에 만료됩니다.

내가 얻은 파일 크기는 다음과 같습니다.

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

우리가 볼 수 있듯이 test_includegrahicps.pdf이는 test.pdftest_includepdf.pdf

포함 그래픽이 포함된 두 번째 스크립트가 큰 PDF 크기를 생성하는 이유 사이즈를 조절할 수 있는 방법이 없을까요?

페이지 가 포함된 PDF를 시도하면 파일 크기를 1000사용 하고 사용하는 것은includepdf1MBincludegrahicps11MB

임시 해결 방법

includepdf현재 일부 트레일과 오류로 인해 및 의 조합을 사용하여 파일 크기를 더 작게 만들 수 있습니다 includegraphics. 이것은 올바른 해결책은 아니지만 내 요구 사항을 어느 정도 해결합니다.

나는 내 질문의 이유를 알 수 없었다.

하지만 내 라텍스 프로젝트에서 인클루드그래픽을 사용해야 하고 동시에 큰 파일 크기를 원하지 않기 때문에 트레일 앤 에러를 수행하여 파일 크기를 훨씬 적게 생성하는 다음 방법을 알아냈습니다.

다음을 사용하여 호출할 PDF의 추가 첫 번째 페이지를 추가한 \includepdfmerge다음 나머지 페이지를 다음을 사용하여 호출할 수 있습니다.includegraphics

그래서 나는 노력했다

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

변경 사항은 다음과 같습니다.

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

다음을 사용하여 시작 페이지와 이후 페이지에 \includepdfmerge를 추가했습니다.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}%

최종 PDF 파일에는 처음에 추가 페이지가 하나 있습니다

이제 파일 크기는 20kb. 다음 링크는 최종 출력 PDF입니다.

https://filebin.net/5p2a32kdx80qmvni

답변1

글꼴 최적화를 실행하려면 PDF를 임시 상자에 한 번 저장하는 것으로 충분할 것 같습니다. pdflatex에만 필요하며, lualatex는 기본적으로 이를 수행합니다.

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

답변2

답변 1부: 인클루드그래픽만 사용할 때 파일 크기가 큰 이유

글꼴이 여러 번 삽입되었기 때문입니다.

만 사용하여 만든 파일includegraphics

$ 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

만 사용하여 만든 파일includepdfmerge

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

첫 번째 페이지를 사용하여 FILE을 만들고 includepdfmerge나머지는 다음을 사용하여 만듭니다.includegraphics

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

보시다시피 다른 두 가지 경우에만 5 times사용할 때 글꼴이 포함됩니다.includegraphicsonce

2부에 대한 답변을 찾을 수 없음: 이를 방지하는 방법

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

비슷한 질문을 찾았습니다.

독립 실행형으로 생성된 그래픽을 포함할 때 동일한 글꼴이 두 번 포함됩니다.

답변 중 하나는 라텍스를 사용하는 것이 불가능하다고 말합니다. 유일한 방법은 나중에 다음을 사용하여 수행하는 것입니다.pdfsizeopt https://tex.stackexchange.com/a/83709/221200

또한 제안된 솔루션을 시도했지만 \pdfinclusioncopyfonts=0작동하지 않거나 PDFlatex에 글꼴이 여러 번 포함됩니다.

관련 정보