)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to add embed 3D file (u3D) in PDF Document

Platform: WPF |
Control: PDF |
Published Date: July 31, 2017 |
Last Revised Date: April 25, 2019

How to add embed 3D file (u3D) in PDF Document

3D Annotation

3D Annotation are used to represent 3D artworks in a PDF document. Creation of new Pdf3DAnnotation can be shown in below code snippet.

C#

//Creates a new PDF document.
PdfDocument document = new PdfDocument();
 
//Creates a new page
PdfPage page = document.Pages.Add();
 
//Creates a new pdf 3d annotation.
Pdf3DAnnotation pdf3dAnnotation = new Pdf3DAnnotation(new RectangleF(10, 50, 300, 150), @"3DAnnotation.U3D");
 
//Handles the activation of the 3d annotation
Pdf3DActivation activation = new Pdf3DActivation();
activation.ActivationMode = Pdf3DActivationMode.ExplicitActivation;
activation.ShowToolbar = true; pdf3dAnnotation.Activation = activation;
 
//Adds annotation to page
page.Annotations.Add(pdf3dAnnotation);

 

Pdf3DView

Represents an attribute to be applied to the virtual camera associated with a 3D annotation. It is used to create additional view to set the Background, Lighting and Rendering but either CameraToWorldMatrix or ViewNodeName must be specified.

C#

//Create a new Pdf3DView
Pdf3DView view = new Pdf3DView();
view.Background = background;
view.LightingScheme = lighting;
view.RenderMode = rendermode;
annotation.Views.Add(view);

 

CameraToWorldMatrix

A 12-element 3D transformation matrix that specifies a position and orientation of the camera in world coordinates. If the array has more than 12 elements, only the first 12 will be considered. We cannot set the C2W matrix automatically. We must provide the matrix value manually in the below format.

[left_x left_y left_z up_x up_y up_z view_x view_y view_z trans_x trans_y trans_z]

 

C#

//Create a new Pdf3DView
Pdf3DView view = new Pdf3DView();
view.CameraToWorldMatrix = new float[] { -0.382684f, 0.92388f, -0.0000000766026f, 0.18024f, 0.0746579f, 0.980785f, 0.906127f, 0.37533f, -0.19509f, -100, -112.432f, 45.6829f };

 

ViewNodeName

A sequence of one or more text strings used to access a view node within the 3D artwork. A View Node is a parameter in the 3D artwork that specifies the view. If both ViewNodeName and CameraToWorldMatrix are specified, then ViewNodeName takes precedence. If ViewNodeName is set to create additional view, Internal name of the Pdf3dView must be specified.

C#

//Create a new Pdf3DView
Pdf3DView view = new Pdf3DView(); 
view.InternalName = Guid.NewGuid().ToString("N");
 view.ViewNodeName = "Near View";

 

Features supported by Pdf3DView

Background:

C#

//Create a new Pdf3DBackground
Pdf3DBackground background = new Pdf3DBackground();
background.ApplyToEntireAnnotation = true;
background.Color = color;
 
//Create view with Background
view.Background = background;

 

Render Mode:

C#

//Create a new RenderMode
Pdf3DRendermode rendermode = new Pdf3DRendermode();
rendermode.Style = Pdf3DRenderStyle.Solid;
rendermode.AuxilaryColor = new PdfColor(System.Drawing.Color.Green);
rendermode.FaceColor = new PdfColor(System.Drawing.Color.Black);
PdfColor color = new PdfColor(System.Drawing.Color.Silver);
//Create view with RenderMode
view.RenderMode = rendermode;

 

Lighting:

C#

//Creates a new Pdf3DLighting
Pdf3DLighting lighting = new Pdf3DLighting();
lighting.Style = Pdf3DLightingStyle.CAD;
//Create view with Lighting
view.LightingScheme = lighting;

 

Insert an u3d into PDF document with Pdf3dView is shown in the below code snippet.

C#

//Create a new PDF document.
PdfDocument document = new PdfDocument ();
 
//Create a new page
PdfPage page = document.Pages.Add ();
 
//Create a new Pdf3DAnnotation.
Pdf3DAnnotation annotation = new Pdf3DAnnotation (new RectangleF(10, 50, 300, 150), @"..\..\Data\threeLevelHierarchy.u3d");
 
//Create a new Pdf3DRendermode
Pdf3DRendermode rendermode = new Pdf3DRendermode ();
rendermode.Style = Pdf3DRenderStyle.Solid;
rendermode.AuxilaryColor = new PdfColor(System.Drawing.Color.Green);
rendermode.FaceColor = new PdfColor(System.Drawing.Color.Black);
PdfColor color = new PdfColor(System.Drawing.Color.Silver);
 
//Create a new Pdf3DBackground
Pdf3DBackground background = new Pdf3DBackground ();
background.ApplyToEntireAnnotation = true;
background.Color = color;
 
//Creates a new Pdf3DLighting
Pdf3DLighting lighting = new Pdf3DLighting ();
lighting.Style = Pdf3DLightingStyle.CAD;
 
//Create a new Pdf3DView
Pdf3DView view = new Pdf3DView ();
view.ExternalName = "View";
view.Background = background;
view.LightingScheme = lighting;
view.RenderMode = rendermode;
view.InternalName = Guid.NewGuid().ToString("N");
view.ViewNodeName = "Near View";
annotation.Views.Add(view);
page.Annotations.Add(annotation);
 
//Save the document to disk.
document.Save("Sample.pdf");
 
//close the document
document.Close(true);

 

Sample Link :

http://www.syncfusion.com/downloads/support/forum/131363/ze/Sample360240407.zip

 

2X faster development

The ultimate WPF UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon