Planet PDF Forum Archive

Planet PDF  ForumThe page you are viewing is part of our 160,000 page discussion forum archive. See below for PDF-related discussions spanning 1999-2008. To ask questions and get help, head to the live Planet PDF Forum.


How to search this archive. The quickest way is to use the filters on our Advanced Search page so that only archive pages are included in the results.


Previous | Next | (P-PDF) Engineering


Topic: iText 3D PDF and JavaScript
Conf: (P-PDF) Engineering, Msg: 160606
From: aheckmeier
Date: 6/11/2007 12:36 AM

Hello,

I've added a 3D modell to an existing PDF with iText. When i add a Script like "host.getField("testField").value = clickedMesh.name;", i get the error message "host is undefined".

If i add the 3D modell and script manually, it works fine ...

Any clue?
Thanks in advance!


Toni




Here is the code of iTexte:


public class PDF3DObject extends PdfAnnotation
{
// See also PDF reference 1.6 (Page 757)
public static final String PDF_NAMESAPCE = "iTextSharp.text.pdf.";
public static final String PDF_NAME_3D = "3D";
public static final String PDF_NAME_3DD = "3DD";
public static final String PDF_NAME_3DV = "3DV";
public static final String PDF_NAME_3DVIEW = "3DView";
public static final String PDF_NAME_C2W = "C2W"; // Transformation matrix (optional)
public static final String PDF_NAME_IN = "IN"; // internal name of the view (optional)
public static final String PDF_NAME_MS = "MS"; //
public static final String PDF_NAME_XN = "XN"; // The external name of the view (required)

public static final String PDF_NAME_U3D = "U3D";
public static final String PDF_NAME_U3DPATH = "U3DPath";


/**
*
* @param writer PdfWriter
* @param u3dFile File
* @param previewImage File
* @param rectangle Rectangle
*/
public PDF3DObject(PdfStamper stamper, File u3dFile, Rectangle rectangle, int page)
{
super(stamper.getWriter(), rectangle);

try
{
PdfWriter writer = stamper.getWriter();

PdfIndirectReference streamRef;
PdfIndirectObject objRef;

PdfContentByte cb = stamper.getOverContent(page);

// Create stream to carry attachment
FileInputStream fistrm = new FileInputStream(u3dFile);
PdfStream stream = new PdfStream(fistrm, writer);

// Mandatory keys
stream.put(PdfName.TYPE, new PdfName(PDF_NAME_3D));
stream.put(PdfName.SUBTYPE, new PdfName(PDF_NAME_U3D));
stream.flateCompress();

// Write stream contents, get reference to stream object, write actual stream length
streamRef = writer.addToBody(stream, false).getIndirectReference();
stream.writeLength();

// Create 3D view dictionary
// PDF documentation states that this can be left out, but without normally we will just get a blank
// 3D image because of wrong coordinate space transformations, etc.
// Instead of providing camera-to-world transformation here, we could also reference view in U3D file itself
// (would be U3DPath key instead of C2W key, U3D value instead of M value for MS key), but i haven't tried
// up to now
// We could also provide an activation dictionary (defining activation behavior), and field-of-view for
// P entry if needed
PdfDictionary dict = new PdfDictionary(new PdfName(PDF_NAME_3DVIEW));

dict.put(new PdfName(PDF_NAME_XN), new PdfString("DefaultView"));
dict.put(new PdfName(PDF_NAME_IN), new PdfString("Unnamed"));

dict.put(new PdfName(PDF3DObject.PDF_NAME_MS), new PdfName(PDF3DObject.PDF_NAME_U3D));

// NOTE: The initial release of Acrobat 7.0 does not correctly display the default view in the U3D data.
// This behavior is expected to be corrected in future releases and hence.
dict.put(new PdfName(PDF3DObject.PDF_NAME_U3DPATH), new PdfString("DefaultView"));

// Write view dictionary, get reference
objRef = writer.addToBody(dict, false);

//
// Create appearance
PdfAppearance ap = cb.createAppearance(rectangle.width(), rectangle.height());
ap.setBoundingBox(rectangle);


put(PdfName.CONTENTS, new PdfString("3D Model"));

// Mandatory keys
put(PdfName.SUBTYPE, new PdfName(PDF_NAME_3D));
put(PdfName.TYPE, PdfName.ANNOT);

// Reference to stream object
put(new PdfName(PDF_NAME_3DD), streamRef);

// Reference to view dictionary object
put(new PdfName(PDF_NAME_3DV), objRef.getIndirectReference());

// Assign appearance and page
setAppearance(PdfAnnotation.APPEARANCE_NORMAL, ap);
}
catch (IOException ex)
{
Debug.error("Internal Error: ", ex);
}
}
}


PDF In-Depth Free Product Trials Ubiquitous PDF

Pitstop Pro

Now graphic arts professionals have even broader and more expert control over their PDF documents. With...

Download free demo

ARTS PDF Aerialist

The ultimate plug-in for Adobe Acrobat and #1 selling product at PDF Store. Advanced splitting, merging,...

Download free demo

Ubiquitous PDF: 2009 IRS income tax forms available for download

With less than a month to go until Americans will be scrambling to file their 2009 tax paperwork. Luckily, printable PDF versions of forms such as the 1040 can be downloaded for free from the IRS website.

March 18, 2010
Search Planet PDF
more searching options...







Download PDF Creator

PDF Resources
Platinum Sponsor
Create & Edit PDF - Nitro PDF Software

ARTS PDF

Silver Sponsors

PDF-Tools QuickPDF: The Unrivaled PDF Developer Toolkit

Get Nitro PDF Professional
Featured Product

NITRO PDF Professional

Built from the ground up, the perfect desktop PDF product for business and enterprise. Nitro PDF Professional has an uncompromising feature set so you can create, combine, edit, collaborate on and...

Featured Event

No upcoming events

PDF Store Categories