TransWikia.com

Read PDF size to adjust size of next page

TeX - LaTeX Asked on October 2, 2021

I am trying to read the size of a PDF file to adjust the size of the next page to the size of the figure.
I have had some success, but the figure is still not well adjusted. I could adjust this figure, but I want to automate the adjustment, as I have 150 figures to insert in the file.
I also need to add an extra height on the page, to place the caption of the figure.
Any suggestion?

%-----------------------------------------------------------------
    setbox0 = hbox{includegraphics{01.pdf}}
    width = thewd0, height = theht0

newpage
%================================================================================
eject pdfpagewidth=thewd0 pdfpageheight=theht0

begin{figure}
    caption{<name picture>}
    includegraphics{01.pdf}
end{figure}

enter image description here

2 Answers

Here is an attempt using igrgraph command from incgraph pacakge.

igrgraph{<text>} automatically typesets <text> in a separate page with height and width the same of <text>, so you don't need to manually change page size.

documentclass{article}
usepackage{incgraph}
usepackage{caption}

begin{document}
text on first page
igrpage{%
  setbox0=hbox{includegraphics{example-image}}%
  begin{minipage}{wd0}
    captionof{figure}{figure on second page}
    box0relax
  end{minipage}%
}
text on third page
end{document}

This generates a three-page pdf, of which the second page is enter image description here

Correct answer by muzimuzhi Z on October 2, 2021

PARTIAL ANSWER

with the help of the answer below:

https://tex.stackexchange.com/a/268919/134993

I write:

%---------------------------------------------------
    newsavebox{measurebox}
    newlength{measuredwidth}
    newlength{measuredheight}
    newcommandmeasureimage[2][1]{%
        savebox{measurebox}{includegraphics[page=#1]{#2}}%
        setlength{measuredwidth}{wdmeasurebox}%
        setlength{measuredheight}{htmeasurebox}%
        savebox{measurebox}{}%
    } %-----------------------------------------------------------------------
measureimage[1]{01.pdf} % measures the 1nd page of the file.
    
newpage
    
newgeometry{left=0mm,right=0mm,top=0cm,bottom=0cm}
eject pdfpagewidth=measuredwidth pdfpageheight=measuredheight

begin{figure}[h]
includegraphics{01.pdf}
caption{caption picture}
end{figure}
%-----------------------------------------------------------------------

TO DO: I still have to find out a way to insert a space below the figure to place the caption.

Any suggestions?

enter image description here

Answered by Edson Marcon on October 2, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP