Example #1
0
        private void MRenderCtrl_Load(object sender, EventArgs e)
        {
            mDocument = new Document();
            mDbView   = mDocument.Initialize("3D");

            mRootSceneNode = new DocumentSceneNode(mDocument);
            mRenderCtrl.ShowSceneNode(mRootSceneNode);

            mContext = new UICommandContext(this);

            mDocument.EnableTransaction(false);
            var material = new MaterialElement();

            material.SetName("Default");
            mMaterialId = mDocument.AddElement(material);

            mDocument.EnableTransaction(true);

            mRenderCtrl.SetSelectCallback((PickedItem item) =>
            {
                var node      = item.GetNode();
                var elementId = node == null ? ElementId.InvalidId : new ElementId(node.GetUserId());
                mSelectionCallback(item, mDocument, elementId);
            });
        }
Example #2
0
        protected void convertToPdfButton_Click(object sender, EventArgs e)
        {
            // Get the server IP and port
            String serverIP   = textBoxServerIP.Text;
            uint   serverPort = uint.Parse(textBoxServerPort.Text);

            // Create a PDF document
            Document pdfDocument = new Document(serverIP, serverPort);

            // Set optional service password
            if (textBoxServicePassword.Text.Length > 0)
            {
                pdfDocument.ServicePassword = textBoxServicePassword.Text;
            }

            // Set license key received after purchase to use the converter in licensed mode
            // Leave it not set to use the converter in demo mode
            pdfDocument.LicenseKey = "4W9+bn19bn5ue2B+bn1/YH98YHd3d3c=";

            // Add a page to PDF document
            PdfPage pdfPage = pdfDocument.AddPage();

            string htmlWithDigitalSignatureMarker = htmlStringTextBox.Text;
            string baseUrl = baseUrlTextBox.Text;

            // Add a HTML string with a marker for digital signature to PDF document
            HtmlToPdfElement htmlToPdfElement = new HtmlToPdfElement(htmlWithDigitalSignatureMarker, baseUrl);

            pdfPage.AddElement(htmlToPdfElement);

            string certificateFilePath = Server.MapPath(@"~/DemoAppFiles/Input/Certificates/evopdf.pfx");

            // Create the digital signature
            DigitalSignatureElement signature = new DigitalSignatureElement(certificateFilePath, "evopdf", 0);

            signature.Reason      = "Protect the document from unwanted changes";
            signature.ContactInfo = "The contact email is [email protected]";
            signature.Location    = "Development server";
            pdfDocument.AddElement(signature);

            // Save the PDF document in a memory buffer
            byte[] outPdfBuffer = pdfDocument.Save();

            // Send the PDF as response to browser

            // Set response content type
            Response.AddHeader("Content-Type", "application/pdf");

            // Instruct the browser to open the PDF file as an attachment or inline
            Response.AddHeader("Content-Disposition", String.Format("attachment; filename=Digital_Signatures.pdf; size={0}", outPdfBuffer.Length.ToString()));

            // Write the PDF document buffer to HTTP response
            Response.BinaryWrite(outPdfBuffer);

            // End the HTTP response and stop the current page processing
            Response.End();
        }
Example #3
0
        /// <summary>
        /// 只能加一次
        /// </summary>
        /// <param name="doc"></param>
        public void AddElement(Document doc)
        {
            var element = new UserElement();

            element.SetName(Text);
            element.SetSchemaName("TextSceneNode");
            Id = doc.AddElement(element);

            element.AddParameter("PositionX", ParameterCreator.Create(Position.x));
            element.AddParameter("PositionY", ParameterCreator.Create(Position.y));
            element.AddParameter("PositionZ", ParameterCreator.Create(Position.z));
        }
Example #4
0
        public void Add(int pageSectionId, string containerElementId, string elementBody)
        {
            var pageSection = _context.PageSections.SingleOrDefault(x => x.PageSectionId == pageSectionId);

            if (pageSection == null)
            {
                return;
            }

            var document = new Document(pageSection.PageSectionBody);

            document.AddElement(containerElementId, elementBody);

            pageSection.PageSectionBody = document.OuterHtml;

            _context.SaveChanges();
        }
