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: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to embed 3D files in PDF document?

 

Essential PDF supports to embed the collections of three-dimensional objects, such as those used by CAD software, to be embedded in PDF files with the help of the Pdf3DAnnotation class.

C#

//Pdf 3D Annotation

Pdf3DAnnotation annot = new Pdf3DAnnotation(new RectangleF(10, 70, 150, 150), @"..\..\Data\AQuick Example.u3d");

//Create font, font style and brush

Font f = new Font("Calibri", 11, FontStyle.Regular);

PdfFont font = new PdfTrueTypeFont(f, false);

PdfBrush brush = new PdfSolidBrush(Color.DarkBlue);

PdfBrush bgbrush = new PdfSolidBrush(Color.WhiteSmoke);

PdfColor color = new PdfColor(Color.Thistle);

page.Graphics.DrawRectangle(bgbrush, new RectangleF(10, 270, 150, 150));

// Pdf 3D Apperance

annot.Appearance = new PdfAppearance(annot);

annot.Appearance.Normal.Graphics.DrawString("Click to activate", font, brush, new PointF(40, 40));

annot.Appearance.Normal.Draw(page, new PointF(annot.Location.X, annot.Location.Y));

 Pdf3DProjection projection = new Pdf3DProjection();

projection.ProjectionType = Pdf3DProjectionType.Perspective;

 projection.FieldOfView = 10;

projection.ClipStyle = Pdf3DProjectionClipStyle.ExplicitNearFar;

projection.NearClipDistance = 10;

Pdf3DActivation activation = new Pdf3DActivation();

activation.ActivationMode = Pdf3DActivationMode.ExplicitActivation;

activation.ShowToolbar = false;

annot.Activation = activation;

Pdf3DBackground background = new Pdf3DBackground();

background.Color = color;

Pdf3DRendermode rendermode = new Pdf3DRendermode();

rendermode.Style = Pdf3DRenderStyle.Solid;

Pdf3DLighting lighting = new Pdf3DLighting();

lighting.Style = Pdf3DLightingStyle.Headlamp;

// Create the default view.

Pdf3DProjection projection1 = new Pdf3DProjection(Pdf3DProjectionType.Perspective);

projection1.FieldOfView = 50;

projection1.ClipStyle = Pdf3DProjectionClipStyle.ExplicitNearFar;

projection1.NearClipDistance = 10;

Pdf3DView defaultView = CreateView("Default View", new float[] { 3.25647f, 1.256987f, -5.66026f, 1.18024f, 1.76479f, 1.056785f, 8.906127f, 2.7353f, -1.09509f, -122.669f, -112.432f, 48.2459f }, 131.569f, background, projection, rendermode, lighting);

annot.Views.Add(defaultView);

//Add the pdf Annotation

page.Annotations.Add(annot);

VB

''Pdf 3D Annotation

Dim annot As Pdf3DAnnotation = New Pdf3DAnnotation(New RectangleF(10, 70, 150, 150), "..\..\Data\AQuick Example.u3d")

''Create font, font style and brush

Dim f As Font = New Font("Calibri", 11, FontStyle.Regular)

Dim font As PdfFont = New PdfTrueTypeFont(f, False)

Dim brush As PdfBrush = New PdfSolidBrush(Color.DarkBlue)

Dim bgbrush As PdfBrush = New PdfSolidBrush(Color.WhiteSmoke)

Dim color As PdfColor = New PdfColor(Color.Thistle)

page.Graphics.DrawRectangle(bgbrush, New RectangleF(10, 270, 150, 150))

'' Pdf 3D Apperance

annot.Appearance = New PdfAppearance(annot)

annot.Appearance.Normal.Graphics.DrawString("Click to activate", font, brush, New PointF(40, 40))

annot.Appearance.Normal.Draw(page, New PointF(annot.Location.X, annot.Location.Y))

Dim projection As Pdf3DProjection = New Pdf3DProjection()

projection.ProjectionType = Pdf3DProjectionType.Perspective

projection.FieldOfView = 10

projection.ClipStyle = Pdf3DProjectionClipStyle.ExplicitNearFar

projection.NearClipDistance = 10

Dim activation As Pdf3DActivation = New Pdf3DActivation()

activation.ActivationMode = Pdf3DActivationMode.ExplicitActivation

activation.ShowToolbar = False

annot.Activation = activation

Dim background As Pdf3DBackground = New Pdf3DBackground()

background.Color = color

Dim rendermode As Pdf3DRendermode = New Pdf3DRendermode()

rendermode.Style = Pdf3DRenderStyle.Solid

Dim lighting As Pdf3DLighting = New Pdf3DLighting()

lighting.Style = Pdf3DLightingStyle.Headlamp

'' Create the default view.

Dim projection1 As Pdf3DProjection = New Pdf3DProjection(Pdf3DProjectionType.Perspective)

projection1.FieldOfView = 50

projection1.ClipStyle = Pdf3DProjectionClipStyle.ExplicitNearFar

projection1.NearClipDistance = 10

 Dim defaultView As Pdf3DView = CreateView("Default View", New Single() { 3.25647f, 1.256987f, -5.66026f, 1.18024f, 1.76479f, 1.056785f, 8.906127f, 2.7353f, -1.09509f, -122.669f, -112.432f, 48.2459f }, 131.569f, background, projection, rendermode, lighting)

annot.Views.Add(defaultView)

''Add the pdf Annotation

page.Annotations.Add(annot)

Please do find the simple sample from the below location .

http://www.syncfusion.com/support/user/uploads/Sample_6ff1693a.zip

