Exemplo n.º 1
0
        // This sample shows how to work with shapes.
        public static void Shapes()
        {
            string pictPath     = @"..\..\..\..\..\..\Testing Files\image1.jpg";
            string documentPath = @"Shapes.docx";

            // Let's create a new document.
            DocumentCore dc = new DocumentCore();

            // Create shape 1 with fill and outline.
            Shape shp1 = new Shape(dc, Layout.Floating(
                                       new HorizontalPosition(25f, LengthUnit.Millimeter, HorizontalPositionAnchor.LeftMargin),
                                       new VerticalPosition(20f, LengthUnit.Millimeter, VerticalPositionAnchor.TopMargin),
                                       new Size(200, 100)
                                       ));

            // Specify outline and fill using a picture.
            shp1.Outline.Fill.SetSolid(Color.DarkGreen);
            shp1.Outline.Width = 2;

            // Set fill for this shape.
            shp1.Fill.SetSolid(Color.Orange);

            // Create shape 2 with some text inside, 100mm*20mm.
            Shape shp2 = new Shape(dc, Layout.Floating(
                                       new HorizontalPosition(100f, LengthUnit.Millimeter, HorizontalPositionAnchor.LeftMargin),
                                       new VerticalPosition(20f, LengthUnit.Millimeter, VerticalPositionAnchor.TopMargin),
                                       new Size(LengthUnitConverter.Convert(100f, LengthUnit.Millimeter, LengthUnit.Point),
                                                LengthUnitConverter.Convert(20f, LengthUnit.Millimeter, LengthUnit.Point))
                                       ));

            // Specify outline and fill using a picture.
            shp2.Outline.Fill.SetSolid(Color.LightGray);
            shp2.Outline.Width = 0.5;

            // Create a new paragraph with a formatted text.
            Paragraph p    = new Paragraph(dc);
            Run       run1 = new Run(dc, "Welcome to International Software Developer conference!");

            run1.CharacterFormat.FontName = "Helvetica";
            run1.CharacterFormat.Size     = 14f;
            run1.CharacterFormat.Italic   = true;
            p.Inlines.Add(run1);

            // Add the paragraph into the shp2.Text property.
            shp2.Text.Blocks.Add(p);

            // Add our shapes into the document.
            dc.Content.End.Insert(shp1.Content);
            dc.Content.End.Insert(shp2.Content);

            // Save the document to DOCX format.
            dc.Save(documentPath);

            // Open the result for demonstation purposes.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(documentPath)
            {
                UseShellExecute = true
            });
        }
Exemplo n.º 2
0
        /// Load an existing document (*.docx, *.rtf, *.pdf, *.html, *.txt, *.pdf) and save it in a PDF document with the digital signature.
        public static void DigitalSignature()
        {
            // Path to a loadable document.
            string loadPath = @"C:\Users\admin\Desktop\Test\Test\Test.pdf";

            DocumentCore dc = DocumentCore.Load(loadPath);

            // Signature line added with MS Word -> Insert tab -> Signature Line button by default has description 'Microsoft Office Signature Line...'.
            ShapeBase signatureLine = dc.GetChildElements(true).OfType <ShapeBase>().FirstOrDefault();

            // This picture symbolizes a handwritten signature
            Picture signature = new Picture(dc, "C:\\Users\\admin\\Desktop\\Test\\Test\\signature.png");

            // Signature in this document will be 4.5 cm right of TopLeft position of signature line
            // and 4.5 cm below of TopLeft position of signature line.
            signature.Layout = Layout.Floating(
                new HorizontalPosition(4.5, LengthUnit.Centimeter, HorizontalPositionAnchor.Page),
                new VerticalPosition(-4.5, LengthUnit.Centimeter, VerticalPositionAnchor.Page),
                signature.Layout.Size);

            dc.Sections.Last().Blocks.Add(
                new Paragraph(dc, signature));

            //signature.Layout = Layout.Inline(signature.Layout.Size);
            PdfSaveOptions options = new PdfSaveOptions();

            // Path to the certificate (*.pfx).
            options.DigitalSignature.CertificatePath = "C:\\Users\\admin\\Desktop\\Test\\Test\\xyz.pfx";

            // Password of the certificate.
            options.DigitalSignature.CertificatePassword = "******";

            // Additional information about the certificate.
            options.DigitalSignature.Location    = "World Wide Web";
            options.DigitalSignature.Reason      = "Document.Net by SautiSoft";
            options.DigitalSignature.ContactInfo = "*****@*****.**";

            // Placeholder where signature should be visualized.
            options.DigitalSignature.SignatureLine = signatureLine;

            // Visual representation of digital signature.
            options.DigitalSignature.Signature = signature;

            string savePath = Path.ChangeExtension(loadPath, ".pdf");

            dc.Save(savePath, options);
            ShowResult(savePath);
        }