Example #5
0
        public async Task AddAsync(int pageSectionId, string containerElementId, string elementBody)
        {
            var pageSection = await _context.PageSections.SingleOrDefaultAsync(x => x.PageSectionId == pageSectionId);

            if (pageSection == null)
            {
                return;
            }

            var document = new Document(pageSection.PageSectionBody);

            document.AddElement(containerElementId, elementBody);

            pageSection.PageSectionBody = document.OuterHtml;

            await _context.SaveChangesAsync();
        }
        protected void createPdfButton_Click(object sender, EventArgs e)
        {
            // Get the server IP and port
            String serverIP   = textBoxServerIP.Text;
            uint   serverPort = uint.Parse(textBoxServerPort.Text);

            // Create a PDF document
            Document pdfDocument = new Document(serverIP, serverPort);

            // Set optional service password
            if (textBoxServicePassword.Text.Length > 0)
            {
                pdfDocument.ServicePassword = textBoxServicePassword.Text;
            }

            // Set license key received after purchase to use the converter in licensed mode
            // Leave it not set to use the converter in demo mode
            pdfDocument.LicenseKey = "4W9+bn19bn5ue2B+bn1/YH98YHd3d3c=";

            // The titles font used to mark various sections of the PDF document
            PdfFont titleFont = new PdfFont("Times New Roman", 12, true);

            titleFont.Bold = true;

            // Create a PDF page in PDF document
            PdfPage pdfPage = pdfDocument.AddPage();

            // Line Elements

            // Add section title
            TextElement titleTextElement = new TextElement(5, 5, "Line Elements", titleFont);

            titleTextElement.ForeColor = RgbColor.Black;
            pdfPage.AddElement(titleTextElement);

            // Add a line with default properties
            LineElement lineElement = new LineElement(0, 0, 50, 0);

            pdfDocument.AddElement(lineElement, 10);

            // Add a bold line
            LineElement boldLineElement = new LineElement(0, 0, 50, 0);

            boldLineElement.LineStyle.LineWidth = 3;
            pdfDocument.AddElement(boldLineElement, 10, true, false, 0, true, false);

            // Add dotted line
            LineElement dottedLineElement = new LineElement(0, 0, 50, 0);

            dottedLineElement.LineStyle.LineDashStyle = LineDashStyle.Dot;
            dottedLineElement.ForeColor = RgbColor.Green;
            pdfDocument.AddElement(dottedLineElement, 10, true, false, 0, true, false);

            // Add a dashed line
            LineElement dashedLineElement = new LineElement(0, 0, 50, 0);

            dashedLineElement.LineStyle.LineDashStyle = LineDashStyle.Dash;
            dashedLineElement.ForeColor = RgbColor.Green;
            pdfDocument.AddElement(dashedLineElement, 10, true, false, 0, true, false);

            // Add a dash-dot-dot line
            LineElement dashDotDotLineElement = new LineElement(0, 0, 50, 0);

            dashDotDotLineElement.LineStyle.LineDashStyle = LineDashStyle.DashDotDot;
            dashDotDotLineElement.ForeColor = RgbColor.Green;
            pdfDocument.AddElement(dashDotDotLineElement, 10, true, false, 0, true, false);

            // Add a bold line with rounded cap style
            LineElement roundCapBoldLine = new LineElement(0, 0, 50, 0);

            roundCapBoldLine.LineStyle.LineWidth    = 5;
            roundCapBoldLine.LineStyle.LineCapStyle = LineCapStyle.RoundCap;
            roundCapBoldLine.ForeColor = RgbColor.Blue;
            pdfDocument.AddElement(roundCapBoldLine, 10, true, false, 0, true, false);

            // Add a bold line with projecting square cap style
            LineElement projectingSquareCapBoldLine = new LineElement(0, 0, 50, 0);

            projectingSquareCapBoldLine.LineStyle.LineWidth    = 5;
            projectingSquareCapBoldLine.LineStyle.LineCapStyle = LineCapStyle.ProjectingSquareCap;
            projectingSquareCapBoldLine.ForeColor = RgbColor.Blue;
            pdfDocument.AddElement(projectingSquareCapBoldLine, 10, true, false, 0, true, false);

            // Add a bold line with projecting butt cap style
            LineElement buttCapBoldLine = new LineElement(0, 0, 50, 0);

            buttCapBoldLine.LineStyle.LineWidth    = 5;
            buttCapBoldLine.LineStyle.LineCapStyle = LineCapStyle.ButtCap;
            buttCapBoldLine.ForeColor = RgbColor.Blue;
            pdfDocument.AddElement(buttCapBoldLine, 10, true, false, 0, true, false);

            // Line Join Styles

            // Add section title
            titleTextElement           = new TextElement(0, 0, "Line Join and Cap Styles", titleFont);
            titleTextElement.ForeColor = RgbColor.Black;
            pdfDocument.AddElement(titleTextElement, 5, false, 10, true);

            // Add graphic path with miter join line style
            PathElement miterJoinPath = new PathElement(new PointFloat(0, 50));

            // Add path lines
            miterJoinPath.AddLineSegment(new PointFloat(25, 0));
            miterJoinPath.AddLineSegment(new PointFloat(50, 50));
            // Set path style
            miterJoinPath.LineStyle.LineWidth     = 5;
            miterJoinPath.LineStyle.LineCapStyle  = LineCapStyle.ProjectingSquareCap;
            miterJoinPath.LineStyle.LineJoinStyle = LineJoinStyle.MiterJoin;
            miterJoinPath.ForeColor = RgbColor.Coral;
            pdfDocument.AddElement(miterJoinPath, 5, false, 10, true);

            // Add graphic path with round join line style
            PathElement roundJoinPath = new PathElement(new PointFloat(0, 50));

            // Add path lines
            roundJoinPath.AddLineSegment(new PointFloat(25, 0));
            roundJoinPath.AddLineSegment(new PointFloat(50, 50));
            // Set path style
            roundJoinPath.LineStyle.LineWidth     = 5;
            roundJoinPath.LineStyle.LineCapStyle  = LineCapStyle.RoundCap;
            roundJoinPath.LineStyle.LineJoinStyle = LineJoinStyle.RoundJoin;
            roundJoinPath.ForeColor = RgbColor.Coral;
            pdfDocument.AddElement(roundJoinPath, 20, true, false, 0, true, false);


            // Add graphic path with bevel join line style
            PathElement bevelJoinPath = new PathElement(new PointFloat(0, 50));

            // Add lines to path
            bevelJoinPath.AddLineSegment(new PointFloat(25, 0));
            bevelJoinPath.AddLineSegment(new PointFloat(50, 50));
            // Set path style
            bevelJoinPath.LineStyle.LineWidth     = 5;
            bevelJoinPath.LineStyle.LineCapStyle  = LineCapStyle.ButtCap;
            bevelJoinPath.LineStyle.LineJoinStyle = LineJoinStyle.BevelJoin;
            bevelJoinPath.ForeColor = RgbColor.Coral;
            // Add element to document
            pdfDocument.AddElement(bevelJoinPath, 20, true, false, 0, true, false);

            // Add a polygon with miter join line style
            PointFloat[] polygonPoints = new PointFloat[] {
                new PointFloat(0, 50),
                new PointFloat(25, 0),
                new PointFloat(50, 50)
            };
            PolygonElement miterJoinPolygon = new PolygonElement(polygonPoints);

            // Set polygon style
            miterJoinPolygon.LineStyle.LineWidth     = 5;
            miterJoinPolygon.LineStyle.LineJoinStyle = LineJoinStyle.MiterJoin;
            miterJoinPolygon.ForeColor = RgbColor.Green;
            miterJoinPolygon.BackColor = RgbColor.AliceBlue;
            pdfDocument.AddElement(miterJoinPolygon, 20, true, false, 0, true, false);

            // Add a polygon with round join line style
            polygonPoints = new PointFloat[] {
                new PointFloat(0, 50),
                new PointFloat(25, 0),
                new PointFloat(50, 50)
            };
            PolygonElement roundJoinPolygon = new PolygonElement(polygonPoints);

            // Set polygon style
            roundJoinPolygon.LineStyle.LineWidth     = 5;
            roundJoinPolygon.LineStyle.LineJoinStyle = LineJoinStyle.RoundJoin;
            roundJoinPolygon.ForeColor = RgbColor.Green;
            roundJoinPolygon.BackColor = RgbColor.Blue;
            pdfDocument.AddElement(roundJoinPolygon, 20, true, false, 0, true, false);

            // Add a polygon with bevel join line style
            polygonPoints = new PointFloat[] {
                new PointFloat(0, 50),
                new PointFloat(25, 0),
                new PointFloat(50, 50)
            };
            PolygonElement bevelJoinPolygon = new PolygonElement(polygonPoints);

            // Set polygon style
            bevelJoinPolygon.LineStyle.LineWidth     = 5;
            bevelJoinPolygon.LineStyle.LineJoinStyle = LineJoinStyle.BevelJoin;
            bevelJoinPolygon.ForeColor = RgbColor.Green;
            bevelJoinPolygon.BackColor = RgbColor.Blue;
            pdfDocument.AddElement(bevelJoinPolygon, 20, true, false, 0, true, false);


            // Add a Graphics Path Element

            // Add section title
            titleTextElement           = new TextElement(0, 0, "Path Elements", titleFont);
            titleTextElement.ForeColor = RgbColor.Black;
            pdfDocument.AddElement(titleTextElement, 5, false, 10, true);

            // Create the path
            PathElement graphicsPath = new PathElement(new PointFloat(0, 0));

            // Add line and Bezier curve segments
            graphicsPath.AddLineSegment(new PointFloat(50, 50));
            graphicsPath.AddBezierCurveSegment(new PointFloat(100, 0), new PointFloat(200, 100), new PointFloat(250, 50));
            graphicsPath.AddLineSegment(new PointFloat(300, 0));
            // Close path
            graphicsPath.ClosePath = true;
            // Set path style
            graphicsPath.LineStyle.LineWidth     = 3;
            graphicsPath.LineStyle.LineJoinStyle = LineJoinStyle.MiterJoin;
            graphicsPath.LineStyle.LineCapStyle  = LineCapStyle.RoundCap;
            graphicsPath.ForeColor = RgbColor.Green;
            //graphicsPath.BackColor = Color.Green;
            graphicsPath.Gradient = new GradientColor(GradientDirection.Vertical, RgbColor.LightGreen, RgbColor.Blue);
            // Add element to document
            pdfDocument.AddElement(graphicsPath, 5, false, 10, true);


            // Add Circle Elements

            // Add section title
            titleTextElement           = new TextElement(0, 0, "Circle Elements", titleFont);
            titleTextElement.ForeColor = RgbColor.Black;
            pdfDocument.AddElement(titleTextElement, 5, false, 10, true);

            // Add a Circle Element with default settings
            CircleElement circleElement = new CircleElement(30, 30, 30);

            pdfDocument.AddElement(circleElement, 10);

            // Add dotted circle element
            CircleElement dottedCircleElement = new CircleElement(30, 30, 30);

            dottedCircleElement.ForeColor = RgbColor.Green;
            dottedCircleElement.LineStyle.LineDashStyle = LineDashStyle.Dot;
            pdfDocument.AddElement(dottedCircleElement, 10, true, false, 0, true, false);

            // Add a disc
            CircleElement discElement = new CircleElement(30, 30, 30);

            discElement.ForeColor = RgbColor.Green;
            discElement.BackColor = RgbColor.LightGray;
            pdfDocument.AddElement(discElement, 10, true, false, 0, true, false);

            // Add disc with bold border
            CircleElement discWithBoldBorder = new CircleElement(30, 30, 30);

            discWithBoldBorder.LineStyle.LineWidth = 5;
            discWithBoldBorder.BackColor           = RgbColor.Coral;
            discWithBoldBorder.ForeColor           = RgbColor.Blue;
            pdfDocument.AddElement(discWithBoldBorder, 10, true, false, 0, true, false);

            // Add colored disc with bold border
            for (int i = 30; i > 0; i = i - 3)
            {
                CircleElement coloredDisc = new CircleElement(30, 30, i);
                coloredDisc.LineStyle.LineWidth = 3;
                switch ((i / 3) % 7)
                {
                case 0:
                    coloredDisc.BackColor = RgbColor.Red;
                    break;

                case 1:
                    coloredDisc.BackColor = RgbColor.Orange;
                    break;

                case 2:
                    coloredDisc.BackColor = RgbColor.Yellow;
                    break;

                case 3:
                    coloredDisc.BackColor = RgbColor.Green;
                    break;

                case 4:
                    coloredDisc.BackColor = RgbColor.Blue;
                    break;

                case 5:
                    coloredDisc.BackColor = RgbColor.Indigo;
                    break;

                case 6:
                    coloredDisc.BackColor = RgbColor.Violet;
                    break;

                default:
                    break;
                }
                if (i == 30)
                {
                    pdfDocument.AddElement(coloredDisc, 10, true, false, 0, true, false);
                }
                else
                {
                    pdfDocument.AddElement(coloredDisc, 3, true, true, 3, true, false);
                }
            }

            // Add a doughnut
            CircleElement exteriorNoBorderDisc = new CircleElement(30, 30, 30);

            exteriorNoBorderDisc.BackColor = RgbColor.Coral;
            pdfDocument.AddElement(exteriorNoBorderDisc, 40, true, false, -30, true, false);

            CircleElement interiorNoBorderDisc = new CircleElement(30, 30, 15);

            interiorNoBorderDisc.BackColor = RgbColor.White;
            pdfDocument.AddElement(interiorNoBorderDisc, 15, true, true, 15, true, false);

            // Add a simple disc
            CircleElement simpleDisc = new CircleElement(30, 30, 30);

            simpleDisc.BackColor = RgbColor.Green;
            pdfDocument.AddElement(simpleDisc, 25, true, false, -15, true, false);


            // Add Ellipse Elements

            // Add section title
            titleTextElement           = new TextElement(0, 0, "Ellipse Elements", titleFont);
            titleTextElement.ForeColor = RgbColor.Black;
            pdfDocument.AddElement(titleTextElement, 5, false, 10, true);

            // Add an Ellipse Element with default settings
            EllipseElement ellipseElement = new EllipseElement(50, 30, 50, 30);

            pdfDocument.AddElement(ellipseElement, 5, false, 10, true);

            // Add an Ellipse Element with background color and line color
            EllipseElement ellipseWithBackgroundAndBorder = new EllipseElement(50, 30, 50, 30);

            ellipseWithBackgroundAndBorder.BackColor = RgbColor.LightGray;
            ellipseWithBackgroundAndBorder.ForeColor = RgbColor.Green;
            pdfDocument.AddElement(ellipseWithBackgroundAndBorder, 10, true, false, 0, true, false);

            // Create an ellipse from multiple Ellipse Arc Elements
            EllipseArcElement ellipseArcElement1 = new EllipseArcElement(0, 0, 100, 60, 0, 100);

            ellipseArcElement1.ForeColor           = RgbColor.Coral;
            ellipseArcElement1.LineStyle.LineWidth = 3;
            pdfDocument.AddElement(ellipseArcElement1, 10, true, false, 0, true, false);

            EllipseArcElement ellipseArcElement2 = new EllipseArcElement(0, 0, 100, 60, 100, 100);

            ellipseArcElement2.ForeColor           = RgbColor.Blue;
            ellipseArcElement2.LineStyle.LineWidth = 3;
            pdfDocument.AddElement(ellipseArcElement2, 0, true, true, 0, true, false);

            EllipseArcElement ellipseArcElement3 = new EllipseArcElement(0, 0, 100, 60, 180, 100);

            ellipseArcElement3.ForeColor           = RgbColor.Green;
            ellipseArcElement3.LineStyle.LineWidth = 3;
            pdfDocument.AddElement(ellipseArcElement3, 0, true, true, 0, true, false);

            EllipseArcElement ellipseArcElement4 = new EllipseArcElement(0, 0, 100, 60, 270, 100);

            ellipseArcElement4.ForeColor           = RgbColor.Violet;
            ellipseArcElement4.LineStyle.LineWidth = 3;
            pdfDocument.AddElement(ellipseArcElement4, 0, true, true, 0, true, false);

            // Create an ellipse from multiple Ellipse Slice Elements
            EllipseSliceElement ellipseSliceElement1 = new EllipseSliceElement(0, 0, 100, 60, 0, 90);

            ellipseSliceElement1.BackColor = RgbColor.Coral;
            pdfDocument.AddElement(ellipseSliceElement1, 10, true, false, 0, true, false);

            EllipseSliceElement ellipseSliceElement2 = new EllipseSliceElement(0, 0, 100, 60, 90, 90);

            ellipseSliceElement2.BackColor = RgbColor.Blue;
            pdfDocument.AddElement(ellipseSliceElement2, 0, true, true, 0, true, false);

            EllipseSliceElement ellipseSliceElement3 = new EllipseSliceElement(0, 0, 100, 60, 180, 90);

            ellipseSliceElement3.BackColor = RgbColor.Green;
            pdfDocument.AddElement(ellipseSliceElement3, 0, true, true, 0, true, false);


            EllipseSliceElement ellipseSliceElement4 = new EllipseSliceElement(0, 0, 100, 60, 270, 90);

            ellipseSliceElement4.BackColor = RgbColor.Violet;
            pdfDocument.AddElement(ellipseSliceElement4, 0, true, true, 0, true, false);

            // Add an Ellipse Element with background
            EllipseElement ellipseWithBackground = new EllipseElement(0, 0, 50, 30);

            ellipseWithBackground.BackColor = RgbColor.Green;
            pdfDocument.AddElement(ellipseWithBackground, 10, true, false, 0, true, false);


            // Add Rectangle Elements

            // Add section title
            titleTextElement           = new TextElement(0, 0, "Rectangle Elements", titleFont);
            titleTextElement.ForeColor = RgbColor.Black;
            pdfDocument.AddElement(titleTextElement, 5, false, 10, true);

            // Add a Rectangle Element with default settings
            RectangleElement rectangleElement = new RectangleElement(0, 0, 100, 60);

            pdfDocument.AddElement(rectangleElement, 10);

            // Add a Rectangle Element with background color and dotted line
            RectangleElement rectangleElementWithDottedLine = new RectangleElement(0, 0, 100, 60);

            rectangleElementWithDottedLine.BackColor = RgbColor.LightGray;
            rectangleElementWithDottedLine.ForeColor = RgbColor.Green;
            rectangleElementWithDottedLine.LineStyle.LineDashStyle = LineDashStyle.Dot;
            pdfDocument.AddElement(rectangleElementWithDottedLine, 10, true, false, 0, true, false);

            // Add a Rectangle Element with background color without border
            RectangleElement rectangleElementWithoutBorder = new RectangleElement(0, 0, 100, 60);

            rectangleElementWithoutBorder.BackColor = RgbColor.Green;
            pdfDocument.AddElement(rectangleElementWithoutBorder, 10, true, false, 0, true, false);

            // Add a Rectangle Element with background color, bold border line and rounded corners
            RectangleElement rectangleElementWithRoundedCorners = new RectangleElement(0, 0, 100, 60);

            rectangleElementWithRoundedCorners.BackColor               = RgbColor.Coral;
            rectangleElementWithRoundedCorners.ForeColor               = RgbColor.Blue;
            rectangleElementWithRoundedCorners.LineStyle.LineWidth     = 5;
            rectangleElementWithRoundedCorners.LineStyle.LineJoinStyle = LineJoinStyle.RoundJoin;
            pdfDocument.AddElement(rectangleElementWithRoundedCorners, 10, true, false, 0, true, false);


            // Add Polygon Elements

            // Add section title
            titleTextElement           = new TextElement(0, 0, "Polygon Elements", titleFont);
            titleTextElement.ForeColor = RgbColor.Black;
            pdfDocument.AddElement(titleTextElement, 5, false, 10, true);

            PointFloat[] polygonElementPoints = new PointFloat[] {
                new PointFloat(0, 50),
                new PointFloat(50, 0),
                new PointFloat(100, 50),
                new PointFloat(50, 100)
            };

            // Add a Polygon Element with default settings
            PolygonElement polygonElement = new PolygonElement(polygonElementPoints);

            pdfDocument.AddElement(polygonElement, 10);

            polygonElementPoints = new PointFloat[] {
                new PointFloat(0, 50),
                new PointFloat(50, 0),
                new PointFloat(100, 50),
                new PointFloat(50, 100)
            };

            // Add a Polygon Element with background color and border
            polygonElement           = new PolygonElement(polygonElementPoints);
            polygonElement.BackColor = RgbColor.LightGray;
            polygonElement.ForeColor = RgbColor.Green;
            polygonElement.LineStyle.LineDashStyle = LineDashStyle.Dot;
            pdfDocument.AddElement(polygonElement, 10, true, false, 0, true, false);

            polygonElementPoints = new PointFloat[] {
                new PointFloat(0, 50),
                new PointFloat(50, 0),
                new PointFloat(100, 50),
                new PointFloat(50, 100)
            };

            // Add a Polygon Element with background color
            polygonElement           = new PolygonElement(polygonElementPoints);
            polygonElement.BackColor = RgbColor.Green;
            pdfDocument.AddElement(polygonElement, 10, true, false, 0, true, false);

            PointFloat[] polyFillPoints = new PointFloat[] {
                new PointFloat(0, 50),
                new PointFloat(50, 0),
                new PointFloat(100, 50),
                new PointFloat(50, 100)
            };

            // Add a Polygon Element with background color and rounded line joins
            PolygonElement polygonElementWithBackgruondColorAndBorder = new PolygonElement(polyFillPoints);

            polygonElementWithBackgruondColorAndBorder.ForeColor               = RgbColor.Blue;
            polygonElementWithBackgruondColorAndBorder.BackColor               = RgbColor.Coral;
            polygonElementWithBackgruondColorAndBorder.LineStyle.LineWidth     = 5;
            polygonElementWithBackgruondColorAndBorder.LineStyle.LineCapStyle  = LineCapStyle.RoundCap;
            polygonElementWithBackgruondColorAndBorder.LineStyle.LineJoinStyle = LineJoinStyle.RoundJoin;
            pdfDocument.AddElement(polygonElementWithBackgruondColorAndBorder, 10, true, false, 0, true, false);

            // Add Bezier Curve Elements

            // Add section title
            titleTextElement           = new TextElement(0, 0, "Bezier Curve Elements", titleFont);
            titleTextElement.ForeColor = RgbColor.Black;
            pdfDocument.AddElement(titleTextElement, 5, false, 10, true);

            // Add a Bezier Curve Element with normal style

            BezierCurveElement bezierCurveElement = new BezierCurveElement(0, 50, 50, 0, 100, 100, 150, 50);

            bezierCurveElement.ForeColor           = RgbColor.Blue;
            bezierCurveElement.LineStyle.LineWidth = 3;
            pdfDocument.AddElement(bezierCurveElement, 10);

            // Add a Bezier Curve Element with dotted line using the controlling points above

            bezierCurveElement           = new BezierCurveElement(0, 50, 50, 0, 100, 100, 150, 50);
            bezierCurveElement.ForeColor = RgbColor.Green;
            bezierCurveElement.LineStyle.LineDashStyle = LineDashStyle.Dot;
            bezierCurveElement.LineStyle.LineWidth     = 1;
            pdfDocument.AddElement(bezierCurveElement, 30, true, false, 0, true, false);


            // Mark the points controlling the Bezier curve
            CircleElement controlPoint1 = new CircleElement(0, 0, 10);

            controlPoint1.BackColor = RgbColor.Violet;
            controlPoint1.Opacity   = 75;
            pdfDocument.AddElement(controlPoint1, -10, true, true, 40, true, false);

            CircleElement controlPoint2 = new CircleElement(0, 0, 10);

            controlPoint2.BackColor = RgbColor.Violet;
            pdfDocument.AddElement(controlPoint2, 50, true, true, -50, true, false);

            CircleElement controlPoint3 = new CircleElement(0, 0, 10);

            controlPoint3.BackColor = RgbColor.Violet;
            pdfDocument.AddElement(controlPoint3, 50, true, true, 100, true, false);

            CircleElement controlPoint4 = new CircleElement(0, 0, 10);

            controlPoint4.BackColor = RgbColor.Violet;
            pdfDocument.AddElement(controlPoint4, 50, true, true, -50, true, false);

            // Save the PDF document in a memory buffer
            byte[] outPdfBuffer = pdfDocument.Save();

            // Send the PDF as response to browser

            // Set response content type
            Response.AddHeader("Content-Type", "application/pdf");

            // Instruct the browser to open the PDF file as an attachment or inline
            Response.AddHeader("Content-Disposition", String.Format("attachment; filename=Graphic_Elements.pdf; size={0}", outPdfBuffer.Length.ToString()));

            // Write the PDF document buffer to HTTP response
            Response.BinaryWrite(outPdfBuffer);

            // End the HTTP response and stop the current page processing
            Response.End();
        }
