Ejemplo n.º 1
0
        /// <summary>
        /// Creates third page in the document
        /// </summary>
        private void CreateThirdPage()
        {
            // Access third page.
            page = document.Pages[2];
            page.Graphics.DrawImage(img, 0, 0, pageSize.Width, pageSize.Height);

            pdfFont = new PdfStandardFont(PdfFontFamily.Helvetica, 12f, PdfFontStyle.Bold);

            page.Graphics.DrawString("Thank You", pdfFont, new PdfSolidBrush(new PdfColor(213, 123, 19)), x, 80);

            pdfFont = new PdfStandardFont(PdfFontFamily.Helvetica, 12f, PdfFontStyle.Regular);

            page.Graphics.DrawString("Thanks for taking the time to complete this form.\nWe will be in contact with you shortly.", pdfFont, solidBrush, x, 110);

            // Send email during button click.
            PdfButtonField submitButton1 = new PdfButtonField(page, "submitButton1");

            submitButton1.Bounds      = new RectangleF(x, 160, 100, 20);
            submitButton1.Font        = pdfFont;
            submitButton1.Text        = "Apply";
            submitButton1.BorderStyle = PdfBorderStyle.Beveled;
            submitButton1.BackColor   = new PdfColor(181, 191, 203);

            // Create a javascript action.
            PdfJavaScriptAction javaAction = new PdfJavaScriptAction("address = app.response(\"Enter an e-mail address.\",\"SEND E-MAIL\",\"\");"
                                                                     + "if (address){ cmdLine = \"mailto:\" + address;" +
                                                                     "this.submitForm(cmdLine,true,false,\"Remarks\");}");

            submitButton1.Actions.MouseUp = javaAction;

            // Add button to the form.
            document.Form.Fields.Add(submitButton1);

            document.Form.SetDefaultAppearance(false);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a PDF document
            PdfDocument doc  = new PdfDocument();
            PdfPageBase page = doc.Pages.Add();

            //Create a Button
            PdfButtonField btn = new PdfButtonField(page, "button1");

            btn.Bounds        = new RectangleF(0, 50, 120, 100);
            btn.HighlightMode = PdfHighlightMode.Push;
            btn.LayoutMode    = PdfButtonLayoutMode.CaptionOverlayIcon;

            //Set text and icon for Normal appearance
            btn.Text = "Normal Text";
            btn.Icon = PdfImage.FromFile(@"..\..\..\..\..\..\Data\E-iceblueLogo.png");

            //Set text and icon for Click appearance (Can only be set when highlight mode is Push)
            btn.AlternateText = "Alternate Text";
            btn.AlternateIcon = PdfImage.FromFile(@"..\..\..\..\..\..\Data\PdfImage.png");

            //Set text and icon for Rollover appearance (Can only be set when highlight mode is Push)
            btn.RolloverText = "Rollover Text";
            btn.RolloverIcon = PdfImage.FromFile(@"..\..\..\..\..\..\Data\PDFJAVA.png");

            //Set icon layout
            btn.IconLayout.Spaces      = new float[] { 0.5f, 0.5f };
            btn.IconLayout.ScaleMode   = PdfButtonIconScaleMode.Proportional;
            btn.IconLayout.ScaleReason = PdfButtonIconScaleReason.Always;
            btn.IconLayout.IsFitBounds = false;

            //Add the button to the document
            doc.Form.Fields.Add(btn);

            String result = "AssignIconToButtonField-result.pdf";

            //Save the document
            doc.SaveToFile(result);

            //Launch the Pdf file
            PDFDocumentViewer(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Adds navigation button.
        /// </summary>
        /// <param name="currentPage"></param>
        /// <param name="buttonText"></param>
        private void NavigateToNextPage(PdfPage currentPage, string buttonText)
        {
            // Create a Button field.
            PdfButtonField submitButton = new PdfButtonField(page, buttonText);

            submitButton.Bounds  = new RectangleF(page.GetClientSize().Width - 30, page.GetClientSize().Height - x, 25, 15);
            submitButton.Font    = pdfFont;
            submitButton.ToolTip = buttonText;

            // Add a new page.
            page = document.Pages.Add();

            // Create an instance of PdfDestination.
            PdfDestination dest = new PdfDestination(page, new PointF(0, 100));

            // Create an instance of GoTo action.
            PdfGoToAction goToAction = new PdfGoToAction(page);

            // Update the destination for the action.
            goToAction.Destination = dest;

            // Set action for the field.
            submitButton.Actions.GotFocus = goToAction;
        }
Ejemplo n.º 4
0
        public ActionResult InteractiveFeatures(string InsideBrowser)
        {
            #region Field Definitions
            document = new PdfDocument();
            document.PageSettings.Margins.All = 0;
            document.PageSettings.Size        = new SizeF(PdfPageSize.A4.Width, 600);
            interactivePage = document.Pages.Add();
            PdfGraphics g    = interactivePage.Graphics;
            RectangleF  rect = new RectangleF(0, 0, interactivePage.Graphics.ClientSize.Width, 100);

            PdfBrush whiteBrush  = new PdfSolidBrush(white);
            PdfPen   whitePen    = new PdfPen(white, 5);
            PdfBrush purpleBrush = new PdfSolidBrush(new PdfColor(255, 158, 0, 160));
            PdfFont  font        = new PdfStandardFont(PdfFontFamily.Helvetica, 25);
            Syncfusion.Drawing.Color maroonColor = Color.FromArgb(255, 188, 32, 60);
            Syncfusion.Drawing.Color orangeColor = Color.FromArgb(255, 255, 167, 73);
            #endregion

            #region Header
            g.DrawRectangle(purpleBrush, rect);
            g.DrawPie(whitePen, whiteBrush, new RectangleF(-20, 35, 700, 200), 20, -180);
            g.DrawRectangle(whiteBrush, new RectangleF(0, 99.5f, 700, 200));
            g.DrawString("Invoice", new PdfStandardFont(PdfFontFamily.TimesRoman, 24), PdfBrushes.White, new PointF(500, 10));

            string basePath = _hostingEnvironment.WebRootPath;
            string dataPath = string.Empty;
            dataPath = basePath + @"/PDF/";

            //Read the file
            FileStream file = new FileStream(dataPath + "AdventureCycle.jpg", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

            g.DrawImage(PdfImage.FromStream(file), new RectangleF(100, 70, 390, 130));
            #endregion

            #region Body

            //Invoice Number
            Random invoiceNumber = new Random();
            g.DrawString("Invoice No: " + invoiceNumber.Next().ToString(), new PdfStandardFont(PdfFontFamily.Helvetica, 14), new PdfSolidBrush(maroonColor), new PointF(50, 210));
            g.DrawString("Date: ", new PdfStandardFont(PdfFontFamily.Helvetica, 14), new PdfSolidBrush(maroonColor), new PointF(350, 210));

            //Current Date
            PdfTextBoxField textBoxField = new PdfTextBoxField(interactivePage, "date");
            textBoxField.Font          = new PdfStandardFont(PdfFontFamily.Helvetica, 12);
            textBoxField.Bounds        = new RectangleF(384, 204, 150, 30);
            textBoxField.ForeColor     = new PdfColor(maroonColor);
            textBoxField.ReadOnly      = true;
            document.Actions.AfterOpen = new PdfJavaScriptAction(@"var newdate = new Date(); 
            var thisfieldis = this.getField('date');  
            
            var theday = util.printd('dddd',newdate); 
            var thedate = util.printd('d',newdate); 
            var themonth = util.printd('mmmm',newdate);
            var theyear = util.printd('yyyy',newdate);  
            
            thisfieldis.strokeColor=color.transparent;
            thisfieldis.value = theday + ' ' + thedate + ', ' + themonth + ' ' + theyear ;");
            document.Form.Fields.Add(textBoxField);

            //invoice table
            PdfLightTable table = new PdfLightTable();
            table.Style.ShowHeader = true;
            g.DrawRectangle(new PdfSolidBrush(Syncfusion.Drawing.Color.FromArgb(238, 238, 238, 248)), new RectangleF(50, 240, 500, 140));

            //Header Style
            PdfCellStyle headerStyle = new PdfCellStyle();
            headerStyle.Font            = new PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Bold);
            headerStyle.TextBrush       = whiteBrush;
            headerStyle.StringFormat    = new PdfStringFormat(PdfTextAlignment.Center);
            headerStyle.BackgroundBrush = new PdfSolidBrush(orangeColor);
            headerStyle.BorderPen       = new PdfPen(whiteBrush, 0);
            table.Style.HeaderStyle     = headerStyle;

            //Cell Style
            PdfCellStyle bodyStyle = new PdfCellStyle();
            bodyStyle.Font           = new PdfStandardFont(PdfFontFamily.Helvetica, 10);
            bodyStyle.StringFormat   = new PdfStringFormat(PdfTextAlignment.Left);
            bodyStyle.BorderPen      = new PdfPen(whiteBrush, 0);
            table.Style.DefaultStyle = bodyStyle;
            table.DataSource         = GetProductReport(_hostingEnvironment.WebRootPath);
            table.Columns[0].Width   = 90;
            table.Columns[1].Width   = 160;
            table.Columns[3].Width   = 100;
            table.Columns[4].Width   = 65;
            table.Style.CellPadding  = 3;
            table.BeginCellLayout   += table_BeginCellLayout;

            PdfLightTableLayoutResult result = table.Draw(interactivePage, new RectangleF(50, 240, 500, 140));

            g.DrawString("Grand Total:", new PdfStandardFont(PdfFontFamily.Helvetica, 12), new PdfSolidBrush(Syncfusion.Drawing.Color.FromArgb(255, 255, 167, 73)), new PointF(result.Bounds.Right - 150, result.Bounds.Bottom));
            CreateTextBox(interactivePage, "GrandTotal", "Grand Total", new RectangleF(result.Bounds.Width - 15, result.Bounds.Bottom - 2, 66, 18), true, "");


            //Send to Server
            PdfButtonField sendButton = new PdfButtonField(interactivePage, "OrderOnline");
            sendButton.Bounds      = new RectangleF(200, result.Bounds.Bottom + 70, 80, 25);
            sendButton.BorderColor = white;
            sendButton.BackColor   = maroonColor;
            sendButton.ForeColor   = white;
            sendButton.Text        = "Order Online";
            PdfSubmitAction submitAction = new PdfSubmitAction("http://stevex.net/dump.php");
            submitAction.DataFormat    = SubmitDataFormat.Html;
            sendButton.Actions.MouseUp = submitAction;
            document.Form.Fields.Add(sendButton);

            //Order by Mail
            PdfButtonField sendMail = new PdfButtonField(interactivePage, "sendMail");
            sendMail.Bounds      = new RectangleF(300, result.Bounds.Bottom + 70, 80, 25);
            sendMail.Text        = "Order By Mail";
            sendMail.BorderColor = white;
            sendMail.BackColor   = maroonColor;
            sendMail.ForeColor   = white;

            // Create a javascript action.
            PdfJavaScriptAction javaAction = new PdfJavaScriptAction("address = app.response(\"Enter an e-mail address.\",\"SEND E-MAIL\",\"\");"
                                                                     + "var aSubmitFields = [];"
                                                                     + "for( var i = 0 ; i < this.numFields; i++){"
                                                                     + "aSubmitFields[i] = this.getNthFieldName(i);"
                                                                     + "}"
                                                                     + "if (address){ cmdLine = \"mailto:\" + address;this.submitForm(cmdLine,true,false,aSubmitFields);}");

            sendMail.Actions.MouseUp = javaAction;
            document.Form.Fields.Add(sendMail);

            //Print
            PdfButtonField printButton = new PdfButtonField(interactivePage, "print");
            printButton.Bounds          = new RectangleF(400, result.Bounds.Bottom + 70, 80, 25);
            printButton.BorderColor     = white;
            printButton.BackColor       = maroonColor;
            printButton.ForeColor       = white;
            printButton.Text            = "Print";
            printButton.Actions.MouseUp = new PdfJavaScriptAction("this.print (true); ");
            document.Form.Fields.Add(printButton);
            file = new FileStream(dataPath + "Product Catalog.pdf", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            PdfAttachment attachment = new PdfAttachment("Product Catalog.pdf", file);
            attachment.ModificationDate = DateTime.Now;
            attachment.Description      = "Specification";
            document.Attachments.Add(attachment);

            //Open Specification
            PdfButtonField openSpecificationButton = new PdfButtonField(interactivePage, "openSpecification");
            openSpecificationButton.Bounds          = new RectangleF(50, result.Bounds.Bottom + 20, 87, 15);
            openSpecificationButton.TextAlignment   = PdfTextAlignment.Left;
            openSpecificationButton.Font            = new PdfStandardFont(PdfFontFamily.Helvetica, 10);
            openSpecificationButton.BorderStyle     = PdfBorderStyle.Underline;
            openSpecificationButton.BorderColor     = orangeColor;
            openSpecificationButton.BackColor       = new PdfColor(255, 255, 255);
            openSpecificationButton.ForeColor       = orangeColor;
            openSpecificationButton.Text            = "Open Specification";
            openSpecificationButton.Actions.MouseUp = new PdfJavaScriptAction("this.exportDataObject({ cName: 'Product Catalog.pdf', nLaunch: 2 });");
            document.Form.Fields.Add(openSpecificationButton);

            RectangleF     uriAnnotationRectangle = new RectangleF(interactivePage.Graphics.ClientSize.Width - 160, interactivePage.Graphics.ClientSize.Height - 30, 80, 20);
            PdfTextWebLink linkAnnot = new PdfTextWebLink();
            linkAnnot.Url   = "http://www.adventure-works.com";
            linkAnnot.Text  = "http://www.adventure-works.com";
            linkAnnot.Font  = new PdfStandardFont(PdfFontFamily.Helvetica, 8);
            linkAnnot.Brush = PdfBrushes.White;
            linkAnnot.DrawTextWebLink(interactivePage, uriAnnotationRectangle.Location);
            #endregion

            #region Footer
            g.DrawRectangle(purpleBrush, new RectangleF(0, interactivePage.Graphics.ClientSize.Height - 100, interactivePage.Graphics.ClientSize.Width, 100));
            g.DrawPie(whitePen, whiteBrush, new RectangleF(-20, interactivePage.Graphics.ClientSize.Height - 250, 700, 200), 0, 180);
            #endregion

            //Save the PDF to the MemoryStream
            MemoryStream ms = new MemoryStream();

            document.Save(ms);

            //If the position is not set to '0' then the PDF will be empty.
            ms.Position = 0;

            //Close the PDF document.
            document.Close(true);

            //Download the PDF document in the browser.
            FileStreamResult fileStreamResult = new FileStreamResult(ms, "application/pdf");
            fileStreamResult.FileDownloadName = "Interactive features.pdf";
            return(fileStreamResult);
        }
Ejemplo n.º 5
0
        public ActionResult Attachments(string Browser)
        {
            //Creates a new PDF document.
            PdfDocument doc = new PdfDocument();

            //Add a page
            PdfPage page = doc.Pages.Add();

            //Set the font
            PdfStandardFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 18f, PdfFontStyle.Bold);

            //Create new PDF color
            PdfColor orangeColor = new PdfColor(255, 255, 167, 73);

            //Draw the text
            page.Graphics.DrawString("Attachments", font, PdfBrushes.Black, new RectangleF(0, 0, page.GetClientSize().Width, page.GetClientSize().Height), new PdfStringFormat(PdfTextAlignment.Center));

            //Create font
            font = new PdfStandardFont(PdfFontFamily.Helvetica, 10f, PdfFontStyle.Regular);

            page.Graphics.DrawString("This PDF document contains image and text file as attachment.", font, PdfBrushes.Black, new PointF(0, 30));

            font = new PdfStandardFont(PdfFontFamily.Helvetica, 8f, PdfFontStyle.Regular);

            page.Graphics.DrawString("Click to open the attachment:", font, PdfBrushes.Black, new PointF(0, 50));

            page.Graphics.DrawString("Click to open the attachment:", font, PdfBrushes.Black, new PointF(0, 70));

            string basePath = _hostingEnvironment.WebRootPath;
            string dataPath = string.Empty;

            dataPath = basePath + @"/PDF/";

            //Read the file
            FileStream file = new FileStream(dataPath + "Text1.txt", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

            //Creates an attachment
            PdfAttachment attachment = new PdfAttachment("Text1.txt", file);

            attachment.ModificationDate = DateTime.Now;

            attachment.Description = "About Syncfusion";

            attachment.MimeType = "application/txt";

            //Adds the attachment to the document
            doc.Attachments.Add(attachment);

            file = new FileStream(dataPath + "Autumn Leaves.jpg", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

            //Creates an attachment
            attachment = new PdfAttachment("Autumn Leaves.jpg", file);

            attachment.ModificationDate = DateTime.Now;

            attachment.Description = "Autumn Leaves Image";

            attachment.MimeType = "application/jpg";

            doc.Attachments.Add(attachment);

            file = new FileStream(dataPath + "Text2.txt", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

            //Creates an attachment
            attachment = new PdfAttachment("Text2.txt", file);

            attachment.ModificationDate = DateTime.Now;

            attachment.Description = "List of Syncfusion Control";

            attachment.MimeType = "application/txt";

            doc.Attachments.Add(attachment);

            //Set document viewerpreference.
            doc.ViewerPreferences.HideWindowUI = false;
            doc.ViewerPreferences.HideMenubar  = false;
            doc.ViewerPreferences.HideToolbar  = false;
            doc.ViewerPreferences.FitWindow    = false;
            doc.ViewerPreferences.DisplayTitle = false;
            doc.ViewerPreferences.PageMode     = PdfPageMode.UseAttachments;

            //Disable the default appearance.
            doc.Form.SetDefaultAppearance(false);

            //Create pdfbuttonfield.
            PdfButtonField openSpecificationButton = new PdfButtonField(page, "openSpecification");

            openSpecificationButton.Bounds          = new RectangleF(105, 50, 62, 10);
            openSpecificationButton.TextAlignment   = PdfTextAlignment.Left;
            openSpecificationButton.Font            = new PdfStandardFont(PdfFontFamily.Helvetica, 7);
            openSpecificationButton.BorderStyle     = PdfBorderStyle.Underline;
            openSpecificationButton.BorderColor     = orangeColor;
            openSpecificationButton.BackColor       = new PdfColor(255, 255, 255);
            openSpecificationButton.ForeColor       = orangeColor;
            openSpecificationButton.Text            = "Autumn Leaves.jpg";
            openSpecificationButton.Actions.MouseUp = new PdfJavaScriptAction("this.exportDataObject({ cName: 'Autumn Leaves.jpg', nLaunch: 2 });");
            doc.Form.Fields.Add(openSpecificationButton);

            openSpecificationButton                 = new PdfButtonField(page, "openSpecification");
            openSpecificationButton.Bounds          = new RectangleF(105, 70, 30, 10);
            openSpecificationButton.TextAlignment   = PdfTextAlignment.Left;
            openSpecificationButton.Font            = new PdfStandardFont(PdfFontFamily.Helvetica, 7);
            openSpecificationButton.BorderStyle     = PdfBorderStyle.Underline;
            openSpecificationButton.BorderColor     = orangeColor;
            openSpecificationButton.BackColor       = new PdfColor(255, 255, 255);
            openSpecificationButton.ForeColor       = orangeColor;
            openSpecificationButton.Text            = "Text1.txt";
            openSpecificationButton.Actions.MouseUp = new PdfJavaScriptAction("this.exportDataObject({ cName: 'Text1.txt', nLaunch: 2 });");
            doc.Form.Fields.Add(openSpecificationButton);

            //Save the PDF to the MemoryStream
            MemoryStream ms = new MemoryStream();

            doc.Save(ms);

            //If the position is not set to '0' then the PDF will be empty.
            ms.Position = 0;

            //Close the PDF document.
            doc.Close(true);

            //Download the PDF document in the browser.
            FileStreamResult fileStreamResult = new FileStreamResult(ms, "application/pdf");

            fileStreamResult.FileDownloadName = "Attachments.pdf";
            return(fileStreamResult);
        }
Ejemplo n.º 6
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

            //margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins       margin   = new PdfMargins();

            margin.Top    = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left   = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right  = margin.Left;

            SetDocumentTemplate(doc, PdfPageSize.A4, margin);

            // Create one page
            PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, new PdfMargins(0));

            float y = 0;

            //title
            y = DrawPageTitle(page, y);

            //load form config data
            using (Stream stream = File.OpenRead(@"..\..\..\..\..\..\..\Data\Form.xml"))
            {
                XPathDocument     xpathDoc     = new XPathDocument(stream);
                XPathNodeIterator sectionNodes = xpathDoc.CreateNavigator().Select("/form/section");
                int fieldIndex = 0;
                foreach (XPathNavigator sectionNode in sectionNodes)
                {
                    //draw section label
                    String sectionLabel = sectionNode.GetAttribute("name", "");
                    y = DrawFormSection(sectionLabel, page, y);

                    XPathNodeIterator fieldNodes = sectionNode.Select("field");
                    foreach (XPathNavigator fieldNode in fieldNodes)
                    {
                        y = DrawFormField(fieldNode, doc.Form, page, y, fieldIndex++);
                    }
                }
            }

            //draw button
            y = y + 10;
            float          buttonWidth  = 80;
            float          buttonX      = (page.Canvas.ClientSize.Width - buttonWidth) / 2;
            RectangleF     buttonBounds = new RectangleF(buttonX, y, buttonWidth, 16f);
            PdfButtonField button       = new PdfButtonField(page, "submit");

            button.Text   = "Submit";
            button.Bounds = buttonBounds;
            PdfSubmitAction submitAction = new PdfSubmitAction("http://www.e-iceblue.com");

            button.Actions.MouseUp = submitAction;
            doc.Form.Fields.Add(button);

            //Save pdf file.
            doc.SaveToFile("FormField.pdf");
            doc.Close();

            //Launching the Pdf file.
            PDFDocumentViewer("FormField.pdf");
        }
Ejemplo n.º 7
0
        public ActionResult Attachments(string Browser)
        {
            //Creates a new PDF document.
            doc = new PdfDocument();

            //Add a page
            PdfPage page = doc.Pages.Add();

            //Set the font
            font = new PdfStandardFont(PdfFontFamily.Helvetica, 18f, PdfFontStyle.Bold);

            System.Drawing.Color orangeColor = System.Drawing.Color.FromArgb(255, 255, 167, 73);

            //Draw the text
            page.Graphics.DrawString("Attachments", font, PdfBrushes.Black, new RectangleF(0, 0, page.GetClientSize().Width, page.GetClientSize().Height), new PdfStringFormat(PdfTextAlignment.Center));

            font = new PdfStandardFont(PdfFontFamily.Helvetica, 10f, PdfFontStyle.Regular);

            page.Graphics.DrawString("This PDF document contains image and text file as attachment.", font, PdfBrushes.Black, new PointF(0, 30));

            font = new PdfStandardFont(PdfFontFamily.Helvetica, 8f, PdfFontStyle.Regular);

            page.Graphics.DrawString("Click to open the attachment:", font, PdfBrushes.Black, new PointF(0, 50));

            page.Graphics.DrawString("Click to open the attachment:", font, PdfBrushes.Black, new PointF(0, 70));

            //Creates an attachment
            PdfAttachment attachment = new PdfAttachment(ResolveApplicationDataPath("Text1.txt"));

            attachment.ModificationDate = DateTime.Now;

            attachment.Description = "About Syncfusion";

            attachment.MimeType = "application/txt";

            //Adds the attachment to the document
            doc.Attachments.Add(attachment);

            //Creates an attachment
            attachment = new PdfAttachment(ResolveApplicationImagePath("Autumn Leaves.jpg"));

            attachment.ModificationDate = DateTime.Now;

            attachment.Description = "Autumn Leaves Image";

            attachment.MimeType = "application/jpg";

            doc.Attachments.Add(attachment);

            //Creates an attachment
            attachment = new PdfAttachment(ResolveApplicationDataPath("Text2.txt"));

            attachment.ModificationDate = DateTime.Now;

            attachment.Description = "List of Syncfusion Control";

            attachment.MimeType = "application/txt";

            doc.Attachments.Add(attachment);

            //Set document viewerpreference.
            doc.ViewerPreferences.HideWindowUI = false;
            doc.ViewerPreferences.HideMenubar  = false;
            doc.ViewerPreferences.HideToolbar  = false;
            doc.ViewerPreferences.FitWindow    = false;
            doc.ViewerPreferences.DisplayTitle = false;
            doc.ViewerPreferences.PageMode     = PdfPageMode.UseAttachments;

            //Disable the default appearance.
            doc.Form.SetDefaultAppearance(false);

            //Create pdfbuttonfield.
            PdfButtonField openSpecificationButton = new PdfButtonField(page, "openSpecification");

            openSpecificationButton.Bounds          = new RectangleF(105, 50, 62, 10);
            openSpecificationButton.TextAlignment   = PdfTextAlignment.Left;
            openSpecificationButton.Font            = new PdfStandardFont(PdfFontFamily.Helvetica, 7);
            openSpecificationButton.BorderStyle     = PdfBorderStyle.Underline;
            openSpecificationButton.BorderColor     = orangeColor;
            openSpecificationButton.BackColor       = new PdfColor(255, 255, 255);
            openSpecificationButton.ForeColor       = orangeColor;
            openSpecificationButton.Text            = "Autumn Leaves.jpg";
            openSpecificationButton.Actions.MouseUp = new PdfJavaScriptAction("this.exportDataObject({ cName: 'Autumn Leaves.jpg', nLaunch: 2 });");
            doc.Form.Fields.Add(openSpecificationButton);

            openSpecificationButton                 = new PdfButtonField(page, "openSpecification");
            openSpecificationButton.Bounds          = new RectangleF(105, 70, 30, 10);
            openSpecificationButton.TextAlignment   = PdfTextAlignment.Left;
            openSpecificationButton.Font            = new PdfStandardFont(PdfFontFamily.Helvetica, 7);
            openSpecificationButton.BorderStyle     = PdfBorderStyle.Underline;
            openSpecificationButton.BorderColor     = orangeColor;
            openSpecificationButton.BackColor       = new PdfColor(255, 255, 255);
            openSpecificationButton.ForeColor       = orangeColor;
            openSpecificationButton.Text            = "Text1.txt";
            openSpecificationButton.Actions.MouseUp = new PdfJavaScriptAction("this.exportDataObject({ cName: 'Text1.txt', nLaunch: 2 });");
            doc.Form.Fields.Add(openSpecificationButton);

            //Stream the output to the browser.
            if (Browser == "Browser")
            {
                return(doc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open));
            }
            else
            {
                return(doc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save));
            }
        }
Ejemplo n.º 8
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document
            PdfDocument doc = new PdfDocument();

            //Create one page
            PdfPageBase page = doc.Pages.Add();

            page.Canvas.DrawString("Move the mouse cursor over the following text to display a tooltip", new PdfTrueTypeFont(new Font("Arial", 15), true), PdfBrushes.Black, new PointF(10, 20));

            //Define the text and its style
            String          text1  = "Your Office Development Master";
            PdfTrueTypeFont font1  = new PdfTrueTypeFont(new Font("Arial", 18), true);
            SizeF           sizeF1 = font1.MeasureString(text1);
            RectangleF      rec1   = new RectangleF(new Point(100, 100), sizeF1);

            //Draw text
            page.Canvas.DrawString(text1, font1, new PdfSolidBrush(Color.Blue), rec1);

            //Create invisible button on text position
            PdfButtonField field1 = new PdfButtonField(page, "field1");

            //Set the bounds and size of field
            field1.Bounds = rec1;
            //Set tooltip content
            field1.ToolTip = "E-iceblue Co. Ltd., a vendor of .NET, Java and WPF development components";
            //Set no border for field
            field1.BorderWidth = 0;
            //Set backcolor and forcolor for field
            field1.BackColor              = Color.Transparent;
            field1.ForeColor              = Color.Transparent;
            field1.LayoutMode             = PdfButtonLayoutMode.IconOnly;
            field1.IconLayout.IsFitBounds = true;

            //Define the text and its style
            String     text2  = "Spire.PDF";
            PdfFont    font2  = new PdfFont(PdfFontFamily.TimesRoman, 20);
            SizeF      sizeF2 = font2.MeasureString(text2);
            RectangleF rec2   = new RectangleF(new Point(100, 160), sizeF2);

            //Draw text
            page.Canvas.DrawString(text2, font2, PdfBrushes.DarkOrange, rec2);

            //Create invisible button on text position
            PdfButtonField field2 = new PdfButtonField(page, "field2");

            field2.Bounds  = rec2;
            field2.ToolTip = "A professional PDF library applied to creating," +
                             "writing, editing, handling and reading PDF files" +
                             "without any external dependencies within .NET" +
                             "( C#, VB.NET, ASP.NET, .NET Core) application.";
            field2.BorderWidth            = 0;
            field2.BackColor              = Color.Transparent;
            field2.ForeColor              = Color.Transparent;
            field2.LayoutMode             = PdfButtonLayoutMode.IconOnly;
            field2.IconLayout.IsFitBounds = true;

            //Add the buttons to pdf form
            doc.AllowCreateForm = true;
            doc.Form.Fields.Add(field1);
            doc.Form.Fields.Add(field2);

            String result = "AddTooltipToText_out.pdf";

            //Save the document
            doc.SaveToFile(result);
            //Launch the Pdf file
            PDFDocumentViewer(result);
        }
Ejemplo n.º 9
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

            //margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins margin = new PdfMargins();
            margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right = margin.Left;

            SetDocumentTemplate(doc, PdfPageSize.A4, margin);

            // Create one page
            PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, new PdfMargins(0));

            float y = 0;

            //title
            y = DrawPageTitle(page, y);

            //load form config data
            using (Stream stream = File.OpenRead(@"..\..\..\..\..\..\Data\Form.xml"))
            {
                XPathDocument xpathDoc = new XPathDocument(stream);
                XPathNodeIterator sectionNodes = xpathDoc.CreateNavigator().Select("/form/section");
                int fieldIndex = 0;
                foreach (XPathNavigator sectionNode in sectionNodes)
                {
                    //draw section label
                    String sectionLabel = sectionNode.GetAttribute("name", "");
                    y = DrawFormSection(sectionLabel, page, y);

                    XPathNodeIterator fieldNodes = sectionNode.Select("field");
                    foreach (XPathNavigator fieldNode in fieldNodes)
                    {
                        y= DrawFormField(fieldNode, doc.Form, page, y, fieldIndex++);
                    }
                }
            }

            //draw button
            y = y + 10;
            float buttonWidth = 80;
            float buttonX = (page.Canvas.ClientSize.Width - buttonWidth) / 2;
            RectangleF buttonBounds = new RectangleF(buttonX, y, buttonWidth, 16f);
            PdfButtonField button = new PdfButtonField(page, "submit");
            button.Text = "Submit";
            button.Bounds = buttonBounds;
            PdfSubmitAction submitAction = new PdfSubmitAction("http://www.e-iceblue.com");
            button.Actions.MouseUp = submitAction;
            doc.Form.Fields.Add(button);

            //Save pdf file.
            doc.SaveToFile("FormField.pdf");
            doc.Close();

            //Launching the Pdf file.
            PDFDocumentViewer("FormField.pdf");
        }