How to add embed 3D file (u3D) in PDF Document?
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 :
https://www.syncfusion.com/downloads/support/forum/131363/ze/Sample360240407.zip
Note:
Starting with v16.2.0.x, if you reference Syncfusion® assemblies from the trial setup or the NuGet feed, include a license key in your projects. Refer to the link to learn about generating and registering the Syncfusion® license key in your application to use the components without a trial message.
Conclusion:
I hope you enjoyed learning about how to add embed 3D file (u3D) in PDF Document.
You can refer to our Flutter PDF feature tour page to learn about its other groundbreaking features and documentation, and how to quickly get started with configuration specifications. You can also explore our Flutter PDF Flutter PDF examples to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to explore our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums or feedback portal. We are always happy to assist you!