Exemplo n.º 3
0
		/// <summary>
        /// This sample shows how to work with shapes and geometry. 
        /// </summary>
        /// <remarks>
        /// Details: https://sautinsoft.com/products/document/help/net/developer-guide/geometry.php
        /// </remarks>
        public static void Geometry()
        {
            string pictPath = @"..\..\image1.jpg";
            string documentPath = @"Geometry.docx";

            // Let's create a new document.
            DocumentCore dc = new DocumentCore();

            // Create shape 1 with preset geometry (Smiley Face).
            Shape shp1 = new Shape(dc, Layout.Floating(
                new HorizontalPosition(20f, LengthUnit.Millimeter, HorizontalPositionAnchor.LeftMargin),
                new VerticalPosition(80f, LengthUnit.Millimeter, VerticalPositionAnchor.TopMargin),
                new Size(100, 100)
                ));

            // Specify outline and fill.
            shp1.Outline.Fill.SetSolid(new Color("358CCB"));
            shp1.Outline.Width = 3;
            shp1.Fill.SetSolid(Color.Orange);

            // Specify a figure.
            shp1.Geometry.SetPreset(Figure.SmileyFace);

            // Create shape 2 with custom geometry path (using points array).
            Shape shp2 = new Shape(dc, Layout.Floating(
                new HorizontalPosition(85f, LengthUnit.Millimeter, HorizontalPositionAnchor.LeftMargin),
                new VerticalPosition(80f, LengthUnit.Millimeter, VerticalPositionAnchor.TopMargin),
                new Size(100, 100)
                ));

            // Specify outline and fill using a picture.
            shp2.Outline.Fill.SetSolid(Color.Green);
            shp2.Outline.Width = 2;

            // Set the picture as fill for this shape.
            shp2.Fill.SetPicture(pictPath);

            // Specify the maximum X and Y coordinates that should be used
            // for within the path coordinate system.
            Size size = new Size(1, 1);

            // Specify the path points (draw a circle of 10 points).
            Point[] points = new Point[10];
            double a = 0;
            for (int i = 0; i < 10; ++i)
            {
                points[i] = new Point(0.5 + Math.Sin(a) * 0.5, 0.5 + Math.Cos(a) * 0.5);
                a += 2 * Math.PI / 10;
            }

            // Create and add new custom path from specified points array.
            shp2.Geometry.SetCustom().AddPath(size, points, true);

            // Create shape3 with custom geometry path (using path elements).
            Shape shp3 = new Shape(dc, Layout.Floating(
                new HorizontalPosition(150f, LengthUnit.Millimeter, HorizontalPositionAnchor.LeftMargin),
                new VerticalPosition(80f, LengthUnit.Millimeter, VerticalPositionAnchor.TopMargin),
                new Size(100, 100)
                ));

            // Specify outline and fill.
            shp3.Outline.Fill.SetSolid(new Color(255,0,0));
            shp3.Outline.Width = 2;
            shp3.Fill.SetSolid(Color.Yellow);

            // Create and add new custom path.
            CustomPath path = shp3.Geometry.SetCustom().AddPath(new Size(1, 1));

            // Specify path elements.
            path.MoveTo(new Point(0, 0));
            path.AddLine(new Point(0, 1));
            path.AddLine(new Point(1, 1));
            path.AddLine(new Point(1, 0));
            path.ClosePath();

            // Add drawing elements to document.
            dc.Content.End.Insert(shp1.Content);
            dc.Content.End.Insert(shp2.Content);
            dc.Content.End.Insert(shp3.Content);

            // Save the document to DOCX format.
            dc.Save(documentPath);

            // Open the result for demonstration purposes.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(documentPath) { UseShellExecute = true });
        }
Exemplo n.º 4
0
        /// <summary>
        /// Load an existing document (*.docx, *.rtf, *.pdf, *.html, *.txt, *.pdf) and save it in a PDF document with the digital signature.
        /// </summary>
        /// <remarks>
        /// Details: https://sautinsoft.com/products/document/help/net/developer-guide/digital-signature-net-csharp-vb.php
        /// </remarks>
        public static void DigitalSignature()
        {
            // Path to a loadable document.
            string loadPath = @"..\..\digitalsignature.docx";
            string savePath = "Result.pdf";

            DocumentCore dc = DocumentCore.Load(loadPath);

            // Create a new invisible Shape for the digital signature.
            // Place the Shape into top-left corner (0 mm, 0 mm) of page.
            Shape signatureShape = new Shape(dc, Layout.Floating(new HorizontalPosition(0f, LengthUnit.Millimeter, HorizontalPositionAnchor.LeftMargin),
                                                                 new VerticalPosition(0f, LengthUnit.Millimeter, VerticalPositionAnchor.TopMargin), new Size(1, 1)));

            ((FloatingLayout)signatureShape.Layout).WrappingStyle = WrappingStyle.InFrontOfText;
            signatureShape.Outline.Fill.SetEmpty();

            // Find a first paragraph and insert our Shape inside it.
            Paragraph firstPar = dc.GetChildElements(true).OfType <Paragraph>().FirstOrDefault();

            firstPar.Inlines.Add(signatureShape);

            // Picture which symbolizes a handwritten signature.
            Picture signaturePict = new Picture(dc, @"..\..\signature.png");

            // Signature picture will be positioned:
            // 14.5 cm from Top of the Shape.
            // 4.5 cm from Left of the Shape.
            signaturePict.Layout = Layout.Floating(
                new HorizontalPosition(4.5, LengthUnit.Centimeter, HorizontalPositionAnchor.Page),
                new VerticalPosition(14.5, LengthUnit.Centimeter, VerticalPositionAnchor.Page),
                new Size(20, 10, LengthUnit.Millimeter));

            PdfSaveOptions options = new PdfSaveOptions();

            // Path to the certificate (*.pfx).
            options.DigitalSignature.CertificatePath = @"..\..\sautinsoft.pfx";

            // The password for the certificate.
            // Each certificate is protected by a password.
            // The reason is to prevent unauthorized the using of the certificate.
            options.DigitalSignature.CertificatePassword = "******";

            // Additional information about the certificate.
            options.DigitalSignature.Location    = "World Wide Web";
            options.DigitalSignature.Reason      = "Document.Net by SautinSoft";
            options.DigitalSignature.ContactInfo = "*****@*****.**";

            // Placeholder where signature should be visualized.
            options.DigitalSignature.SignatureLine = signatureShape;

            // Visual representation of digital signature.
            options.DigitalSignature.Signature = signaturePict;

            dc.Save(savePath, options);

            // Open the result for demonstration purposes.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(savePath)
            {
                UseShellExecute = true
            });
        }