[Tex/LaTex] PDF file containing 3D object is not included correctly with \includegraphics

3dgraphicspdf

I have a PDF file, containing a 3D object in PRC format. I try to include this into a LaTeX document to be compiled with pdflatex, with the simple source below:

\documentclass{minimal}
\usepackage{graphicx}
\begin{document}
\includegraphics{LC.pdf}
\end{document}

Running pdflatex (version 3.1415926-2.3-1.40.12, TeX Live 2011) over this does not yield any error or warning, but the PDF file created does not include the 3D content (in fact, it is empty). The log file for my compilation appears happy, however:

<LC.pdf, id=1, 200.74097pt x 196.72597pt>
File: LC.pdf Graphic file (type pdf)
 <use LC.pdf>
Package pdftex.def Info: LC.pdf used on input line 4.
(pdftex.def)             Requested size: 200.74046pt x 196.72548pt.
 [1 <./LC.pdf>] (./a.aux) )

So: what am I doing wrong? How can I include this PDF figure, keeping its 3D content, into a LaTeX document?

Best Answer

As Martin said, interactive parts of a PDF, called Annotations in PDF specification parlance, such as links or 3D objects, get lost when embedding a PDF containing them. Instead, Annotations have to be re-generated for the new PDF.

To embed a 3D object in the PRC format into a PDF, use LaTeX package media9. See media9 manual, section "3D quick-start guide".

In case the standalone PRC file is not available it can be extracted from the PDF. This can be done manually, as explained below, or automatically with the help of a small Perl script. Either method requires a tool for uncompressing PDFs, such as PDFtk.

Extracting the PRC from PDF is not recommended if the PRC was generated by asymptote and you have the asy source file of it! Standalone PRC files are generated from asy source by

    asy --keep --tex pdflatex mysource.asy

Automatically, using PDFtk + Perl script

This extracts all PRC streams from PDFwithPRC.pdf to separate files prc-0.prc, prc-1.prc, ...

pdftk PDFwithPRC.pdf output - uncompress | perl prcextract.pl

On Windows, with a Java runtime and some perl.exe installed:

java -jar pdftk-all.jar PDFwithPRC.pdf output - uncompress | perl prcextract.pl

Perl script prcextract.pl:

#!/usr/bin/perl

$prc=0;
$stream=0;
$cnt=0;

while(<>){
  if(/^stream/) {$stream=1;}
  elsif(/^endstream/) {$stream=0; if($prc){close $PRC;} $prc=0;}
  elsif((/^PRC/ || $prc) && $stream) {
    if(!$prc){open $PRC,">prc-".$cnt++.".prc";select $PRC} print; $prc=1;
  }
}

Manual procedure, by PDFtk + text editor

First uncompress the PDF:

pdftk doc.pdf output doc.unc.pdf uncompress

Open doc.unc.pdf in a text editor and scroll down to a line that starts with PRC. This line appears just after a line with the PDF keyword stream.

Delete everything from begin of the file up to and including the line containing the stream keyword.

Delete everything beginning with the line starting with the endstream keyword directly after the PRC stream upto the end of the file.

Save what has left as a file whose name ends in .prc.

Related Question