Esempio n. 1
0
        static void Main(string[] args)
        {
            // Create the pdf document
            //PDF4NET v5: PDFDocument doc = new PDFDocument();
            PDFFixedDocument doc = new PDFFixedDocument();

            // Create a blank page
            //PDF4NET v5: PDFPage page = doc.AddPage();
            PDFPage page = doc.Pages.Add();

            // Create the annotation that will display the 3D artwork.
            PDF3DAnnotation annot3d = new PDF3DAnnotation();

            // Add the annotation to the page.
            page.Annotations.Add(annot3d);

            //PDF4NET v5: annot3d.Rectangle = new RectangleF(50, 50, 400, 400);
            annot3d.DisplayRectangle = new PDFDisplayRectangle(50, 50, 400, 400);

            annot3d.Stream = Create3DStream();

            //PDF4NET v5: annot3d.Appearance = new PDFAnnotationAppearance();
            annot3d.NormalAppearance = new PDFAnnotationAppearance(annot3d.DisplayRectangle.Width, annot3d.DisplayRectangle.Height);

            //PDF4NET v5: annot3d.Appearance.Canvas.DrawText("Click to activate", new PDFFont(),
            //                null, new PDFBrush(new PDFRgbColor()), 200, 200, 0, PDFTextAlign.MiddleCenter);
            PDFStringLayoutOptions slo = new PDFStringLayoutOptions();

            slo.X = 200;
            slo.Y = 200;
            slo.HorizontalAlign = PDFStringHorizontalAlign.Center;
            slo.VerticalAlign   = PDFStringVerticalAlign.Middle;
            PDFStringAppearanceOptions sao = new PDFStringAppearanceOptions();

            sao.Font  = new PDFStandardFont(PDFStandardFontFace.Helvetica, 10);
            sao.Brush = new PDFBrush(PDFRgbColor.Black);
            annot3d.NormalAppearance.Canvas.DrawString("Click to activate", sao, slo);

            // Create the default view.
            //PDF4NET v5: PDF3DProjection projection1 = new PDF3DProjection(PDF3DProjectionType.Perspective);
            PDF3DProjection projection1 = new PDF3DProjection()
            {
                Type = PDF3DProjectionType.Perspective
            };

            projection1.FieldOfView = 30;
            PDF3DLightingScheme lightScheme1 = null;
            //PDF4NET v5: PDF3DRenderMode renderMode1 = new PDF3DRenderMode(PDF3DRenderStyle.Solid);
            PDF3DRenderMode renderMode1 = new PDF3DRenderMode()
            {
                Mode = PDF3DRenderModeType.Solid
            };

            //PDF4NET v5: PDF3DBackground background1 = new PDF3DBackground(new PDFRgbColor(255, 255, 255));
            PDF3DBackground background1 = new PDF3DBackground()
            {
                Color = PDFRgbColor.White
            };

            PDF3DView defaultView = CreateView("Default view",
                                               new double[] { -0.382684f, 0.92388f, -0.0000000766026f, 0.18024f, 0.0746579f, 0.980785f, 0.906127f, 0.37533f, -0.19509f, -122.669f, -112.432f, 45.6829f },
                                               131.695f, background1, projection1, renderMode1, lightScheme1);

            // Create a wireframe view.
            //PDF4NET v5: PDF3DRenderMode renderMode2 = new PDF3DRenderMode(PDF3DRenderStyle.Wireframe);
            PDF3DRenderMode renderMode2 = new PDF3DRenderMode()
            {
                Mode = PDF3DRenderModeType.Wireframe
            };

            PDF3DView wireframeView = CreateView("Wireframe view",
                                                 new double[] { -0.382684f, 0.92388f, -0.0000000766026f, 0.18024f, 0.0746579f, 0.980785f, 0.906127f, 0.37533f, -0.19509f, -122.669f, -112.432f, 45.6829f },
                                                 131.695f, background1, projection1, renderMode2, lightScheme1);

            // Create a transparent wireframe view.
            //PDF4NET v5: PDF3DRenderMode renderMode3 = new PDF3DRenderMode(PDF3DRenderStyle.TransparentWireframe);
            PDF3DRenderMode renderMode3 = new PDF3DRenderMode()
            {
                Mode = PDF3DRenderModeType.TransparentWireframe
            };

            renderMode3.AuxiliaryColor = new PDFRgbColor(0, 192, 0);
            PDF3DView transparentWireframeView = CreateView("Transparent wireframe view",
                                                            new double[] { -0.382684f, 0.92388f, -0.0000000766026f, 0.18024f, 0.0746579f, 0.980785f, 0.906127f, 0.37533f, -0.19509f, -122.669f, -112.432f, 45.6829f },
                                                            131.695f, background1, projection1, renderMode3, lightScheme1);

            annot3d.Stream.Views.Add(defaultView);
            annot3d.Stream.Views.Add(wireframeView);
            annot3d.Stream.Views.Add(transparentWireframeView);
            //PDF4NET v5: annot3d.Stream.DefaultView = 0;
            annot3d.Stream.DefaultView = defaultView;

            doc.Save("Sample_3D.pdf");
        }