Example #7
0
        protected void createPdfButton_Click(object sender, EventArgs e)
        {
            // Get the server IP and port
            String serverIP   = textBoxServerIP.Text;
            uint   serverPort = uint.Parse(textBoxServerPort.Text);

            // Create a PDF document
            Document pdfDocument = new Document(serverIP, serverPort);

            // Set optional service password
            if (textBoxServicePassword.Text.Length > 0)
            {
                pdfDocument.ServicePassword = textBoxServicePassword.Text;
            }

            // Set license key received after purchase to use the converter in licensed mode
            // Leave it not set to use the converter in demo mode
            pdfDocument.LicenseKey = "4W9+bn19bn5ue2B+bn1/YH98YHd3d3c=";

            // Add a page to PDF document
            PdfPage pdfPage = pdfDocument.AddPage();

            // The titles font used to mark various sections of the PDF document
            PdfFont titleFont = new PdfFont("Times New Roman", 10, true);

            titleFont.Bold = true;
            PdfFont subtitleFont = new PdfFont("Times New Roman", 8, true);

            // Add document title
            TextElement titleTextElement = new TextElement(5, 5, "Add Text Notes to a PDF Document", titleFont);

            pdfPage.AddElement(titleTextElement);

            // Add the text element
            string      text        = "Click the next icon to open the the text note:";
            TextElement textElement = new TextElement(0, 0, 200, text, subtitleFont);

            pdfDocument.AddElement(textElement, 10);

            RectangleFloat textNoteRectangle = new RectangleFloat(0, 0, 10, 10);

            // Create the text note
            TextNoteElement textNoteElement = new TextNoteElement(textNoteRectangle, "This is an initially closed text note");

            textNoteElement.NoteIcon = TextNoteIcon.Note;
            textNoteElement.Open     = false;
            pdfDocument.AddElement(textNoteElement, 10, true, false, 0, true, false);

            // Add the text element
            text        = "This is an already opened text note:";
            textElement = new TextElement(0, 0, 200, text, subtitleFont);
            pdfDocument.AddElement(textElement, 5, false, 10, true);

            textNoteRectangle = new RectangleFloat(0, 0, 10, 10);

            // Create the text note
            TextNoteElement textNoteOpenedElement = new TextNoteElement(textNoteRectangle, "This is an initially opened text note");

            textNoteOpenedElement.NoteIcon = TextNoteIcon.Note;
            textNoteOpenedElement.Open     = true;
            pdfDocument.AddElement(textNoteOpenedElement, 10, true, false, 0, true, false);


            // Add the text element
            text        = "Click the next icon to open the the help note:";
            textElement = new TextElement(0, 0, 200, text, subtitleFont);
            pdfDocument.AddElement(textElement, 5, false, 10, true);

            textNoteRectangle = new RectangleFloat(0, 0, 10, 10);

            // Create the text note
            TextNoteElement helpNoteElement = new TextNoteElement(textNoteRectangle, "This is an initially closed help note");

            helpNoteElement.NoteIcon = TextNoteIcon.Help;
            helpNoteElement.Open     = false;
            pdfDocument.AddElement(helpNoteElement, 10, true, false, 0, true, false);

            // Add the text element
            text        = "This is an already opened help note:";
            textElement = new TextElement(0, 0, 200, text, subtitleFont);
            pdfDocument.AddElement(textElement, 5, false, 10, true);

            textNoteRectangle = new RectangleFloat(0, 0, 10, 10);

            // Create the text note
            TextNoteElement helpNoteOpenedElement = new TextNoteElement(textNoteRectangle, "This is an initially opened help note");

            helpNoteOpenedElement.NoteIcon = TextNoteIcon.Help;
            helpNoteOpenedElement.Open     = true;
            pdfDocument.AddElement(helpNoteOpenedElement, 10, true, false, 0, true, false);

            // Add the text element
            text        = "Click the next icon to open the comment:";
            textElement = new TextElement(0, 0, 200, text, subtitleFont);
            pdfDocument.AddElement(textElement, 5, false, 10, true);

            textNoteRectangle = new RectangleFloat(0, 0, 10, 10);

            // Create the text note
            TextNoteElement commentNoteElement = new TextNoteElement(textNoteRectangle, "This is an initially closed comment note");

            commentNoteElement.NoteIcon = TextNoteIcon.Comment;
            commentNoteElement.Open     = false;
            pdfDocument.AddElement(commentNoteElement, 10, true, false, 0, true, false);


            // Add the text element
            text        = "This is an already opened comment:";
            textElement = new TextElement(0, 0, 200, text, subtitleFont);
            pdfDocument.AddElement(textElement, 5, false, 10, true);

            textNoteRectangle = new RectangleFloat(0, 0, 10, 10);

            // Create the text note
            TextNoteElement commentNoteOpenedElement = new TextNoteElement(textNoteRectangle, "This is an initially opened comment note");

            commentNoteOpenedElement.NoteIcon = TextNoteIcon.Comment;
            commentNoteOpenedElement.Open     = true;
            pdfDocument.AddElement(commentNoteOpenedElement, 10, true, false, 0, true, false);

            // Add the text element
            text        = "Click the next icon to open the paragraph note: ";
            textElement = new TextElement(0, 0, 200, text, subtitleFont);
            pdfDocument.AddElement(textElement, 5, false, 10, true);

            textNoteRectangle = new RectangleFloat(0, 0, 10, 10);

            // Create the text note
            TextNoteElement paragraphNoteElement = new TextNoteElement(textNoteRectangle, "This is an initially closed paragraph note");

            paragraphNoteElement.NoteIcon = TextNoteIcon.Paragraph;
            paragraphNoteElement.Open     = false;
            pdfDocument.AddElement(paragraphNoteElement, 10, true, false, 0, true, false);

            // Add the text element
            text        = "Click the next icon to open the new paragraph note:";
            textElement = new TextElement(0, 0, 200, text, subtitleFont);
            pdfDocument.AddElement(textElement, 5, false, 10, true);

            textNoteRectangle = new RectangleFloat(0, 0, 10, 10);

            // Create the text note
            TextNoteElement newParagraphNoteElement = new TextNoteElement(textNoteRectangle, "This is an initially closed new paragraph note");

            newParagraphNoteElement.NoteIcon = TextNoteIcon.NewParagraph;
            newParagraphNoteElement.Open     = false;
            pdfDocument.AddElement(newParagraphNoteElement, 10, true, false, 0, true, false);

            // Add the text element
            text        = "Click the next icon to open the key note:";
            textElement = new TextElement(0, 0, 200, text, subtitleFont);
            pdfDocument.AddElement(textElement, 5, false, 10, true);

            textNoteRectangle = new RectangleFloat(0, 0, 10, 10);

            // Create the text note
            TextNoteElement keyNoteElement = new TextNoteElement(textNoteRectangle, "This is an initially closed key note");

            keyNoteElement.NoteIcon = TextNoteIcon.Key;
            keyNoteElement.Open     = false;
            pdfDocument.AddElement(keyNoteElement, 10, true, false, 0, true, false);

            // Save the PDF document in a memory buffer
            byte[] outPdfBuffer = pdfDocument.Save();

            // Send the PDF as response to browser

            // Set response content type
            Response.AddHeader("Content-Type", "application/pdf");

            // Instruct the browser to open the PDF file as an attachment or inline
            Response.AddHeader("Content-Disposition", String.Format("attachment; filename=Text_Notes.pdf; size={0}", outPdfBuffer.Length.ToString()));

            // Write the PDF document buffer to HTTP response
            Response.BinaryWrite(outPdfBuffer);

            // End the HTTP response and stop the current page processing
            Response.End();
        }
        protected void createPdfButton_Click(object sender, EventArgs e)
        {
            // Get the server IP and port
            String serverIP   = textBoxServerIP.Text;
            uint   serverPort = uint.Parse(textBoxServerPort.Text);

            // Create a PDF document
            Document pdfDocument = new Document(serverIP, serverPort);

            // Set optional service password
            if (textBoxServicePassword.Text.Length > 0)
            {
                pdfDocument.ServicePassword = textBoxServicePassword.Text;
            }

            // Set license key received after purchase to use the converter in licensed mode
            // Leave it not set to use the converter in demo mode
            pdfDocument.LicenseKey = "4W9+bn19bn5ue2B+bn1/YH98YHd3d3c=";

            // Add a page to PDF document
            PdfPage pdfPage = pdfDocument.AddPage();

            // The titles font used to mark various sections of the PDF document
            PdfFont titleFont = new PdfFont("Times New Roman", 10, true);

            titleFont.Bold = true;
            PdfFont subtitleFont = new PdfFont("Times New Roman", 8, true);

            // The links text font
            PdfFont linkTextFont = new PdfFont("Times New Roman", 8, true);

            linkTextFont.Bold      = true;
            linkTextFont.Underline = true;

            // Add document title
            TextElement titleTextElement = new TextElement(5, 5, "Create URI Links in PDF Document", titleFont);

            pdfPage.AddElement(titleTextElement);

            // Make a text in PDF a link to a web page

            // Add the text element
            string      text            = "Click this text to open a web page!";
            TextElement linkTextElement = new TextElement(0, 0, 150, text, linkTextFont);

            linkTextElement.ForeColor = RgbColor.Navy;
            pdfDocument.AddElement(linkTextElement, 15);

            // Create the URI link element having the size of the text element
            RectangleFloat linkRectangle = RectangleFloat.Empty;
            string         url           = "http://www.evopdf.com";
            LinkUrlElement uriLink       = new LinkUrlElement(linkRectangle, url);

            // Add the URI link to PDF document
            pdfDocument.AddElement(uriLink, 0, true, true, 0, true, false);

            // Make an image in PDF a link to a web page

            TextElement subtitleTextElement = new TextElement(0, 0, "Click the image below to open a web page:", subtitleFont);

            pdfDocument.AddElement(subtitleTextElement, 10);

            // Add the image element
            ImageElement linkImageElement = new ImageElement(0, 0, 120, Server.MapPath("~/DemoAppFiles/Input/Images/logo.jpg"));

            pdfDocument.AddElement(linkImageElement);

            // Create the URI link element having the size of the image element
            linkRectangle = RectangleFloat.Empty;
            uriLink       = new LinkUrlElement(linkRectangle, url);

            // Add the URI link to PDF document
            pdfDocument.AddElement(uriLink, 0, true, true, 0, true, false);

            // Save the PDF document in a memory buffer
            byte[] outPdfBuffer = pdfDocument.Save();

            // Send the PDF as response to browser

            // Set response content type
            Response.AddHeader("Content-Type", "application/pdf");

            // Instruct the browser to open the PDF file as an attachment or inline
            Response.AddHeader("Content-Disposition", String.Format("attachment; filename=URI_Links.pdf; size={0}", outPdfBuffer.Length.ToString()));

            // Write the PDF document buffer to HTTP response
            Response.BinaryWrite(outPdfBuffer);

            // End the HTTP response and stop the current page processing
            Response.End();
        }
        protected void createPdfButton_Click(object sender, EventArgs e)
        {
            // Get the server IP and port
            String serverIP   = textBoxServerIP.Text;
            uint   serverPort = uint.Parse(textBoxServerPort.Text);

            // Create a PDF document
            Document pdfDocument = new Document(serverIP, serverPort);

            // Set optional service password
            if (textBoxServicePassword.Text.Length > 0)
            {
                pdfDocument.ServicePassword = textBoxServicePassword.Text;
            }

            // Set license key received after purchase to use the converter in licensed mode
            // Leave it not set to use the converter in demo mode
            pdfDocument.LicenseKey = "4W9+bn19bn5ue2B+bn1/YH98YHd3d3c=";

            // The titles font used to mark various sections of the PDF document
            PdfFont titleFont = new PdfFont("Times New Roman", 10, true);

            titleFont.Bold      = true;
            titleFont.Underline = true;

            // Create a PDF page in PDF document
            PdfPage pdfPage = pdfDocument.AddPage();

            // Text Elements Using Fonts Installed in System

            // Add section title
            TextElement titleTextElement = new TextElement(5, 5, "Text Elements Using Fonts Installed in System", titleFont);

            titleTextElement.ForeColor = RgbColor.DarkGreen;
            pdfPage.AddElement(titleTextElement);

            // Embed in PDF document a font with Normal style installed in system
            PdfFont embeddedSystemFontNormal = new PdfFont("Times New Roman", 10, true);

            // Add a text element using a font with Normal style installed in system
            TextElement embeddedSystemFontNormalTextElement = new TextElement(0, 0, "This text uses a font with Normal style installed in system", embeddedSystemFontNormal);

            pdfDocument.AddElement(embeddedSystemFontNormalTextElement, 5, 10);

            // Embed in PDF document a font with Bold style installed in system
            PdfFont embeddedSystemFontBold = new PdfFont("Times New Roman", 10, true);

            embeddedSystemFontBold.Bold = true;

            // Add a text element using a font with Bold style installed in system
            TextElement embeddedSystemFontBoldTextElement = new TextElement(0, 0, "This text uses a font with Bold style installed in system", embeddedSystemFontBold);

            pdfDocument.AddElement(embeddedSystemFontBoldTextElement, 3);

            // Embed in PDF document a font with Italic style installed in system
            PdfFont embeddedSystemFontItalic = new PdfFont("Times New Roman", 10, true);

            embeddedSystemFontItalic.Italic = true;

            // Add a text element using a font with Italic style installed in system
            TextElement embeddedSystemFontItalicTextElement = new TextElement(0, 0, "This text uses a font with Italic style installed in system", embeddedSystemFontItalic);

            pdfDocument.AddElement(embeddedSystemFontItalicTextElement, 3);

            // Text Elements Using Fonts From Local Files

            // Add section title
            titleTextElement           = new TextElement(0, 0, "Text Elements Using Fonts From Local Files", titleFont);
            titleTextElement.ForeColor = RgbColor.Navy;
            pdfDocument.AddElement(titleTextElement, -5, 15);

            // Embed a True Type font from a local file in PDF document
            PdfFont localTrueTypeFont = new PdfFont(Server.MapPath("~/DemoAppFiles/Input/Fonts/TrueType.ttf"), 10);

            // Add a text element using the local True Type font to PDF document
            TextElement localFontTtfTextElement = new TextElement(0, 0, "This text uses a True Type Font loaded from a local file", localTrueTypeFont);

            pdfDocument.AddElement(localFontTtfTextElement, 5, 10);

            // Embed an OpenType font with TrueType Outlines in PDF document
            PdfFont localOpenTypeTrueTypeFont = new PdfFont(Server.MapPath("~/DemoAppFiles/Input/Fonts/OpenTypeTrueType.otf"), 10);

            // Add a text element using the local OpenType font with TrueType Outlines to PDF document
            TextElement localOpenTypeTrueTypeFontTextElement = new TextElement(0, 0, "This text uses an Open Type Font with TrueType Outlines loaded from a local file", localOpenTypeTrueTypeFont);

            pdfDocument.AddElement(localOpenTypeTrueTypeFontTextElement);

            //  Embed an OpenType font with PostScript Outlines in PDF document
            PdfFont localOpenTypePostScriptFont = new PdfFont(Server.MapPath("~/DemoAppFiles/Input/Fonts/OpenTypePostScript.otf"), 10);

            // Add a text element using the local OpenType font with PostScript Outlines to PDF document
            TextElement localOpenTypePostScriptFontTextElement = new TextElement(0, 0, "This text uses an Open Type Font with PostScript Outlines loaded from a local file", localOpenTypePostScriptFont);

            pdfDocument.AddElement(localOpenTypePostScriptFontTextElement, 3);

            // Text Elements Using Standard PDF Fonts

            // Add section title
            titleTextElement           = new TextElement(0, 0, "Text Elements Using Standard PDF Fonts", titleFont);
            titleTextElement.ForeColor = RgbColor.DarkGreen;
            pdfDocument.AddElement(titleTextElement, -5, 10);

            // Create a standard PDF font with Normal style
            PdfFont standardPdfFontNormal = new PdfFont(StdFontBaseFamily.Helvetica, 10);

            // Add a text element using the standard PDF font with Normal style
            TextElement standardPdfFontNormalTextElement = new TextElement(0, 0, "This text uses a standard PDF font with Normal style", standardPdfFontNormal);

            pdfDocument.AddElement(standardPdfFontNormalTextElement, 5, 10);

            // Create a standard PDF font with Bold style
            PdfFont standardPdfFontBold = new PdfFont(StdFontBaseFamily.HelveticaBold, 10);

            // Add a text element using the standard PDF font with Bold style
            TextElement standardPdfFontBoldTextElement = new TextElement(0, 0, "This text uses a standard PDF font with Bold style", standardPdfFontBold);

            pdfDocument.AddElement(standardPdfFontBoldTextElement, 3);

            // Create a standard PDF font with Italic style
            PdfFont standardPdfFontItalic = new PdfFont(StdFontBaseFamily.HelveticaOblique, 10);

            // Add a text element using the standard PDF font with Italic style
            TextElement standardPdfFontItalicTextElement = new TextElement(0, 0, "This text uses a standard PDF font with Italic style", standardPdfFontItalic);

            pdfDocument.AddElement(standardPdfFontItalicTextElement, 3);

            // Add a text element that flows freely in width and height

            string text = System.IO.File.ReadAllText(Server.MapPath("~/DemoAppFiles/Input/Text_Files/Text_File.txt"));

            // Add section title
            titleTextElement           = new TextElement(0, 0, "Text Element that flows freely in width and height", titleFont);
            titleTextElement.ForeColor = RgbColor.DarkGreen;
            pdfDocument.AddElement(titleTextElement, -5, 10);

            // Add the text element
            TextElement freeWidthAndHeightTextElement = new TextElement(0, 0, text, embeddedSystemFontNormal);

            pdfDocument.AddElement(freeWidthAndHeightTextElement, 5, 10);

            // Add a text element with a given width that flows freely in height

            // Add section title
            titleTextElement           = new TextElement(0, 0, "Text Element with a given width that flows freely in height", titleFont);
            titleTextElement.ForeColor = RgbColor.Navy;
            pdfDocument.AddElement(titleTextElement, -5, 10);

            // Add the text element
            TextElement freeHeightTextElement = new TextElement(0, 0, 400, text, embeddedSystemFontNormal);

            pdfDocument.AddElement(freeHeightTextElement, 5, 10);

            // Add a text element with a given width and height

            // Add section title
            titleTextElement           = new TextElement(0, 0, "Text Element with a given width and height", titleFont);
            titleTextElement.ForeColor = RgbColor.DarkGreen;
            pdfDocument.AddElement(titleTextElement, -5, 10);

            // Add the text element
            TextElement boundedTextElement = new TextElement(0, 0, 400, 50, text, embeddedSystemFontNormal);

            pdfDocument.AddElement(boundedTextElement, 5, 10);

            // Add a text element that flows freely on next PDF page

            // Add section title
            titleTextElement           = new TextElement(0, 0, "Text Element that flows freely on multiple PDF pages", titleFont);
            titleTextElement.ForeColor = RgbColor.Navy;
            pdfDocument.AddElement(titleTextElement, -5, 10);

            // Add the text element
            string      multiPageText        = System.IO.File.ReadAllText(Server.MapPath("~/DemoAppFiles/Input/Text_Files/Large_Text_File.txt"));
            TextElement multiPageTextElement = new TextElement(0, 0, 575, multiPageText, embeddedSystemFontNormal);

            multiPageTextElement.BackColor = RgbColor.WhiteSmoke;
            pdfDocument.AddElement(multiPageTextElement, 5, 10);

            // Add a line at the bottom of the multipage text element

            LineElement bottomLine = new LineElement(0, 0, 100, 0);

            pdfDocument.AddElement(bottomLine, 0, 1);

            pdfPage = pdfDocument.AddPage();

            // Text Elements with Vertical Text

            // Add section title
            titleTextElement           = new TextElement(0, 0, "Vertical Text", titleFont);
            titleTextElement.ForeColor = RgbColor.Navy;
            pdfPage.AddElement(titleTextElement);

            // Add a top to bottom vertical text
            string topBottomText = "This is a Top to Bottom Vertical Text";

            TextElement topBottomVerticalTextElement = new TextElement(0, 0, topBottomText, embeddedSystemFontNormal);

            topBottomVerticalTextElement.Translate(25, 50);
            topBottomVerticalTextElement.Rotate(90);
            pdfDocument.AddElement(topBottomVerticalTextElement);

            pdfPage = pdfDocument.AddPage();

            // Add a bottom to top vertical text
            string bottomTopText      = "This is a Bottom to Top Vertical Text";
            float  bottomTopTextWidth = 200;

            TextElement bottomTopVerticalTextElement = new TextElement(0, 0, bottomTopText, embeddedSystemFontNormal);

            bottomTopVerticalTextElement.Translate(0, bottomTopTextWidth);
            bottomTopVerticalTextElement.Rotate(-90);
            pdfPage.AddElement(bottomTopVerticalTextElement);

            // Add a text stamp to a PDF document

            // Create a PDF font
            PdfFont stampPdfFont = new PdfFont("Times New Roman", 24, true);
            // The stamp text
            string stampText = String.Format("Text Stamp {0}", DateTime.Now.ToString("d"));
            // Measure the text
            float   textWidth = 100;
            PdfPage page      = pdfDocument.AddPage();
            // Get the PDF page drawable area width and height
            float pdfPageWidth  = page.PageSize.Width;
            float pdfPageHeight = page.PageSize.Height;

            // Calculate the PDF page diagonal
            float pdfPageDiagonal = (float)Math.Sqrt(pdfPageWidth * pdfPageWidth + pdfPageHeight * pdfPageHeight);

            // The text location on PDF page diagonal
            float xStampLocation = (pdfPageDiagonal - textWidth) / 2;

            // Create the stamp as a rotated text element
            TextElement stampTextElement = new TextElement(xStampLocation, 0, stampText, stampPdfFont);

            stampTextElement.ForeColor = RgbColor.Coral;
            stampTextElement.Rotate((float)(Math.Atan(pdfPageHeight / pdfPageWidth) * (180 / Math.PI)));
            stampTextElement.Opacity = 75;

            // Add the stamp to PDF page
            page.AddElement(stampTextElement);

            // Save the PDF document in a memory buffer
            byte[] outPdfBuffer = pdfDocument.Save();

            // Send the PDF as response to browser

            // Set response content type
            Response.AddHeader("Content-Type", "application/pdf");

            // Instruct the browser to open the PDF file as an attachment or inline
            Response.AddHeader("Content-Disposition", String.Format("attachment; filename=Text_Elements.pdf; size={0}", outPdfBuffer.Length.ToString()));

            // Write the PDF document buffer to HTTP response
            Response.BinaryWrite(outPdfBuffer);

            // End the HTTP response and stop the current page processing
            Response.End();
        }
        protected void createPdfButton_Click(object sender, EventArgs e)
        {
            // Get the server IP and port
            String serverIP   = textBoxServerIP.Text;
            uint   serverPort = uint.Parse(textBoxServerPort.Text);

            // Create a PDF document
            Document pdfDocument = new Document(serverIP, serverPort);

            // Set optional service password
            if (textBoxServicePassword.Text.Length > 0)
            {
                pdfDocument.ServicePassword = textBoxServicePassword.Text;
            }

            // Set license key received after purchase to use the converter in licensed mode
            // Leave it not set to use the converter in demo mode
            pdfDocument.LicenseKey = "4W9+bn19bn5ue2B+bn1/YH98YHd3d3c=";

            // The titles font used to mark various sections of the PDF document
            PdfFont titleFont = new PdfFont("Times New Roman", 12, true);

            titleFont.Bold = true;
            PdfFont subtitleFont = new PdfFont("Times New Roman", 8, true);

            subtitleFont.Bold = true;

            // Create a PDF page in PDF document
            PdfPage pdfPage = pdfDocument.AddPage();

            // Add section title
            TextElement titleTextElement = new TextElement(5, 5, "Images Scaling", titleFont);

            titleTextElement.ForeColor = RgbColor.Black;
            pdfPage.AddElement(titleTextElement);

            // Add an unscaled image

            // Add section title
            TextElement subtitleTextElement = new TextElement(0, 0, "Unscaled small image with normal resolution", subtitleFont);

            subtitleTextElement.ForeColor = RgbColor.Navy;
            pdfDocument.AddElement(subtitleTextElement, 10);

            string       imagePath            = Server.MapPath("~/DemoAppFiles/Input/Images/picture_small.jpg");
            ImageElement unscaledImageElement = new ImageElement(0, 0, imagePath);

            pdfDocument.AddElement(unscaledImageElement, 10);

            // Add a large image scaled down to same size in PDF

            // Add section title
            subtitleTextElement           = new TextElement(0, 0, "Scaled down large image has higher resolution", subtitleFont);
            subtitleTextElement.ForeColor = RgbColor.Navy;
            pdfDocument.AddElement(subtitleTextElement, 10);

            imagePath = Server.MapPath("~/DemoAppFiles/Input/Images/picture_large.jpg");
            ImageElement scaledDownImageElement = new ImageElement(0, 0, 50, imagePath);

            pdfDocument.AddElement(scaledDownImageElement, 10);

            // Add a border around the scaled down image
            RectangleElement borderElement = new RectangleElement(0, 0, 0, 0);

            pdfDocument.AddElement(borderElement);

            // Add an unscaled small image

            // Add section title
            subtitleTextElement           = new TextElement(0, 0, "Unscaled small image", subtitleFont);
            subtitleTextElement.ForeColor = RgbColor.Navy;
            pdfDocument.AddElement(subtitleTextElement, 10);

            imagePath            = Server.MapPath("~/DemoAppFiles/Input/Images/picture_smaller.jpg");
            unscaledImageElement = new ImageElement(0, 0, imagePath);
            pdfDocument.AddElement(unscaledImageElement, 10);

            // Add an enlarged image

            // Add section title
            subtitleTextElement           = new TextElement(0, 0, "Enlarged small image has lower resolution", subtitleFont);
            subtitleTextElement.ForeColor = RgbColor.Navy;
            pdfDocument.AddElement(subtitleTextElement, 10);

            imagePath = Server.MapPath("~/DemoAppFiles/Input/Images/picture_smaller.jpg");
            ImageElement enlargedImageElement = new ImageElement(0, 0, 200, imagePath);

            // Allow the image to be enlarged
            enlargedImageElement.EnlargeEnabled = true;
            pdfDocument.AddElement(enlargedImageElement, 10);

            // Scale an image preserving the aspect ratio

            // Add section title
            subtitleTextElement           = new TextElement(0, 0, "Scaled down image preserving aspect ratio", subtitleFont);
            subtitleTextElement.ForeColor = RgbColor.Navy;
            pdfDocument.AddElement(subtitleTextElement, 10);

            imagePath = Server.MapPath("~/DemoAppFiles/Input/Images/landscape.jpg");
            ImageElement keepAspectImageElement = new ImageElement(0, 0, 80, 80, true, imagePath);

            pdfDocument.AddElement(keepAspectImageElement, 10);

            borderElement           = new RectangleElement(0, 0, 0, 0);
            borderElement.ForeColor = RgbColor.Black;
            pdfDocument.AddElement(borderElement);

            // Scale an image without preserving aspect ratio
            // This can produce a distorted image

            // Add section title
            subtitleTextElement           = new TextElement(0, 0, "Scaled down image without preserving aspect ratio", subtitleFont);
            subtitleTextElement.ForeColor = RgbColor.Navy;
            pdfDocument.AddElement(subtitleTextElement, 10);

            imagePath = Server.MapPath("~/DemoAppFiles/Input/Images/landscape.jpg");
            ImageElement notKeepAspectImageElement = new ImageElement(0, 0, 80, 80, false, imagePath);

            pdfDocument.AddElement(notKeepAspectImageElement, 10);

            borderElement           = new RectangleElement(0, 0, 0, 0);
            borderElement.ForeColor = RgbColor.Black;
            pdfDocument.AddElement(borderElement);

            // Add transparent images

            // Add section title
            titleTextElement           = new TextElement(0, 0, "Transparent Images", titleFont);
            titleTextElement.ForeColor = RgbColor.Black;
            pdfDocument.AddElement(titleTextElement, 10);

            imagePath = Server.MapPath("~/DemoAppFiles/Input/Images/transparent.png");
            ImageElement trasparentImageElement = new ImageElement(0, 0, 150, imagePath);

            pdfDocument.AddElement(trasparentImageElement, 10);

            imagePath = Server.MapPath("~/DemoAppFiles/Input/Images/rose.png");
            trasparentImageElement = new ImageElement(0, 0, 150, imagePath);
            pdfDocument.AddElement(trasparentImageElement, 10);

            // Rotate images

            // Add a new page to document
            pdfPage = pdfDocument.AddPage();

            // Add section title
            titleTextElement           = new TextElement(0, 0, "Rotated Images", titleFont);
            titleTextElement.ForeColor = RgbColor.Black;
            pdfPage.AddElement(titleTextElement);

            // Add a not rotated image
            imagePath = Server.MapPath("~/DemoAppFiles/Input/Images/compass.png");
            ImageElement noRotationImageElement = new ImageElement(0, 25, 125, imagePath);

            pdfPage.AddElement(noRotationImageElement);

            // The rotated coordinates system location
            float rotatedImageXLocation = 125;
            float rotatedImageYLocation = 175;

            // Add the image rotated 90 degrees
            ImageElement rotate90ImageElement = new ImageElement(0, 0, 125, imagePath);

            rotate90ImageElement.Translate(rotatedImageXLocation, rotatedImageYLocation);
            rotate90ImageElement.Rotate(90);
            pdfPage.AddElement(rotate90ImageElement);

            rotatedImageXLocation = 125;
            rotatedImageYLocation = 450;

            // Add the image rotated 180 degrees
            ImageElement rotate180ImageElement = new ImageElement(0, 0, 125, imagePath);

            rotate180ImageElement.Translate(rotatedImageXLocation, rotatedImageYLocation);
            rotate180ImageElement.Rotate(180);
            pdfPage.AddElement(rotate180ImageElement);

            rotatedImageXLocation = 0;
            rotatedImageYLocation = 600;

            // Add the image rotated 270 degrees
            ImageElement rotate270ImageElement = new ImageElement(0, 0, 125, imagePath);

            rotate270ImageElement.Translate(rotatedImageXLocation, rotatedImageYLocation);
            rotate270ImageElement.Rotate(270);
            pdfPage.AddElement(rotate270ImageElement);

            // Save the PDF document in a memory buffer
            byte[] outPdfBuffer = pdfDocument.Save();

            // Send the PDF as response to browser

            // Set response content type
            Response.AddHeader("Content-Type", "application/pdf");

            // Instruct the browser to open the PDF file as an attachment or inline
            Response.AddHeader("Content-Disposition", String.Format("attachment; filename=Image_Elements.pdf; size={0}", outPdfBuffer.Length.ToString()));

            // Write the PDF document buffer to HTTP response
            Response.BinaryWrite(outPdfBuffer);

            // End the HTTP response and stop the current page processing
            Response.End();
        }
