Creating Advanced 3D PDF files using the Datalogics PDF Java Toolkit

Creating Advanced 3D PDF files using the Datalogics PDF Java Toolkit

Sample of the Week:

Almost immediately after posting my last article on working with 3D PDF files, I heard from a developer that wanted to know how to programmatically create some of the more advanced types of views that Acrobat is capable of making. Specifically, they were looking for the ability to hide certain parts in a view and create cross sections. This Gist builds on that earlier article so you may want to go back and review it first. This article also assumes you are already familiar with 3D PDF.

What You Need to Know First:

In addition to the Projection Dictionary, the camera position, each “View” in a 3D PDF file can have additional dictionaries that can be used to set a background color specific to that view, change the render mode of the entire model for that view, set a lighting scheme specific to that view and turn on the cutting plane for cross sections. These dictionaries control the settings for the entire model. But in addition to these, the Node Dictionary can be used to specify particular areas of the 3D model and the opacity and visibility with which individual nodes are displayed.

The previous article discussed how to create views and add them to the view array. This article discusses adding two additional views, one that will change the location and visibility of a node and one that adds a cross section. Again, the numbers used in this Gist are specific to the model specified in the input files, the matrix numbers that you use for your model will be different.

Shifting Nodes and Changing Opacity in a View:

To create a view where we shift the location of a node as well as it’s children and change it’s opacity, we need to create a view in much the same was as we did in the previous article.

BreakModelTreeThen we need to create a PDF3DNode Object for each node that we want the view to treat differently from the main model. When creating it, we need to know the field Node block name, as described in the U3D or PRC specification. It’s the same name that is shown in the 3D model window in Acrobat. We can also set the opacity, visibility, and a matrix that specifies the position and orientation of this node, relative to its parent, in world coordinates.



Now we can create a PDF3DNodeArray and add our nodes to it then add the view to the views array.

Adding a Cross Section View:

For a cross section view, we need to construct a Cross Section Dictionary. In this case, I want to simply add a cutting plane to an existing view so I’ll clone the default view that I created earlier in the Gist.

Then we create a cross section. The array that gets passed in is the Orientation key, a three-element array specifying the orientation of the cutting plane in world space. Each value represents the orientation in relation to the X, Y, and Z axes, respectively (see 13.6.5, “Coordinate Systems for 3D”). Exactly one of the values must be null, indicating an initial state of the cutting plane that is perpendicular to the corresponding axis and clipping all geometry on the positive side of that axis. The other two values are numbers indicating the rotation of the plane, in degrees, around their corresponding axes. The order in which these rotations are applied matches the order in which the values appear in the array. Then we set the offset of the plane to be just slightly below the center on the z axis. Finally we set the colors to ones that match what Acrobat creates. This part is optional; the defaults look just as good.

We can now create the Cross Section array, add our cross section to it, and add the view to the views array.

To get started with 3D PDF files, download this Gist and request an evaluation copy of The Datalogics PDF Java Toolkit.

2 thoughts on “Creating Advanced 3D PDF files using the Datalogics PDF Java Toolkit

  1. Hi Joel Geraci,
    We have a requirement to convert cad file to 3d pdf and display in browser.
    Is there any way to convert cad file to 3d pdf using datalogics pdf java toolkit.
    Thanks in advance.

    1. Poornachandar:

      The Datalogics PDF Java Toolkit can play a role in converting CAD files to 3D PDF but it can’t do it all by itself. You’d need another library or tool to convert from the source CAD file to either U3D or PRC. Then you can use these formats as input to the Java Toolkit when creating your PDF. You can either start with a 3D PDF template and just insert your new 3D model or you can create a new one from scratch.

Leave a Reply

Your email address will not be published.