Esempio n. 2
0
        private static void Create3DAnnotations(PDFFixedDocument document, PDFFont font, Stream u3dStream)
        {
            PDFBrush blackBrush = new PDFBrush();

            PDFPage page = document.Pages.Add();

            page.Rotation = 90;

            page.Canvas.DrawString("3D annotations", font, blackBrush, 50, 50);

            byte[] u3dContent = new byte[u3dStream.Length];
            u3dStream.Read(u3dContent, 0, u3dContent.Length);

            PDF3DView view0 = new PDF3DView();

            view0.CameraToWorldMatrix    = new double[] { 1, 0, 0, 0, 0, -1, 0, 1, 0, -0.417542, -0.881257, -0.125705 };
            view0.CenterOfOrbit          = 0.123106;
            view0.ExternalName           = "Default";
            view0.InternalName           = "Default";
            view0.Projection             = new PDF3DProjection();
            view0.Projection.FieldOfView = 30;

            PDF3DView view1 = new PDF3DView();

            view1.CameraToWorldMatrix    = new double[] { -0.999888, 0.014949, 0, 0.014949, 0.999887, 0.00157084, 0.0000234825, 0.00157066, -0.999999, -0.416654, -0.761122, -0.00184508 };
            view1.CenterOfOrbit          = 0.123106;
            view1.ExternalName           = "Top";
            view1.InternalName           = "Top";
            view1.Projection             = new PDF3DProjection();
            view1.Projection.FieldOfView = 14.8096;

            PDF3DView view2 = new PDF3DView();

            view2.CameraToWorldMatrix    = new double[] { -1.0, -0.0000411671, 0.0000000000509201, -0.00000101387, 0.0246288, 0.999697, -0.0000411546, 0.999697, -0.0246288, -0.417072, -0.881787, -0.121915 };
            view2.CenterOfOrbit          = 0.123106;
            view2.ExternalName           = "Side";
            view2.InternalName           = "Side";
            view2.Projection             = new PDF3DProjection();
            view2.Projection.FieldOfView = 12.3794;

            PDF3DView view3 = new PDF3DView();

            view3.CameraToWorldMatrix    = new double[] { -0.797002, -0.603977, -0.0000000438577, -0.294384, 0.388467, 0.873173, -0.527376, 0.695921, -0.48741, -0.3518, -0.844506, -0.0675629 };
            view3.CenterOfOrbit          = 0.123106;
            view3.ExternalName           = "Isometric";
            view3.InternalName           = "Isometric";
            view3.Projection             = new PDF3DProjection();
            view3.Projection.FieldOfView = 15.1226;

            PDF3DView view4 = new PDF3DView();

            view4.CameraToWorldMatrix    = new double[] { 0.00737633, -0.999973, -0.0000000000147744, -0.0656414, -0.000484206, 0.997843, -0.997816, -0.00736042, -0.0656432, -0.293887, -0.757928, -0.119485 };
            view4.CenterOfOrbit          = 0.123106;
            view4.ExternalName           = "Front";
            view4.InternalName           = "Front";
            view4.Projection             = new PDF3DProjection();
            view4.Projection.FieldOfView = 15.1226;

            PDF3DView view5 = new PDF3DView();

            view5.CameraToWorldMatrix    = new double[] { 0.0151008, 0.999886, 0.0000000000261366, 0.0492408, -0.000743662, 0.998787, 0.998673, -0.0150825, -0.0492464, -0.540019, -0.756862, -0.118884 };
            view5.CenterOfOrbit          = 0.123106;
            view5.ExternalName           = "Back";
            view5.InternalName           = "Back";
            view5.Projection             = new PDF3DProjection();
            view5.Projection.FieldOfView = 12.3794;

            PDF3DStream _3dStream = new PDF3DStream();

            _3dStream.Views.Add(view0);
            _3dStream.Views.Add(view1);
            _3dStream.Views.Add(view2);
            _3dStream.Views.Add(view3);
            _3dStream.Views.Add(view4);
            _3dStream.Views.Add(view5);
            _3dStream.Content          = u3dContent;
            _3dStream.DefaultViewIndex = 0;
            PDF3DAnnotation _3da = new PDF3DAnnotation();

            _3da.Stream = _3dStream;

            PDFAnnotationAppearance appearance = new PDFAnnotationAppearance(200, 200);

            appearance.Canvas.DrawString("Click to activate", font, blackBrush, 50, 50);
            _3da.NormalAppearance = appearance;

            page.Annotations.Add(_3da);
            _3da.DisplayRectangle = new PDFDisplayRectangle(36, 36, 720, 540);

            PDFStringAppearanceOptions sao = new PDFStringAppearanceOptions();

            sao.Font  = font;
            sao.Brush = blackBrush;
            PDFStringLayoutOptions slo = new PDFStringLayoutOptions();

            slo.Y = 585 + 18 / 2;
            slo.HorizontalAlign = PDFStringHorizontalAlign.Center;
            slo.VerticalAlign   = PDFStringVerticalAlign.Middle;

            PDFPen blackPen = new PDFPen(new PDFRgbColor(0, 0, 0), 1);

            page.Canvas.DrawRectangle(blackPen, 50, 585, 120, 18);
            slo.X = 50 + 120 / 2;
            page.Canvas.DrawString("Top", sao, slo);

            PDFGoTo3DViewAction gotoTopView = new PDFGoTo3DViewAction();

            gotoTopView.ViewIndex        = 1;
            gotoTopView.TargetAnnotation = _3da;
            PDFLinkAnnotation linkGotoTopView = new PDFLinkAnnotation();

            page.Annotations.Add(linkGotoTopView);
            linkGotoTopView.DisplayRectangle = new PDFDisplayRectangle(50, 585, 120, 18);
            linkGotoTopView.Action           = gotoTopView;

            page.Canvas.DrawRectangle(blackPen, 190, 585, 120, 18);
            slo.X = 190 + 120 / 2;
            page.Canvas.DrawString("Side", sao, slo);

            PDFGoTo3DViewAction gotoSideView = new PDFGoTo3DViewAction();

            gotoSideView.ViewIndex        = 2;
            gotoSideView.TargetAnnotation = _3da;
            PDFLinkAnnotation linkGotoSideView = new PDFLinkAnnotation();

            page.Annotations.Add(linkGotoSideView);
            linkGotoSideView.DisplayRectangle = new PDFDisplayRectangle(190, 585, 120, 18);
            linkGotoSideView.Action           = gotoSideView;

            page.Canvas.DrawRectangle(blackPen, 330, 585, 120, 18);
            slo.X = 330 + 120 / 2;
            page.Canvas.DrawString("Isometric", sao, slo);

            PDFGoTo3DViewAction gotoIsometricView = new PDFGoTo3DViewAction();

            gotoIsometricView.ViewIndex        = 3;
            gotoIsometricView.TargetAnnotation = _3da;
            PDFLinkAnnotation linkGotoIsometricView = new PDFLinkAnnotation();

            page.Annotations.Add(linkGotoIsometricView);
            linkGotoIsometricView.DisplayRectangle = new PDFDisplayRectangle(330, 585, 120, 18);
            linkGotoIsometricView.Action           = gotoIsometricView;

            page.Canvas.DrawRectangle(blackPen, 470, 585, 120, 18);
            slo.X = 470 + 120 / 2;
            page.Canvas.DrawString("Front", sao, slo);

            PDFGoTo3DViewAction gotoFrontView = new PDFGoTo3DViewAction();

            gotoFrontView.ViewIndex        = 4;
            gotoFrontView.TargetAnnotation = _3da;
            PDFLinkAnnotation linkGotoFrontView = new PDFLinkAnnotation();

            page.Annotations.Add(linkGotoFrontView);
            linkGotoFrontView.DisplayRectangle = new PDFDisplayRectangle(470, 585, 120, 18);
            linkGotoFrontView.Action           = gotoFrontView;

            page.Canvas.DrawRectangle(blackPen, 610, 585, 120, 18);
            slo.X = 610 + 120 / 2;
            page.Canvas.DrawString("Back", sao, slo);

            PDFGoTo3DViewAction gotoBackView = new PDFGoTo3DViewAction();

            gotoBackView.ViewIndex        = 5;
            gotoBackView.TargetAnnotation = _3da;
            PDFLinkAnnotation linkGotoBackView = new PDFLinkAnnotation();

            page.Annotations.Add(linkGotoBackView);
            linkGotoBackView.DisplayRectangle = new PDFDisplayRectangle(610, 585, 120, 18);
            linkGotoBackView.Action           = gotoBackView;
        }