Article ID: Published Date: Last Revised Date: Platform: Control:
886 04/30/2011 07/10/2014 WinForms PDF
Tags:
Did you find this information helpful?
Comments
Pushpendra Kataria Jun 24, 2017

can you please tell the property setting for orthographic projection

Reply
Pushpendra Kataria Jun 24, 2017

hello, can you please tell me how to set orthographic projection of 3d annotation in a pdf. i mean what are the properties value like clipstyle, farclipdistance, fieldview etc. to be define to get an orthographic projection. Actually i am a beginner so please help me.

Reply
Praveenkumar H [Syncfusion] Jun 27, 2017

Hi Pushpendra,

Please find the code snippet to set the orthographic projection.

           //Create a new PDF document.

            PdfDocument document = new PdfDocument();

            //Create a new page .

            PdfPage page = document.Pages.Add();

            //Create a new rectangle

            RectangleF rectangle = new RectangleF(10, 40, 30, 30);

            //Create a new Pdf3DAnnotation.

            Pdf3DAnnotation annotation = new Pdf3DAnnotation(new RectangleF(10, 50, 300, 150), @"../../Data/GetSubgraphBound.u3d");

           

            //Create a new Pdf3DProjection with orthographic.

            Pdf3DProjection projection = new Pdf3DProjection();

            projection.ProjectionType = Pdf3DProjectionType.Orthographic;          

            projection.FieldOfView = 10;

            projection.OrthoScaleMode = Pdf3DProjectionOrthoScaleMode.Width;

            projection.ClipStyle = Pdf3DProjectionClipStyle.ExplicitNearFar;

            projection.NearClipDistance = 10;

            //Create a new Pdf3DView

            Pdf3DView view = new Pdf3DView();

            view.ViewNodeName = "Near View";

            view.Projection = projection;

            view.InternalName= view.InternalName = Guid.NewGuid().ToString("N");

            annotation.Views.Add(view);

            //Adds the annotation in a new page.

            page.Annotations.Add(annotation);

            //Save the document to disk.

            document.Save("Output.pdf");

            //close the document

            document.Close(true);

Please let me know if you have any doubt in this.

Pushpendra Kataria Jul 03, 2017

thanks for your reply,

but still i m facing problem, after opening the pdf we still have to click on use Orthographic Projection. By default it is showing perspective, i want it to be orthographic as we open the the pdf file.


Reply
Pushpendra Kataria Jul 04, 2017

this is what i am doing

 //Create a new PDF document.

            Syncfusion.Pdf.PdfDocument document = new Syncfusion.Pdf.PdfDocument();

            //document.PageSettings.Size = PdfPageSize.A3;

            document.PageSettings.Size = new SizeF(1190, 842);

            document.PageSettings.Orientation = PdfPageOrientation.Landscape;

            //Create Margin Object

            PdfMargins margin = new PdfMargins();

            //Set All side border

            margin.All = 5;

            //Set margin to PDf Page

            document.PageSettings.Margins = margin;

            //Create a new page .

            Syncfusion.Pdf.PdfPage page = document.Pages.Add();

//Create a new Pdf3DAnnotation.

            Pdf3DAnnotation annotation = new Pdf3DAnnotation(new RectangleF(10, 47, 1160, 601), @"C:\Users\home\Desktop\u3d\Assem1_table.u3d");

            PdfColor color = new PdfColor(Color.Transparent);

            //Create a new Pdf3DBackground

            Pdf3DBackground background = new Pdf3DBackground(color);

            background.ApplyToEntireAnnotation = true;

            // Activating 3D pdf

            Pdf3DActivation activation = new Pdf3DActivation();

            activation.ActivationMode = Pdf3DActivationMode.PageOpen;

            activation.ShowToolbar = false;

            annotation.Activation = activation;


            //Create a new Pdf3DProjection.

            Pdf3DProjection projection = new Pdf3DProjection();

             projection.ProjectionType = Pdf3DProjectionType.Orthographic;

             projection.FieldOfView = 10;

             projection.OrthoScaleMode = Pdf3DProjectionOrthoScaleMode.Width;

             projection.ClipStyle = Pdf3DProjectionClipStyle.ExplicitNearFar;

             projection.NearClipDistance = 10;


            


            //Create a new Pdf3DRendermode.

            Pdf3DRendermode renderMode = new Pdf3DRendermode();

            renderMode.Style = Pdf3DRenderStyle.SolidOutline;

            renderMode.AuxilaryColor = new PdfColor(Color.Black);

            renderMode.FaceColor = new PdfColor(Color.Black);

            renderMode.CreaseValue = 90f;


            // Create Lighting

            Pdf3DLighting lighting = new Pdf3DLighting();

            lighting.Style = Pdf3DLightingStyle.White;

#region Front View

            Pdf3DView view = new Pdf3DView();

            float[] matrix = new float[] { -1f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, -1f, 0.053185f, 0.0865646f, 0.376491f };

            view.CameraToWorldMatrix = matrix;

            view.CenterOfOrbit = 0.268659f;

            view.Background = background;

            view.ExternalName = "Front View";

           // view.ViewNodeName = "Front View";

            view.InternalName = view.InternalName = Guid.NewGuid().ToString("N");

            view.RenderMode = renderMode;

            view.LightingScheme = lighting;

            view.Projection = projection;

            annotation.Views.Add(view);

            #endregion

//Save the document to disk.

            document.Save(@"C:\Users\home\Desktop\u3d\Output-3D PDF.pdf");

            //close the document

            document.Close(true);

Reply
Add Comment
You must log in to leave a comment

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