
이 주제에 대해 찾을 수 있는 모든 답변을 시도했지만 제대로 작동하지 않습니다.
이 MWE는 제대로 작동하지만 \pdfximage
lualatex에서는 작동하지 않으므로 pdflatex에서만 작동합니다.
\documentclass[12pt]{article}%
\usepackage{graphicx}
\begin{document}
\pdfximage{index.pdf}%
\the\pdflastximagepages
\end{document}
작동하지 않습니다. 위 링크의 코드는 다음과 같습니다.
\documentclass{article}
\newcommand*{\pdfnumberofpages}[1]{%
\directlua{%
local doc = epdf.open("\luatexluaescapestring{#1}")
local pages
if (doc) then
pages = doc:getCatalog():getNumPages()
else
pages = 0
end
tex.write(pages)
}%
}
\begin{document}
Number of pages: \pdfnumberofpages{index.pdf}
\end{document}
이제, lulatex foo.tex
준다
(/usr/local/texlive/2019/texmf-dist/tex/latex/base/size10.clo)) (./foo.aux)
! Undefined control sequence.
\pdfnumberofpages ...open("\luatexluaescapestring
{#1}") local pages if (doc...
l.17 Number of pages: \pdfnumberofpages{test.pdf}
다음을 사용하여 외부 PDF 파일의 PDF 페이지 수를 얻는 올바른 방법은 무엇입니까루아텍스?
Linux에서 TL 2019를 사용합니다.
답변1
pdftex 프리미티브는 사라지지 않았으며 이름만 변경되었습니다: \pdfximage
is \saveimageresource
및 \pdflastximagepages
is \lastsavedimageresourcepages
. 그래서:
\documentclass[12pt]{article}%
\usepackage{graphicx}
\begin{document}
\saveimageresource{index.pdf}%
\the\lastsavedimageresourcepages
\end{document}
또는 luatex85
패키지를 로드한 다음 pdftex 기본 요소를 사용하여 문서가 pdflatex 및 lualatex로 컴파일되도록 할 수 있습니다.
답변2
라이브러리 (poppler 기반) 가 라이브러리(pplib 기반) epdf
로 대체되었습니다 . pdfe
또한 을 정의하지 않았 \luatexluaescapestring
으므로 을 의미했을 것입니다 \luaescapestring
.
\documentclass{article}
\newcommand*{\pdfnumberofpages}[1]{%
\directlua{%
local pages = 0
local doc = pdfe.open("\luaescapestring{#1}")
if doc then
pages = pdfe.getnofpages(doc)
pdfe.close(doc)
end
tex.write(pages)
}%
}
\begin{document}
Number of pages: \pdfnumberofpages{index.pdf}
\end{document}