Q: I am trying to embed an U3D models in a PDF annotation. I have
successfully embedded an U3D model to an existing 3d annotation, but
is seems to override the one that was already there. And it seems to
override the annotation’s javascript as well.
I have been using your library to attatch the U3D models. Is embedding
multiple U3D files possible with the current library distribution? I
have attatched the code I am using so far as an example:
static void AnnotationHighLevelAPI(PDFDoc doc) throws PDFNetException
{
System.out.println("Traversing all annotations in the document...");
int page_num = 1;
for (PageIterator itr = doc.getPageIterator(); itr.hasNext() {
System.out.println("Page " + (page_num++) + ": ");
Page page = (Page) (itr.next());
int num_annots = page.getNumAnnots();
for (int i = 0; i < num_annots; ++i) {
Annot annot = page.getAnnot(i);
if (annot.isValid() == false) continue;
System.out.println("Annot Type: " +
annot.getSDFObj().get("Subtype").value().getName());
double[] bbox = annot.getRect().get();
System.out.println(" Position: " + ", " + bbox[0] + ", "
+ bbox[1] + ", " + bbox[2] + ", " + bbox[3]);
// my annotation is on the right side of the screen
if (bbox[0] > 140) {
Obj cosAnnot = annot.getSDFObj();
StdFile u3d_file = new StdFile(("c:/model.u3d"),
StdFile.e_read_mode);
FilterReader u3d_reader = new FilterReader(u3d_file);
Obj u3d_data_dict = doc.createIndirectStream(u3d_reader,new
FlateEncode(null));
u3d_data_dict.putName("Subtype", "U3D");
cosAnnot.put("3DD", u3d_data_dict);
}
}
}
}
public static void main(String[] args) {
PDFNet.initialize();
try {
PDFDoc doc = new PDFDoc(("c:/myPdf.pdf"));
doc.initSecurityHandler();
AnnotationHighLevelAPI(doc);
doc.save(("c:/test.pdf"), SDFDoc.e_incremental, null);
} catch (Exception e) {
e.printStackTrace();
}
PDFNet.terminate();
}
---------------
A: Based on your sample code you are currently modifying (editing)
existing annotations on the page. So you are overwriting existing
annotations and converting them to U3D annotations.
In case you would simply like to add a new 3D annotation to a page,
please take a look at U3D sample project (http://www.pdftron.com/net/
samplecode.html#U3D). You can further extend Create3DAnnotation()
method to pass in the positioning and other information.