Example #11
0
        protected void createPdfButton_Click(object sender, EventArgs e)
        {
            // Get the server IP and port
            String serverIP   = textBoxServerIP.Text;
            uint   serverPort = uint.Parse(textBoxServerPort.Text);

            // Create a PDF document
            Document pdfDocument = new Document(serverIP, serverPort);

            // Set optional service password
            if (textBoxServicePassword.Text.Length > 0)
            {
                pdfDocument.ServicePassword = textBoxServicePassword.Text;
            }

            // Set license key received after purchase to use the converter in licensed mode
            // Leave it not set to use the converter in demo mode
            pdfDocument.LicenseKey = "4W9+bn19bn5ue2B+bn1/YH98YHd3d3c=";

            // Display the attachments panel when the PDF document is opened in a PDF viewer
            pdfDocument.ViewerPreferences.PageMode = ViewerPageMode.UseAttachments;

            // Add a page to PDF document
            PdfPage pdfPage = pdfDocument.AddPage();

            // The titles font used to mark various sections of the PDF document
            PdfFont titleFont = new PdfFont("Times New Roman", 10, true);

            titleFont.Bold = true;
            PdfFont subtitleFont = new PdfFont("Times New Roman", 8, true);

            // Add document title
            TextElement titleTextElement = new TextElement(5, 5, "Attach Files and Streams to a PDF Document", titleFont);

            pdfPage.AddElement(titleTextElement);

            // Create an attachment from a file without icon
            string fileAttachmentPath = Server.MapPath("~/DemoAppFiles/Input/Attach_Files/Attachment_File.txt");

            pdfDocument.AddFileAttachment(fileAttachmentPath, "Attachment from File");

            // Create an attachment from a stream without icon
            string fileStreamAttachmentPath = Server.MapPath("~/DemoAppFiles/Input/Attach_Files/Attachment_Stream.txt");

            byte[] attachmentData = System.IO.File.ReadAllBytes(fileStreamAttachmentPath);
            pdfDocument.AddFileAttachment(attachmentData, "Attachment_Stream.txt", "Attachment from Stream");

            // Add the text element
            string      text        = "Click the next icon to open the attachment from a file:";
            TextElement textElement = new TextElement(0, 0, 200, text, subtitleFont);

            pdfDocument.AddElement(textElement, 15);

            // Create an attachment from file with paperclip icon in PDF
            string fileAttachmentWithIconPath = Server.MapPath("~/DemoAppFiles/Input/Attach_Files/Attachment_File_Icon.txt");
            // Create the attachment from file
            RectangleFloat        attachFromFileIconRectangle = new RectangleFloat(0, 0, 6, 10);
            FileAttachmentElement attachFromFileElement       = new FileAttachmentElement(attachFromFileIconRectangle, fileAttachmentWithIconPath);

            attachFromFileElement.IconType  = FileAttachmentIcon.Paperclip;
            attachFromFileElement.Text      = "Attachment from File with Paperclip Icon";
            attachFromFileElement.IconColor = RgbColor.Blue;
            pdfDocument.AddElement(attachFromFileElement, 10, true, false, 0, true, false);

            // Add the text element
            text        = "Click the next icon to open the attachment from a stream:";
            textElement = new TextElement(0, 0, 200, text, subtitleFont);
            pdfDocument.AddElement(textElement, 5, false, 10, true);

            // Create an attachment from stream with pushpin icon in PDF
            string fileStreamAttachmentWithIconPath = Server.MapPath("~/DemoAppFiles/Input/Attach_Files/Attachment_Stream_Icon.txt");

            byte[] attachmentDataWithIcon = System.IO.File.ReadAllBytes(fileStreamAttachmentWithIconPath);
            // Create the attachment from stream
            RectangleFloat        attachFromStreamIconRectangle = new RectangleFloat(0, 0, 6, 10);
            FileAttachmentElement attachFromStreamElement       = new FileAttachmentElement(attachFromStreamIconRectangle, attachmentDataWithIcon, "Attachment_Stream_Icon.txt");

            attachFromStreamElement.IconType  = FileAttachmentIcon.PushPin;
            attachFromStreamElement.Text      = "Attachment from Stream with Pushpin Icon";
            attachFromStreamElement.IconColor = RgbColor.Green;
            pdfDocument.AddElement(attachFromStreamElement, 10, true, false, 0, true, false);

            // Save the PDF document in a memory buffer
            byte[] outPdfBuffer = pdfDocument.Save();

            // Send the PDF as response to browser

            // Set response content type
            Response.AddHeader("Content-Type", "application/pdf");

            // Instruct the browser to open the PDF file as an attachment or inline
            Response.AddHeader("Content-Disposition", String.Format("attachment; filename=File_Attachments.pdf; size={0}", outPdfBuffer.Length.ToString()));

            // Write the PDF document buffer to HTTP response
            Response.BinaryWrite(outPdfBuffer);

            // End the HTTP response and stop the current page processing
            Response.End();
        }
