2

I am creating a template for document creation, where I need to insert images of varying sizes (sometimes 1024px, sometimes ~4000px wide). Those images can be oriented both vertically and horizontally.

The problem is, I can't afford to have them shrunk (there is text in them).
Is there a way to force LaTeX to create a new page as big as the picture, which picture would fully fill?

I thought of a macro, which would end document style and temporarily use a different one (change pages to horizontal, change sizes...), but I don't think this would handle sizes well.

In the past, I did this manually via Adobe Acrobat (which was able to insert an image as an independent page with its own size). I use MiKTeX 2.9.

CarLaTeX
  • 62,716
  • 3
    Short answer: Use pdfpages or standalone depending on what you want (include an image page to LaTeX or create a page reduced to the contents). – Schweinebacke Feb 03 '17 at 13:08
  • pdfpages looks like it inserts pdf pages, I have those images in .jpg, .png or something like that. Anyway, it might work with some effort. Does it preserve the size of included pages?

    About standalone package, I can't really imagine how would I use it. Ideally, I would like to create macro, which would take image.jpg(.png...) as an argument and create a new page, which would contain only image.jpg

    – liskacek Feb 03 '17 at 14:44
  • See http://tex.stackexchange.com/questions/6834/change-paper-size-in-mid-document OTOH, are you sure you are losing resolution? A PDF viewer with a zoom feature should be able to recover the full resolution (and the resulting PDF files can become huge). – John Kormylo Feb 03 '17 at 15:23
  • You mean that if I were to insert image into a page and it was resized, it stil should be able to recover the full resolution? Like putting 4600px * 3450px on A4 page and with enough zoom, it would still show it in original size? – liskacek Feb 03 '17 at 15:46
  • Yes, but you would have to know the zoom factor to use. Another option is to use \href (hyperref package) to link to the image file. – John Kormylo Feb 03 '17 at 21:01
  • pdfpages cannot only insert PDFs but every image format graphicx can import. Using pdflatex, xelatex or lualatex you can, e.g., also insert PNG or JPEG pages without loosing any pixel of the original file. – Schweinebacke Feb 04 '17 at 16:13

1 Answers1

2

Here is an example using the PNG shown below. While zooming in on the circle shows stair-stepping, both images when zoomed look the same.

\documentclass{article}
\usepackage{graphicx}
\usepackage{hyperref}

\begin{document}
\href{http://www.elfsoft2000.com/projects/large.png}{link to web image}

\href[pdfnewwindow]{large.pdf}{link to local pdf}

\includegraphics[width=0.25\textwidth]{large.png}

\noindent\includegraphics[width=\textwidth]{large.png}

\end{document}

example iamge

It turns out you can only link to images on the web or local PDFs. However, one can easily convert images to PDFs using standalone.

\documentclass{standalone}
\usepackage{graphicx}
\begin{document}
\includegraphics{large.png}
\end{document}
John Kormylo
  • 79,712
  • 3
  • 50
  • 120
  • May I ask for an example of targeting local pdf? I tried \href{pom.pdf}{link to image}. pom.pdf is located in the same folder. – liskacek Feb 04 '17 at 12:35
  • I tried to enter relative path \hyperbaseurl{pom.pdf} and absolute path \hyperbaseurl{D:\Test\Img}, but that did not work. Main file has an image prepared in pom.pdf, which is in the same folder. I tried googling, but I did not find much about \hyperbaseurl. – liskacek Feb 05 '17 at 11:51
  • My experiments show that \hyperbaseurl has to go into the preamble. My latest experiments show that the baseurl is ignored with local PDFs. Weird! – John Kormylo Feb 05 '17 at 17:21
  • The heart of \baseurl is the command \special{html:<base href="\@baseurl">} which is executed AtBeginDocument. In other words, the base url is written as HTML directly to the PDF driver. – John Kormylo Feb 05 '17 at 18:11
  • I managed to find an easy way how to deal with this problem: http://ftp.math.purdue.edu/mirrors/ctan.org/macros/latex/contrib/incgraph/incgraph.pdf ... "The graphics can be centered for a given paper format or the paper may be resized to the graphics dimensions." It looks like it is exactly what I needed. Thank you for your answers. – liskacek Feb 06 '17 at 20:49