# PDF file containing 3D object is not included correctly with \includegraphics

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?

• I guess the 3D object is implemented using PDF annotations. These are dropped by pdftex because AFAIK they only work reliable in the main PDF, not in an included PDF. The same is true for hyperlinks in included PDFs. I think there might be a way to have them, but pdftex doesn't know how to handle included PDF annotations in general. See How to preserve hyperlinks in included pdf? which might work as duplicate. Apr 15, 2012 at 14:21
• @Martin Well, I'm sure it can be done, because Acrobat and at least one other PDF editor manage to do it (and I have not yet experienced an issue with this)! But it might be that pdftex implementation is lacking in this respect. It is be a bit sad if, after generating my PDF with pdflatex, I have to include my 3D graphs using Acrobat Pro…
– F'x
Apr 15, 2012 at 14:35
• It looks to me like that. You could ask the question on comp.text.tex as well, there it will be noticed by the pdftex gurus/developers, which might give you an authorized answer on this topic. Apr 15, 2012 at 14:38
• @Martin thanks, I have now asked on c.t.t
– F'x
Apr 15, 2012 at 14:46
• @egreg I know; I am using Acrobat X Pro (and I also checked with Adobe Reader 9)
– F'x
Apr 15, 2012 at 15:00

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.

• media9 allows include of PRC files into PDF, but not PRC-containing PDF files into PDF. Do you have a solution to extract a PRC from a PDF?
– F'x
Apr 16, 2012 at 8:34
• It's possible. See my edit. Apr 16, 2012 at 8:58
• Your example file was generated using asymptote. In that case it is much better to create a standalone PRC from the asy source file and include it with media9. See my answer to your previous question. Apr 16, 2012 at 9:03
• @Regarding Asymptote, yes, I understand it's easier with the PRC file… but then again, you need not only the .prc but a lot of auxiliary files, which is a pain (compared to the simple PDF). In the end, the answer seems to be that pdftex simply doesn't support this kind of inclusion, and no one is interested enough to fix it (I am interested, but not to the point of hacking pdftex without any prior experience!).
– F'x
Apr 16, 2012 at 9:55
• Under the hood, Asympote uses my old movie15.sty package for including the PRC into PDF. It is obsolete and to be replaced by the new media9. There is not much about the additional JavaScript file you are referring to and which Asymtote attaches. It only enables billboard behaviour of textlabels (labels always facing the camera) and setting orthographic view instead of perspective view. All this can be done easily with media9 (add3Djscript=asylabels.js, 3Dortho). The optimal viewpoint, size&aspect ration can be set from within Reader, just right-click on Generate Default View. Apr 16, 2012 at 10:20