Example #12
0
        protected void convertToPdfButton_Click(object sender, EventArgs e)
        {
            // Get the server IP and port
            String serverIP   = textBoxServerIP.Text;
            uint   serverPort = uint.Parse(textBoxServerPort.Text);

            // Create a PDF document
            Document pdfDocument = new Document(serverIP, serverPort);

            // Set optional service password
            if (textBoxServicePassword.Text.Length > 0)
            {
                pdfDocument.ServicePassword = textBoxServicePassword.Text;
            }

            // Set license key received after purchase to use the converter in licensed mode
            // Leave it not set to use the converter in demo mode
            pdfDocument.LicenseKey = "4W9+bn19bn5ue2B+bn1/YH98YHd3d3c=";

            // Add a page to PDF document
            PdfPage firstPdfPage = pdfDocument.AddPage();

            // Create Header
            if (addHeaderCheckBox.Checked)
            {
                CreateHeader(pdfDocument, drawHeaderLineCheckBox.Checked);
            }

            // Create Footer
            if (addFooterCheckBox.Checked)
            {
                CreateFooter(pdfDocument, drawFooterLineCheckBox.Checked, addPageNumbersInFooterCheckBox.Checked);
            }

            // Add First HTML

            // Create the first HTML to PDF element
            HtmlToPdfElement firstHtml = new HtmlToPdfElement(0, 0, firstUrlTextBox.Text);

            // Optionally set a delay before conversion to allow asynchonous scripts to finish
            firstHtml.ConversionDelay = 2;

            // Optionally add a space between header and the content generated by this HTML to PDF element
            // The spacing for first page and the subsequent pages can be set independently
            // Leave this option not set for no spacing
            firstHtml.Y          = float.Parse(firstPageSpacingTextBox.Text);
            firstHtml.TopSpacing = float.Parse(headerSpacingTextBox.Text);

            // Optionally add a space between footer and the content generated by this HTML to PDF element
            // Leave this option not set for no spacing
            firstHtml.BottomSpacing = float.Parse(footerSpacingTextBox.Text);

            // Set the header visibility in first, odd and even pages
            if (addHeaderCheckBox.Checked)
            {
                firstPdfPage.ShowHeader         = showHeaderInFirstPageCheckBox.Checked;
                firstHtml.ShowHeaderInEvenPages = showHeaderInEvenPagesCheckBox.Checked;
                firstHtml.ShowHeaderInOddPages  = showHeaderInOddPagesCheckBox.Checked;
            }

            // Set the footer visibility in first, odd and even pages
            if (addFooterCheckBox.Checked)
            {
                firstPdfPage.ShowFooter         = showFooterInFirstPageCheckBox.Checked;
                firstHtml.ShowFooterInEvenPages = showFooterInEvenPagesCheckBox.Checked;
                firstHtml.ShowFooterInOddPages  = showFooterInOddPagesCheckBox.Checked;
            }

            // Add the first HTML to PDF element to PDF document
            firstPdfPage.AddElement(firstHtml);

            // Add Second HTML

            // Create the second HTML to PDF element
            HtmlToPdfElement secondHtml = new HtmlToPdfElement(0, 0, secondUrlTextBox.Text);

            // Optionally set a delay before conversion to allow asynchonous scripts to finish
            secondHtml.ConversionDelay = 2;

            // Optionally add a space between header and the content generated by this HTML to PDF element
            // Leave this option not set for no spacing
            secondHtml.TopSpacing = float.Parse(headerSpacingTextBox.Text);

            // Optionally add a space between footer and the content generated by this HTML to PDF element
            // Leave this option not set for no spacing
            secondHtml.BottomSpacing = float.Parse(footerSpacingTextBox.Text);

            // Set the header visibility in odd and even pages
            if (addHeaderCheckBox.Checked)
            {
                secondHtml.ShowHeaderInEvenPages = showHeaderInEvenPagesCheckBox.Checked;
                secondHtml.ShowHeaderInOddPages  = showHeaderInOddPagesCheckBox.Checked;
            }

            // Set the footer visibility in odd and even pages
            if (addFooterCheckBox.Checked)
            {
                secondHtml.ShowFooterInEvenPages = showFooterInEvenPagesCheckBox.Checked;
                secondHtml.ShowFooterInOddPages  = showFooterInOddPagesCheckBox.Checked;
            }

            if (startNewPageCheckBox.Checked)
            {
                // Create a PDF page where to add the second HTML
                PdfPage secondPdfPage = pdfDocument.AddPage();
                // Add the second HTML to PDF element to PDF document at the beginnig of the new PDF page
                secondPdfPage.AddElement(secondHtml);
            }
            else
            {
                // Add the second HTML to PDF element to PDF document write after the last added element
                pdfDocument.AddElement(secondHtml);
            }

            // Save the PDF document in a memory buffer
            byte[] outPdfBuffer = pdfDocument.Save();

            // Send the PDF as response to browser

            // Set response content type
            Response.AddHeader("Content-Type", "application/pdf");

            // Instruct the browser to open the PDF file as an attachment or inline
            Response.AddHeader("Content-Disposition", String.Format("attachment; filename=Header_Footer_in_Merge_Multipe_HTML.pdf; size={0}", outPdfBuffer.Length.ToString()));

            // Write the PDF document buffer to HTTP response
            Response.BinaryWrite(outPdfBuffer);

            // End the HTTP response and stop the current page processing
            Response.End();
        }
        protected void createPdfButton_Click(object sender, EventArgs e)
        {
            // Get the server IP and port
            String serverIP   = textBoxServerIP.Text;
            uint   serverPort = uint.Parse(textBoxServerPort.Text);

            // Create a PDF document
            Document pdfDocument = new Document(serverIP, serverPort);

            // Set optional service password
            if (textBoxServicePassword.Text.Length > 0)
            {
                pdfDocument.ServicePassword = textBoxServicePassword.Text;
            }

            // Set license key received after purchase to use the converter in licensed mode
            // Leave it not set to use the converter in demo mode
            pdfDocument.LicenseKey = "4W9+bn19bn5ue2B+bn1/YH98YHd3d3c=";

            // Add a page to PDF document
            PdfPage pdfPage = pdfDocument.AddPage();

            // The font used for titles in PDF document
            PdfFont titlesFont = new PdfFont("Times New Roman", 10, true);

            titlesFont.Bold = true;
            // The font used for field names in PDF document
            PdfFont fieldNameFont = new PdfFont("Times New Roman", 10, true);
            // The font used for buttons text in PDF document
            PdfFont buttonTextFont = new PdfFont("Times New Roman", 10, false);
            // The font used for PDF form text box fields
            PdfFont textFieldFont = new PdfFont(StdFontBaseFamily.Helvetica, 8);
            // The font used for PDF form combo box fields
            PdfFont comboBoxFieldFont = new PdfFont(StdFontBaseFamily.Helvetica, 8);

            // Add document title
            TextElement titleTextElement = new TextElement(5, 5, "Create PDF Forms", titlesFont);

            pdfPage.AddElement(titleTextElement);

            // Add a text box field to PDF form
            TextElement fieldNameTextElement = new TextElement(5, 30, 60, "First name:", fieldNameFont);

            pdfPage.AddElement(fieldNameTextElement);
            RectangleFloat fieldBoundingRectangle = new RectangleFloat(0, 50, 150, 15);
            // Create the form field
            PdfFormTextBox firstNameTextBoxField = new PdfFormTextBox(fieldBoundingRectangle, "Enter First Name", textFieldFont);

            pdfDocument.AddFormField(firstNameTextBoxField, 10, true, false, 0, true, false);
            // Set unique form field name used when the form is submitted
            firstNameTextBoxField.Name = "firstName";
            // Set the form field default value
            firstNameTextBoxField.DefaultValue = "A default first name";
            // Set form field style
            firstNameTextBoxField.Style.BackColor = RgbColor.AliceBlue;

            // Add a text box field to PDF form
            fieldNameTextElement = new TextElement(0, 75, 60, "Last name:", fieldNameFont);
            pdfDocument.AddElement(fieldNameTextElement, 5, false, 10, true);
            fieldBoundingRectangle = new RectangleFloat(0, 90, 150, 15);
            // Create the form field
            PdfFormTextBox textBoxField = new PdfFormTextBox(fieldBoundingRectangle, "Enter Last Name", textFieldFont);

            pdfDocument.AddFormField(textBoxField, 10, true, false, 0, true, false);
            // Set unique form field name used when the form is submitted
            textBoxField.Name = "lastName";
            // Set the form field default value
            textBoxField.DefaultValue = "A default last name";
            // Set form field style
            textBoxField.Style.BackColor = RgbColor.MistyRose;

            // Add a password text box field to PDF form
            fieldNameTextElement = new TextElement(0, 105, 60, "Password:"******"", textFieldFont);

            pdfDocument.AddFormField(passwordTextBoxField, 10, true, false, 0, true, false);
            // Set unique form field name used when the form is submitted
            passwordTextBoxField.Name = "password";
            // Set form field style
            passwordTextBoxField.Style.BackColor = RgbColor.AliceBlue;
            // Set the password mode for the text box
            passwordTextBoxField.IsPassword = true;

            // Add a radio buttons group to PDF form
            fieldNameTextElement = new TextElement(0, 0, 60, "Gender:", fieldNameFont);
            pdfDocument.AddElement(fieldNameTextElement, 5, false, 10, true);

            // Create the radio buttons group
            PdfFormRadioButtonsGroup radioButtonsGroup = new PdfFormRadioButtonsGroup();

            pdfDocument.AddFormField(radioButtonsGroup);
            // Set unique form field name used when the form is submitted
            radioButtonsGroup.Name = "gender";
            // Set style of the radio buttons in this group
            radioButtonsGroup.Style.BackColor = RgbColor.AntiqueWhite;

            // Add the first radio button to group
            RectangleFloat radioButtonRectangle = new RectangleFloat(0, 0, 50, 10);
            // Create the form field
            PdfFormRadioButton radioButtonFieldMale = new PdfFormRadioButton(radioButtonRectangle, "male");

            radioButtonsGroup.AddRadioButton(radioButtonFieldMale, 10, true, false, 0, true, false);

            fieldNameTextElement = new TextElement(0, 0, 30, "Male", fieldNameFont);
            pdfDocument.AddElement(fieldNameTextElement, 5, true, false, 0, true, false);

            // Add the second radio button to group
            radioButtonRectangle = new RectangleFloat(0, 0, 50, 10);
            // Create the form field
            PdfFormRadioButton radioButtonFieldFemale = new PdfFormRadioButton(radioButtonRectangle, "female");

            radioButtonsGroup.AddRadioButton(radioButtonFieldFemale, 15, true, false, 0, true, false);

            fieldNameTextElement = new TextElement(0, 0, 30, "Female", fieldNameFont);
            pdfDocument.AddElement(fieldNameTextElement, 5, true, false, 0, true, false);

            // Set the selected radio btton in group
            radioButtonsGroup.SetCheckedRadioButton(radioButtonFieldFemale);

            // Add a checkbox field to PDF form
            fieldNameTextElement = new TextElement(0, 0, 60, "Vehicle:", fieldNameFont);
            pdfDocument.AddElement(fieldNameTextElement, 5, false, 10, true);
            fieldBoundingRectangle = new RectangleFloat(0, 0, 10, 10);
            // Create the form field
            PdfFormCheckBox checkBoxField = new PdfFormCheckBox(fieldBoundingRectangle, true);

            pdfDocument.AddFormField(checkBoxField, 10, true, false, 0, true, false);
            // Set unique form field name used when the form is submitted
            checkBoxField.Name = "haveCar";
            // Set form field style
            checkBoxField.Style.BackColor = RgbColor.AntiqueWhite;
            // Set checkbox field checked state
            checkBoxField.Checked = true;

            fieldNameTextElement = new TextElement(0, 0, 50, "I have a car", fieldNameFont);
            pdfDocument.AddElement(fieldNameTextElement, 10, true, false, 0, true, false);

            // Add a combo box list field to PDF form
            fieldNameTextElement = new TextElement(0, 0, 60, "Vehicle Type:", fieldNameFont);
            pdfDocument.AddElement(fieldNameTextElement, 5, false, 10, true);

            fieldBoundingRectangle = new RectangleFloat(0, 0, 50, 15);
            string[] comboBoxItems = new string[] { "Volvo", "Saab", "Audi", "Opel" };
            // Create the form field
            PdfFormComboBox comboBoxField = new PdfFormComboBox(fieldBoundingRectangle, comboBoxItems, comboBoxFieldFont);

            pdfDocument.AddFormField(comboBoxField, 10, true, false, 0, true, false);
            // Set unique form field name used when the form is submitted
            comboBoxField.Name = "vehicleType";
            // Set the form field default value
            comboBoxField.DefaultValue = "Audi";
            // Set form field style
            comboBoxField.Style.BackColor = RgbColor.LightCyan;
            // Set selected item in combo box
            comboBoxField.Value = "Audi";

            // Add a multiline text box field to PDF form
            fieldNameTextElement = new TextElement(0, 0, 60, "Comments:", fieldNameFont);
            pdfDocument.AddElement(fieldNameTextElement, 5, false, 10, true);

            fieldBoundingRectangle = new RectangleFloat(0, 0, 150, 60);
            // Create the form field
            PdfFormTextBox multilineTextBoxField = new PdfFormTextBox(fieldBoundingRectangle,
                                                                      "Enter your comments here:\r\nFirst comment line\r\nSecond comment line", textFieldFont);

            pdfDocument.AddFormField(multilineTextBoxField, 10, true, false, 0, true, false);
            // Set unique form field name used when the form is submitted
            multilineTextBoxField.Name = "comments";
            // Set form field style
            multilineTextBoxField.Style.BackColor = RgbColor.AliceBlue;
            // Set the multiline mode for text box field
            multilineTextBoxField.IsMultiLine = true;

            // Add a form submit button to PDF form
            fieldBoundingRectangle = new RectangleFloat(0, 0, 75, 15);
            PdfFormButton submitFormButton = new PdfFormButton(fieldBoundingRectangle, "Submit", buttonTextFont);

            pdfDocument.AddFormField(submitFormButton, 5, false, 10, true);
            // Set unique form field name used when the form is submitted
            submitFormButton.Name = "submitFormButton";
            // Set form field style
            submitFormButton.Style.BackColor = RgbColor.Beige;
            // Create the form submit action
            PdfSubmitFormAction submitFormAction = new PdfSubmitFormAction(submitUrlTextBox.Text);

            submitFormAction.Flags |= PdfFormSubmitFlags.ExportFormat;
            if (getMethodRadioButton.Checked)
            {
                submitFormAction.Flags |= PdfFormSubmitFlags.GetMethod;
            }
            // Set the form submit button action
            submitFormButton.Action = submitFormAction;

            // Add a form reset button to PDF form
            fieldBoundingRectangle = new RectangleFloat(0, 0, 75, 15);
            PdfFormButton resetFormButton = new PdfFormButton(fieldBoundingRectangle, "Reset", buttonTextFont);

            pdfDocument.AddFormField(resetFormButton, 10, true, false, 0, true, false);
            // Set unique form field name used when the form is submitted
            resetFormButton.Name = "resetFormButton";
            // Set form field style
            resetFormButton.Style.BackColor = RgbColor.Beige;
            // Create the form reset action
            PdfResetFormAction resetFormAction = new PdfResetFormAction();

            // Set the form reset button action
            resetFormButton.Action = resetFormAction;

            // Save the PDF document in a memory buffer
            byte[] outPdfBuffer = pdfDocument.Save();

            // Send the PDF as response to browser

            // Set response content type
            Response.AddHeader("Content-Type", "application/pdf");

            // Instruct the browser to open the PDF file as an attachment or inline
            Response.AddHeader("Content-Disposition", String.Format("attachment; filename=Create_PDF_Forms.pdf; size={0}", outPdfBuffer.Length.ToString()));

            // Write the PDF document buffer to HTTP response
            Response.BinaryWrite(outPdfBuffer);

            // End the HTTP response and stop the current page processing
            Response.End();
        }
Example #14
0
        protected void convertToPdfButton_Click(object sender, EventArgs e)
        {
            // Get the server IP and port
            String serverIP   = textBoxServerIP.Text;
            uint   serverPort = uint.Parse(textBoxServerPort.Text);

            // Create the PDF document where to add the HTML documents
            Document pdfDocument = new Document(serverIP, serverPort);

            // Set optional service password
            if (textBoxServicePassword.Text.Length > 0)
            {
                pdfDocument.ServicePassword = textBoxServicePassword.Text;
            }

            // Set license key received after purchase to use the converter in licensed mode
            // Leave it not set to use the converter in demo mode
            pdfDocument.LicenseKey = "4W9+bn19bn5ue2B+bn1/YH98YHd3d3c=";

            // Create a PDF page where to add the first HTML
            PdfPage firstPdfPage = pdfDocument.AddPage();

            // Create the first HTML to PDF element
            HtmlToPdfElement firstHtml = new HtmlToPdfElement(0, 0, firstUrlTextBox.Text);

            // Optionally set a delay before conversion to allow asynchronous scripts to finish
            firstHtml.ConversionDelay = 2;

            // Add the first HTML to PDF document
            firstPdfPage.AddElement(firstHtml);

            PdfPage secondPdfPage = null;

            // Create the second HTML to PDF element
            HtmlToPdfElement secondHtml = new HtmlToPdfElement(0, 0, secondUrlTextBox.Text);

            // Optionally set a delay before conversion to allow asynchronous scripts to finish
            secondHtml.ConversionDelay = 2;

            if (startNewPageCheckBox.Checked)
            {
                // Create a PDF page where to add the second HTML
                secondPdfPage = pdfDocument.AddPage();

                // Add the second HTML to PDF document
                secondPdfPage.AddElement(secondHtml);
            }
            else
            {
                // Add the second HTML right after the first one
                pdfDocument.AddElement(secondHtml);
            }

            // Save the PDF document in a memory buffer
            byte[] outPdfBuffer = pdfDocument.Save();

            // Send the PDF as response to browser

            // Set response content type
            Response.AddHeader("Content-Type", "application/pdf");

            // Instruct the browser to open the PDF file as an attachment or inline
            Response.AddHeader("Content-Disposition", String.Format("attachment; filename=Merge_Multipe_HTML.pdf; size={0}", outPdfBuffer.Length.ToString()));

            // Write the PDF document buffer to HTTP response
            Response.BinaryWrite(outPdfBuffer);

            // End the HTTP response and stop the current page processing
            Response.End();
        }