Exemple #1
0
        private static void CreateDocumentActions(PdfFixedDocument document)
        {
            // Create an action that will open the document at the last page with 200% zoom.
            PdfPageDirectDestination pageDestination = new PdfPageDirectDestination();

            pageDestination.Page = document.Pages[document.Pages.Count - 1];
            pageDestination.Zoom = 200;
            pageDestination.Top  = 0;
            pageDestination.Left = 0;
            PdfGoToAction openAction = new PdfGoToAction();

            openAction.Destination = pageDestination;
            document.OpenAction    = openAction;

            // Create an action that is executed when the document is closed.
            PdfJavaScriptAction jsCloseAction = new PdfJavaScriptAction();

            jsCloseAction.Script       = "app.alert({cMsg: \"The document will close now.\", cTitle: \"Xfinium.Pdf Actions Sample\"});";
            document.BeforeCloseAction = jsCloseAction;

            // Create an action that is executed before the document is printed.
            PdfJavaScriptAction jsBeforePrintAction = new PdfJavaScriptAction();

            jsBeforePrintAction.Script = "app.alert({cMsg: \"The document will be printed.\", cTitle: \"Xfinium.Pdf Actions Sample\"});";
            document.BeforePrintAction = jsBeforePrintAction;

            // Create an action that is executed after the document is printed.
            PdfJavaScriptAction jsAfterPrintAction = new PdfJavaScriptAction();

            jsAfterPrintAction.Script = "app.alert({cMsg: \"The document has been printed.\", cTitle: \"Xfinium.Pdf Actions Sample\"});";
            document.AfterPrintAction = jsAfterPrintAction;
        }
Exemple #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            String      input = "..\\..\\..\\..\\..\\..\\Data\\PDFTemplate-Az.pdf";
            PdfDocument doc   = new PdfDocument();

            // Read a pdf file
            doc.LoadFromFile(input);

            string javaScript = "var rightNow = new Date();"

                                + "var endDate = new Date('October 20, 2015 23:59:59');"

                                + "if(rightNow.getTime() > endDate)"

                                + "app.alert('This document has expired, please contact us for a new one.',1);"

                                + "this.closeDoc();";

            PdfJavaScriptAction js = new PdfJavaScriptAction(javaScript);

            doc.AfterOpenAction = js;


            String result = "SetExpiryDate_out.pdf";

            //Save the document
            doc.SaveToFile(result);
            //Launch the Pdf file
            PDFDocumentViewer(result);
        }
Exemple #3
0
        private static void CreateJavaScriptActions(PdfFixedDocument document, PdfFont font)
        {
            PdfPen   blackPen   = new PdfPen(new PdfRgbColor(0, 0, 0), 1);
            PdfBrush blackBrush = new PdfBrush();

            font.Size = 12;
            PdfStringAppearanceOptions sao = new PdfStringAppearanceOptions();

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

            slo.HorizontalAlign = PdfStringHorizontalAlign.Center;
            slo.VerticalAlign   = PdfStringVerticalAlign.Middle;

            for (int i = 0; i < document.Pages.Count; i++)
            {
                document.Pages[i].Graphics.DrawString("JavaScript actions:", font, blackBrush, 400, 480);

                document.Pages[i].Graphics.DrawRectangle(blackPen, 400, 500, 200, 20);
                slo.X = 500;
                slo.Y = 510;
                document.Pages[i].Graphics.DrawString("Click me", sao, slo);

                // Create a link annotation on top of the widget.
                PdfLinkAnnotation link = new PdfLinkAnnotation();
                document.Pages[i].Annotations.Add(link);
                link.VisualRectangle = new PdfVisualRectangle(400, 500, 200, 20);

                // Create a Javascript action and attach it to the link.
                PdfJavaScriptAction jsAction = new PdfJavaScriptAction();
                jsAction.Script = "app.alert({cMsg: \"JavaScript action: you are now on page " + (i + 1) + "\", cTitle: \"Xfinium.Pdf Actions Sample\"});";
                link.Action     = jsAction;
            }
        }
Exemple #4
0
        private static void CreateDocumentActions(PdfFixedDocument document)
        {
            // Create an action that will open the document at the last page with 200% zoom.
            PdfPageDirectDestination pageDestination = new PdfPageDirectDestination();
            pageDestination.Page = document.Pages[document.Pages.Count - 1];
            pageDestination.Zoom = 200;
            pageDestination.Top = 0;
            pageDestination.Left = 0;
            PdfGoToAction openAction = new PdfGoToAction();
            openAction.Destination = pageDestination;
            document.OpenAction = openAction;

            // Create an action that is executed when the document is closed.
            PdfJavaScriptAction jsCloseAction = new PdfJavaScriptAction();
            jsCloseAction.Script = "app.alert({cMsg: \"The document will close now.\", cTitle: \"Xfinium.Pdf Actions Sample\"});";
            document.BeforeCloseAction = jsCloseAction;

            // Create an action that is executed before the document is printed.
            PdfJavaScriptAction jsBeforePrintAction = new PdfJavaScriptAction();
            jsBeforePrintAction.Script = "app.alert({cMsg: \"The document will be printed.\", cTitle: \"Xfinium.Pdf Actions Sample\"});";
            document.BeforePrintAction = jsBeforePrintAction;

            // Create an action that is executed after the document is printed.
            PdfJavaScriptAction jsAfterPrintAction = new PdfJavaScriptAction();
            jsAfterPrintAction.Script = "app.alert({cMsg: \"The document has been printed.\", cTitle: \"Xfinium.Pdf Actions Sample\"});";
            document.AfterPrintAction = jsAfterPrintAction;
        }
Exemple #5
0
        private void button1_Click(object sender, EventArgs e)
        {
            string input = @"..\..\..\..\..\..\Data\FormFieldTemplate.pdf";

            //Open pdf document
            PdfDocument pdf = new PdfDocument();

            pdf.LoadFromFile(input);

            //Get the first page
            PdfPageBase page = pdf.Pages[0];

            //As for existing pdf, the property needs to be set as true
            pdf.AllowCreateForm = true;

            //Create a new pdf font
            PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 12f, PdfFontStyle.Bold);

            //Create a pdf brush
            PdfBrush brush = PdfBrushes.Black;

            float x     = 50;
            float y     = 550;
            float tempX = 0;

            //Draw a text into page
            string text1 = "Enter a number, such as 12345: ";

            //Draw a text into page
            page.Canvas.DrawString(text1, font, brush, x, y);

            //Add a textBox field
            tempX = font.MeasureString(text1).Width + x + 15;
            PdfTextBoxField textbox = new PdfTextBoxField(page, "Number-TextBox");

            textbox.Bounds      = new RectangleF(tempX, y, 100, 15);
            textbox.BorderWidth = 0.75f;
            textbox.BorderStyle = PdfBorderStyle.Solid;

            //Add a JavaScript action to be performed when uses type a keystroke into a text field
            string js = PdfJavaScript.GetNumberKeystrokeString(2, 0, 0, 0, "$", true);
            PdfJavaScriptAction jsAction = new PdfJavaScriptAction(js);

            textbox.Actions.KeyPressed = jsAction;

            //Add a JavaScript action to format the value of text field
            js       = PdfJavaScript.GetNumberFormatString(2, 0, 0, 0, "$", true);
            jsAction = new PdfJavaScriptAction(js);
            textbox.Actions.Format = jsAction;
            pdf.Form.Fields.Add(textbox);

            //Save and launch the result file
            string output = "AddJavaScriptAction_out.pdf";

            //Save to file
            pdf.SaveToFile(output);

            //Launch the Pdf file
            PDFDocumentViewer(output);
        }
        /// <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();

            //Draw pages
            PdfPageBase lastPage = DrawPages(doc);

            //script
            String script
                = "app.alert({"
                  + "    cMsg: \"I'll lead; you must follow me.\","
                  + "    nIcon: 3,"
                  + "    cTitle: \"JavaScript Action\""
                  + "});";
            PdfJavaScriptAction action1 = new PdfJavaScriptAction(script);

            doc.AfterOpenAction = action1;

            //script
            script
                = "app.alert({"
                  + "    cMsg: \"The firt page!\","
                  + "    nIcon: 3,"
                  + "    cTitle: \"JavaScript Action\""
                  + "});";
            PdfJavaScriptAction action2 = new PdfJavaScriptAction(script);

            action1.NextAction = action2;

            PdfDestination dest = new PdfDestination(lastPage);

            dest.Zoom = 1;
            PdfGoToAction action3 = new PdfGoToAction(dest);

            action2.NextAction = action3;

            //script
            script
                = "app.alert({"
                  + "    cMsg: \"Oh sorry, it's the last page. I'm missing!\","
                  + "    nIcon: 3,"
                  + "    cTitle: \"JavaScript Action\""
                  + "});";
            PdfJavaScriptAction action4 = new PdfJavaScriptAction(script);

            action3.NextAction = action4;

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

            //Launching the Pdf file.
            PDFDocumentViewer("ActionChain.pdf");
        }
Exemple #8
0
        void table_BeginCellLayout(object sender, BeginCellLayoutEventArgs args)
        {
            if (args.CellIndex == 2 && args.RowIndex > -1)
            {
                CreateTextBox(interactivePage, "price" + args.RowIndex.ToString(), "Price", args.Bounds, true, args.Value);
                args.Skip = true;
            }
            else if (args.CellIndex == 3 && args.RowIndex == -1)
            {
                PdfPopupAnnotation popupAnnotation = new PdfPopupAnnotation(new RectangleF(args.Bounds.Right - 18, args.Bounds.Top + 2, 1, 1),
                                                                            "Please enter a validate interger between 1 to 50");
                popupAnnotation.Border.Width            = 4;
                popupAnnotation.Open                    = false;
                popupAnnotation.Border.HorizontalRadius = 10;
                popupAnnotation.Border.VerticalRadius   = 10;
                popupAnnotation.Icon                    = PdfPopupIcon.Comment;
                interactivePage.Annotations.Add(popupAnnotation);
            }
            else if (args.CellIndex == 3 && args.RowIndex > -1)
            {
                PdfTextBoxField textBoxField = new PdfTextBoxField(interactivePage, "quantity" + args.RowIndex.ToString());


                //Set properties to the textbox.
                textBoxField.Font        = new PdfStandardFont(PdfFontFamily.Helvetica, 12);;
                textBoxField.BorderColor = new PdfColor(white);
                textBoxField.BackColor   = Syncfusion.Drawing.Color.FromArgb(255, 238, 238, 248);
                textBoxField.Bounds      = args.Bounds;
                textBoxField.Text        = "0";
                PdfJavaScriptAction action = new PdfJavaScriptAction(@"event.rc = event.value > -1 && event.value < 51; 
                var f = this.getField('price" + args.RowIndex.ToString() + @"')
                var f1 = this.getField('quantity" + args.RowIndex.ToString() + @"')
                var f2 = this.getField('TotalPrice" + args.RowIndex.ToString() + @"')
                var f3 = this.getField('GrandTotal');
                if(!event.rc)
                {

                f1.fillColor=color.red;
                app.beep();
                }
                else
                {
                    f1.fillColor = color.transparent;
                    f2.value = f1.value * f.value;
                    f3.value = this.getField('TotalPrice0').value + this.getField('TotalPrice1').value + this.getField('TotalPrice2').value + this.getField('TotalPrice3').value + this.getField('TotalPrice4').value +this.getField('TotalPrice5').value;
                }");
                textBoxField.Actions.LostFocus = action;
                document.Form.Fields.Add(textBoxField);
            }
            else if (args.CellIndex == 4 && args.RowIndex > -1)
            {
                CreateTextBox(interactivePage, "TotalPrice" + args.RowIndex.ToString(), "Total Price", args.Bounds, true, "0");
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

            //Draw pages
            PdfPageBase lastPage = DrawPages(doc);

            //script
            String script
                = "app.alert({"
                + "    cMsg: \"I'll lead; you must follow me.\","
                + "    nIcon: 3,"
                + "    cTitle: \"JavaScript Action\""
                + "});";
            PdfJavaScriptAction action1 = new PdfJavaScriptAction(script);
            doc.AfterOpenAction = action1;

            //script
            script
                = "app.alert({"
                + "    cMsg: \"The firt page!\","
                + "    nIcon: 3,"
                + "    cTitle: \"JavaScript Action\""
                + "});";
            PdfJavaScriptAction action2 = new PdfJavaScriptAction(script);
            action1.NextAction = action2;

            PdfDestination dest = new PdfDestination(lastPage);
            dest.Zoom = 1;
            PdfGoToAction action3 = new PdfGoToAction(dest);
            action2.NextAction = action3;

            //script
            script
                = "app.alert({"
                + "    cMsg: \"Oh sorry, it's the last page. I'm missing!\","
                + "    nIcon: 3,"
                + "    cTitle: \"JavaScript Action\""
                + "});";
            PdfJavaScriptAction action4 = new PdfJavaScriptAction(script);
            action3.NextAction = action4;

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

            //Launching the Pdf file.
            PDFDocumentViewer("ActionChain.pdf");
        }
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document
            PdfDocument pdf = new PdfDocument();

            //Load a pdf document
            pdf.LoadFromFile(@"..\..\..\..\..\..\Data\ExtractJavaScript.pdf");

            string js = null;

            PdfFormWidget form = pdf.Form as PdfFormWidget;

            for (int i = 0; i < form.FieldsWidget.List.Count; i++)
            {
                PdfField field = form.FieldsWidget.List[i] as PdfField;
                if (field is PdfTextBoxFieldWidget)
                {
                    PdfTextBoxFieldWidget textbox = field as PdfTextBoxFieldWidget;

                    //Find the textbox named total
                    if (textbox.Name == "total")
                    {
                        //Get the action
                        PdfJavaScriptAction jsa = textbox.Actions.Calculate;

                        if (jsa != null)
                        {
                            //Get JavaScript
                            js = jsa.Script;
                        }
                    }
                }
            }

            //Save and launch the result file
            File.WriteAllText("ExtractJavaScript.txt", js);
            System.Diagnostics.Process.Start("ExtractJavaScript.txt");
        }
        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;

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

            float           y      = 10;
            float           x      = 0;
            PdfTrueTypeFont font   = new PdfTrueTypeFont(new Font("Arial", 12));
            String          label  = "Simple Link: ";
            PdfStringFormat format = new PdfStringFormat();

            format.MeasureTrailingSpaces = true;
            page.Canvas.DrawString(label, font, PdfBrushes.OrangeRed, 0, y, format);
            x = font.MeasureString(label, format).Width;
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 12, FontStyle.Underline));
            String          url1  = "http://www.e-iceblue.com";

            page.Canvas.DrawString(url1, font1, PdfBrushes.Blue, x, y);
            y = y + font1.MeasureString(url1).Height;

            label = "Web Link: ";
            page.Canvas.DrawString(label, font, PdfBrushes.OrangeRed, 0, y, format);
            x = font.MeasureString(label, format).Width;
            String         text  = "e-iceblue";
            PdfTextWebLink link2 = new PdfTextWebLink();

            link2.Text  = text;
            link2.Url   = url1;
            link2.Font  = font1;
            link2.Brush = PdfBrushes.Blue;
            link2.DrawTextWebLink(page.Canvas, new PointF(x, y));
            y = y + font1.MeasureString(text).Height;

            label = "URI Annonationa: ";
            page.Canvas.DrawString(label, font, PdfBrushes.OrangeRed, 0, y, format);
            x    = font.MeasureString(label, format).Width;
            text = "Google";
            PointF           location   = new PointF(x, y);
            SizeF            size       = font1.MeasureString(text);
            RectangleF       linkBounds = new RectangleF(location, size);
            PdfUriAnnotation link3      = new PdfUriAnnotation(linkBounds);

            link3.Border = new PdfAnnotationBorder(0);
            link3.Uri    = "http://www.google.com";
            (page as PdfNewPage).Annotations.Add(link3);
            page.Canvas.DrawString(text, font1, PdfBrushes.Blue, x, y);
            y = y + size.Height;

            label = "URI Annonationa Action: ";
            page.Canvas.DrawString(label, font, PdfBrushes.OrangeRed, 0, y, format);
            x          = font.MeasureString(label, format).Width;
            text       = "JavaScript Action (Click Me)";
            location   = new PointF(x, y);
            size       = font1.MeasureString(text);
            linkBounds = new RectangleF(location, size);
            PdfUriAnnotation link4 = new PdfUriAnnotation(linkBounds);

            link4.Border = new PdfAnnotationBorder(0.75f);
            link4.Color  = Color.LightGray;
            //script
            String script
                = "app.alert({"
                  + "    cMsg: \"Hello.\","
                  + "    nIcon: 3,"
                  + "    cTitle: \"JavaScript Action\""
                  + "});";
            PdfJavaScriptAction action = new PdfJavaScriptAction(script);

            link4.Action = action;
            (page as PdfNewPage).Annotations.Add(link4);
            page.Canvas.DrawString(text, font1, PdfBrushes.Blue, x, y);
            y = y + size.Height;

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

            //Launching the Pdf file.
            PDFDocumentViewer("Link.pdf");
        }
Exemple #12
0
        public async Task <IActionResult> SetPdfExpiration(int id)
        {
            var      invalidChars = Path.GetInvalidFileNameChars();
            Document doc          = await _unitOfWork.Documents.GetDocumentByIdAsync(id);

            var expDate = DateTime.Now.AddDays(2);

            doc.ExpiryDate = expDate;
            PdfJavaScriptAction scriptAction = BuildExpireJSFunc(doc);
            string saveAs = await GetFullPath(doc.FolderId, doc.DocumentName + "." + doc.MimeType);

            //this key is what the new pdf with the expiration function attached to it will be renamed with
            var expKey = SystemConstants.ExpiryKey;

            //03.23.2020 network path
            string userPath = _networkDocPath + _userSession.FirstName + _userSession.LastName + _userSession.Id + "\\";

            //string userPath = _hostingEnv.WebRootPath + "\\UploadFiles\\" + _userSession.FirstName + _userSession.LastName + _userSession.Id + "\\";


            if (!Directory.Exists(userPath))
            {
                Directory.CreateDirectory(userPath);
            }
            else
            {
                DeleteOldDirectoryFiles(userPath);
            }
            string expPath = "";

            try
            {
                //03.23.2020 network path _hostingEnv.WebRootPath + "\\"
                using (FileStream fs = new FileStream(doc.Path, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
                {
                    if (doc.MimeType == "pdf")
                    {
                        PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fs);

                        PdfDocument document = new PdfDocument();
                        PdfDocument.Merge(document, loadedDocument);
                        string validFileName = new string(doc.DocumentName
                                                          .Where(x => !invalidChars.Contains(x))
                                                          .ToArray());

                        if (doc.DocId > 0)
                        {
                            document.Actions.AfterOpen = scriptAction;
                        }

                        doc.Path = await GetRelativePath(doc.FolderId, validFileName + "." + doc.MimeType);

                        expPath = userPath + validFileName + "." + doc.MimeType;

                        if (System.IO.File.Exists(expPath))
                        {
                            System.IO.File.Delete(expPath);
                        }
                        //  FileStream outputStream = new FileStream(expPath, FileMode.CreateNew);
                        using (FileStream outputStream = new FileStream(expPath, FileMode.CreateNew))
                        {
                            document.Save(outputStream);
                            document.Close(true);
                            loadedDocument.Close(true);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            var pdfPaths = new PdfViewerViewModel
            {
                ReadOnlyPath = doc.Path,
                DownloadPath = expPath
            };
            var        userAgent = Request.Headers["User-Agent"];
            string     uaString  = Convert.ToString(userAgent[0]);
            var        uaParser  = Parser.GetDefault();
            ClientInfo c         = uaParser.Parse(uaString);
            //if (c.UserAgent.Family == "IE")
            //{
            //    return RedirectToAction("Download", "Documents", new { docPath = pdfPaths.DownloadPath, ieDownload = true });
            //}
            //else
            //{
            //    return RedirectToAction("Index", "PdfViewer", pdfPaths);
            //}

            var stream = new FileStream(pdfPaths.ReadOnlyPath, FileMode.Open);


            ////return File(stream, "application/pdf","test.pdf");

            //return new FileStreamResult(stream, "application/pdf");

            //ProcessStartInfo info = new ProcessStartInfo();
            //info.Verb = "Open";
            //info.FileName = @"C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe";
            ////info.FileName = @"C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe";
            ////info.Arguments = String.Format(@"/p /h {0}", pdfPaths.DownloadPath);
            //info.CreateNoWindow = false;
            //info.WindowStyle = ProcessWindowStyle.Hidden;
            //info.UseShellExecute = true;

            //info.Arguments = String.Format(pdfPaths.DownloadPath);
            //Process p = Process.Start(info);
            //pdfPaths.DownloadPath = @"D:\test.pdf";

            //return RedirectToAction("Index", "PdfViewer", pdfPaths);
            return(new FileStreamResult(stream, "application/pdf"));
        }
Exemple #13
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;

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

            float y = 10;
            float x = 0;
            PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 12));
            String label = "Simple Link: ";
            PdfStringFormat format = new PdfStringFormat();
            format.MeasureTrailingSpaces = true;
            page.Canvas.DrawString(label, font, PdfBrushes.OrangeRed, 0, y, format);
            x = font.MeasureString(label, format).Width;
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 12, FontStyle.Underline));
            String url1 = "http://www.e-iceblue.com";
            page.Canvas.DrawString(url1, font1, PdfBrushes.Blue, x, y);
            y = y + font1.MeasureString(url1).Height;

            label = "Web Link: ";
            page.Canvas.DrawString(label, font, PdfBrushes.OrangeRed, 0, y, format);
            x = font.MeasureString(label, format).Width;
            String text = "e-iceblue";
            PdfTextWebLink link2 = new PdfTextWebLink();
            link2.Text = text;
            link2.Url = url1;
            link2.Font = font1;
            link2.Brush = PdfBrushes.Blue;
            link2.DrawTextWebLink(page.Canvas, new PointF(x, y));
            y = y + font1.MeasureString(text).Height;

            label = "URI Annonationa: ";
            page.Canvas.DrawString(label, font, PdfBrushes.OrangeRed, 0, y, format);
            x = font.MeasureString(label, format).Width;
            text = "Google";
            PointF location = new PointF(x, y);
            SizeF size = font1.MeasureString(text);
            RectangleF linkBounds = new RectangleF(location, size);
            PdfUriAnnotation link3 = new PdfUriAnnotation(linkBounds);
            link3.Border = new PdfAnnotationBorder(0);
            link3.Uri = "http://www.google.com";
            (page as PdfNewPage).Annotations.Add(link3);
            page.Canvas.DrawString(text, font1, PdfBrushes.Blue, x, y);
            y = y + size.Height;

            label = "URI Annonationa Action: ";
            page.Canvas.DrawString(label, font, PdfBrushes.OrangeRed, 0, y, format);
            x = font.MeasureString(label, format).Width;
            text = "JavaScript Action (Click Me)";
            location = new PointF(x, y);
            size = font1.MeasureString(text);
            linkBounds = new RectangleF(location, size);
            PdfUriAnnotation link4 = new PdfUriAnnotation(linkBounds);
            link4.Border = new PdfAnnotationBorder(0.75f);
            link4.Color = Color.LightGray;
            //script
            String script
                = "app.alert({"
                + "    cMsg: \"Hello.\","
                + "    nIcon: 3,"
                + "    cTitle: \"JavaScript Action\""
                + "});";
            PdfJavaScriptAction action = new PdfJavaScriptAction(script);
            link4.Action = action;
            (page as PdfNewPage).Annotations.Add(link4);
            page.Canvas.DrawString(text, font1, PdfBrushes.Blue, x, y);
            y = y + size.Height;

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

            //Launching the Pdf file.
            PDFDocumentViewer("Link.pdf");
        }
Exemple #14
0
        /// <summary>
        /// Main method for running the sample.
        /// </summary>
        public static SampleOutputInfo[] Run()
        {
            PdfFixedDocument document = new PdfFixedDocument();
            PdfStandardFont helvetica = new PdfStandardFont(PdfStandardFontFace.Helvetica, 12);
            PdfBrush brush = new PdfBrush();

            PdfPage page = document.Pages.Add();

            // First name
            page.Graphics.DrawString("First name:", helvetica, brush, 50, 50);
            PdfTextBoxField firstNameTextBox = new PdfTextBoxField("firstname");
            page.Fields.Add(firstNameTextBox);
            firstNameTextBox.Widgets[0].Font = helvetica;
            firstNameTextBox.Widgets[0].VisualRectangle = new PdfVisualRectangle(150, 45, 200, 20);
            firstNameTextBox.Widgets[0].BorderColor = PdfRgbColor.Black;
            firstNameTextBox.Widgets[0].BorderWidth = 1;

            // Last name
            page.Graphics.DrawString("Last name:", helvetica, brush, 50, 80);
            PdfTextBoxField lastNameTextBox = new PdfTextBoxField("lastname");
            page.Fields.Add(lastNameTextBox);
            lastNameTextBox.Widgets[0].Font = helvetica;
            lastNameTextBox.Widgets[0].VisualRectangle = new PdfVisualRectangle(150, 75, 200, 20);
            lastNameTextBox.Widgets[0].BorderColor = PdfRgbColor.Black;
            lastNameTextBox.Widgets[0].BorderWidth = 1;

            // Sex
            page.Graphics.DrawString("Sex:", helvetica, brush, 50, 110);
            PdfRadioButtonField sexRadioButton = new PdfRadioButtonField("sex");
            PdfRadioButtonWidget maleRadioItem = new PdfRadioButtonWidget();
            sexRadioButton.Widgets.Add(maleRadioItem);
            PdfRadioButtonWidget femaleRadioItem = new PdfRadioButtonWidget();
            sexRadioButton.Widgets.Add(femaleRadioItem);
            page.Fields.Add(sexRadioButton);

            page.Graphics.DrawString("Male", helvetica, brush, 180, 110);
            maleRadioItem.ExportValue = "M";
            maleRadioItem.CheckStyle = PdfCheckStyle.Circle;
            maleRadioItem.VisualRectangle = new PdfVisualRectangle(150, 105, 20, 20);
            maleRadioItem.BorderColor = PdfRgbColor.Black;
            maleRadioItem.BorderWidth = 1;

            page.Graphics.DrawString("Female", helvetica, brush, 280, 110);
            femaleRadioItem.ExportValue = "F";
            femaleRadioItem.CheckStyle = PdfCheckStyle.Circle;
            femaleRadioItem.VisualRectangle = new PdfVisualRectangle(250, 105, 20, 20);
            femaleRadioItem.BorderColor = PdfRgbColor.Black;
            femaleRadioItem.BorderWidth = 1;

            // First car
            page.Graphics.DrawString("First car:", helvetica, brush, 50, 140);
            PdfComboBoxField firstCarList = new PdfComboBoxField("firstcar");
            firstCarList.Items.Add(new PdfListItem("Mercedes", "Mercedes"));
            firstCarList.Items.Add(new PdfListItem("BMW", "BMW"));
            firstCarList.Items.Add(new PdfListItem("Audi", "Audi"));
            firstCarList.Items.Add(new PdfListItem("Volkswagen", "Volkswagen"));
            firstCarList.Items.Add(new PdfListItem("Porsche", "Porsche"));
            firstCarList.Items.Add(new PdfListItem("Honda", "Honda"));
            firstCarList.Items.Add(new PdfListItem("Toyota", "Toyota"));
            firstCarList.Items.Add(new PdfListItem("Lexus", "Lexus"));
            firstCarList.Items.Add(new PdfListItem("Infiniti", "Infiniti"));
            firstCarList.Items.Add(new PdfListItem("Acura", "Acura"));
            page.Fields.Add(firstCarList);
            firstCarList.Widgets[0].Font = helvetica;
            firstCarList.Widgets[0].VisualRectangle = new PdfVisualRectangle(150, 135, 200, 20);
            firstCarList.Widgets[0].BorderColor = PdfRgbColor.Black;
            firstCarList.Widgets[0].BorderWidth = 1;

            // Second car
            page.Graphics.DrawString("Second car:", helvetica, brush, 50, 170);
            PdfListBoxField secondCarList = new PdfListBoxField("secondcar");
            secondCarList.Items.Add(new PdfListItem("Mercedes", "Mercedes"));
            secondCarList.Items.Add(new PdfListItem("BMW", "BMW"));
            secondCarList.Items.Add(new PdfListItem("Audi", "Audi"));
            secondCarList.Items.Add(new PdfListItem("Volkswagen", "Volkswagen"));
            secondCarList.Items.Add(new PdfListItem("Porsche", "Porsche"));
            secondCarList.Items.Add(new PdfListItem("Honda", "Honda"));
            secondCarList.Items.Add(new PdfListItem("Toyota", "Toyota"));
            secondCarList.Items.Add(new PdfListItem("Lexus", "Lexus"));
            secondCarList.Items.Add(new PdfListItem("Infiniti", "Infiniti"));
            secondCarList.Items.Add(new PdfListItem("Acura", "Acura"));
            page.Fields.Add(secondCarList);
            secondCarList.Widgets[0].Font = helvetica;
            secondCarList.Widgets[0].VisualRectangle = new PdfVisualRectangle(150, 165, 200, 60);
            secondCarList.Widgets[0].BorderColor = PdfRgbColor.Black;
            secondCarList.Widgets[0].BorderWidth = 1;

            // I agree
            page.Graphics.DrawString("I agree:", helvetica, brush, 50, 240);
            PdfCheckBoxField agreeCheckBox = new PdfCheckBoxField("agree");
            page.Fields.Add(agreeCheckBox);
            agreeCheckBox.Widgets[0].Font = helvetica;
            (agreeCheckBox.Widgets[0] as PdfCheckWidget).ExportValue = "YES";
            (agreeCheckBox.Widgets[0] as PdfCheckWidget).CheckStyle = PdfCheckStyle.Check;
            agreeCheckBox.Widgets[0].VisualRectangle = new PdfVisualRectangle(150, 235, 20, 20);
            agreeCheckBox.Widgets[0].BorderColor = PdfRgbColor.Black;
            agreeCheckBox.Widgets[0].BorderWidth = 1;

            // Sign here
            page.Graphics.DrawString("Sign here:", helvetica, brush, 50, 270);
            PdfSignatureField signHereField = new PdfSignatureField("signhere");
            page.Fields.Add(signHereField);
            signHereField.Widgets[0].Font = helvetica;
            signHereField.Widgets[0].VisualRectangle = new PdfVisualRectangle(150, 265, 200, 60);

            // Submit form
            PdfPushButtonField submitBtn = new PdfPushButtonField("submit");
            page.Fields.Add(submitBtn);
            submitBtn.Widgets[0].VisualRectangle = new PdfVisualRectangle(450, 45, 150, 30);
            (submitBtn.Widgets[0] as PdfPushButtonWidget).Caption = "Submit form";
            submitBtn.Widgets[0].BackgroundColor = PdfRgbColor.LightGray;
            PdfSubmitFormAction submitFormAction = new PdfSubmitFormAction();
            submitFormAction.DataFormat = PdfSubmitDataFormat.FDF;
            submitFormAction.Fields.Add("firstname");
            submitFormAction.Fields.Add("lastname");
            submitFormAction.Fields.Add("sex");
            submitFormAction.Fields.Add("firstcar");
            submitFormAction.Fields.Add("secondcar");
            submitFormAction.Fields.Add("agree");
            submitFormAction.Fields.Add("signhere");
            submitFormAction.SubmitFields = true;
            submitFormAction.Url = "http://www.xfiniumsoft.com/";
            submitBtn.Widgets[0].MouseUp = submitFormAction;

            // Reset form
            PdfPushButtonField resetBtn = new PdfPushButtonField("reset");
            page.Fields.Add(resetBtn);
            resetBtn.Widgets[0].VisualRectangle = new PdfVisualRectangle(450, 85, 150, 30);
            (resetBtn.Widgets[0] as PdfPushButtonWidget).Caption = "Reset form";
            resetBtn.Widgets[0].BackgroundColor = PdfRgbColor.LightGray;
            PdfResetFormAction resetFormAction = new PdfResetFormAction();
            resetBtn.Widgets[0].MouseUp = resetFormAction;

            // Print form
            PdfPushButtonField printBtn = new PdfPushButtonField("print");
            page.Fields.Add(printBtn);
            printBtn.Widgets[0].VisualRectangle = new PdfVisualRectangle(450, 125, 150, 30);
            (printBtn.Widgets[0] as PdfPushButtonWidget).Caption = "Print form";
            printBtn.Widgets[0].BackgroundColor = PdfRgbColor.LightGray;
            PdfJavaScriptAction printAction = new PdfJavaScriptAction();
            printAction.Script = "this.print(true);\n";
            printBtn.Widgets[0].MouseUp = printAction;

            SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.formgenerator.pdf") };
            return output;
        }
Exemple #15
0
        protected void buttonCreatePdf_Click(object sender, EventArgs e)
        {
            // create a PDF document
            PdfDocument document = new PdfDocument();

            // set a demo serial number
            document.SerialNumber = "YCgJMTAE-BiwJAhIB-EhlWTlBA-UEBRQFBA-U1FOUVJO-WVlZWQ==";

            // create the true type fonts that can be used in document
            System.Drawing.Font ttfFont           = new System.Drawing.Font("Times New Roman", 10, System.Drawing.GraphicsUnit.Point);
            PdfFont             newTimesFont      = document.CreateFont(ttfFont);
            PdfFont             newTimesFontEmbed = document.CreateFont(ttfFont, true);

            // create page 1
            PdfPage page1 = document.AddPage();
            // create a text object to be laid out on this page
            PdfText text1 = new PdfText(10, 10, "This is the Page 1 of the document with Open action", newTimesFontEmbed);

            // layout the text
            page1.Layout(text1);

            // create page 2
            PdfPage page2 = document.AddPage();
            // create a text object to be laid out on this page
            PdfText text2 = new PdfText(10, 10, "This is the Page 2 of the document with Open action", newTimesFontEmbed);

            // layout the text
            page2.Layout(text2);

            // create page 1
            PdfPage page3 = document.AddPage();
            // create a text object to be laid out on this page
            PdfText text3 = new PdfText(10, 10, "This is the Page 3 of the document with Open action", newTimesFontEmbed);

            // layout the text
            page3.Layout(text3);

            if (radioButtonJavaScript.Checked)
            {
                // display an alert message when the document is opened

                string alertMessage   = textBoxAlertMessage.Text;
                string javaScriptCode = "app.alert({cMsg: \"" + alertMessage + "\", cTitle: \"Open Document JavaScript Action\"});";

                // create the JavaScript action to display the alert
                PdfJavaScriptAction javaScriptAction = new PdfJavaScriptAction(javaScriptCode);

                // set the document JavaScript open action
                document.SetOpenAction(javaScriptAction);
            }
            else
            {
                // go to a given page in document and set the given zoom level when the document is opened

                int pageIndex = radioButtonPage1.Checked ? 0 : (radioButtonPage2.Checked ? 1 : 2);
                int zoomLevel = int.Parse(textBoxZoomLevel.Text);

                PdfDestination openDestination = new PdfDestination(document.Pages[pageIndex], new System.Drawing.PointF(10, 10));
                openDestination.Zoom = zoomLevel;
                PdfGoToAction goToAction = new PdfGoToAction(openDestination);

                // set the document GoTo open action
                document.SetOpenAction(goToAction);
            }

            try
            {
                // write the PDF document to a memory buffer
                byte[] pdfBuffer = document.WriteToMemory();

                // inform the browser about the binary data format
                HttpContext.Current.Response.AddHeader("Content-Type", "application/pdf");

                // let the browser know how to open the PDF document and the file name
                HttpContext.Current.Response.AddHeader("Content-Disposition", String.Format("attachment; filename=OpenAction.pdf; size={0}",
                                                                                            pdfBuffer.Length.ToString()));

                // write the PDF buffer to HTTP response
                HttpContext.Current.Response.BinaryWrite(pdfBuffer);

                // call End() method of HTTP response to stop ASP.NET page processing
                HttpContext.Current.Response.End();
            }
            finally
            {
                document.Close();
            }
        }
Exemple #16
0
        private static void CreateJavaScriptActions(PdfFixedDocument document, PdfFont font)
        {
            PdfPen blackPen = new PdfPen(new PdfRgbColor(0, 0, 0), 1);
            PdfBrush blackBrush = new PdfBrush();

            font.Size = 12;
            PdfStringAppearanceOptions sao = new PdfStringAppearanceOptions();
            sao.Brush = blackBrush;
            sao.Font = font;
            PdfStringLayoutOptions slo = new PdfStringLayoutOptions();
            slo.HorizontalAlign = PdfStringHorizontalAlign.Center;
            slo.VerticalAlign = PdfStringVerticalAlign.Middle;

            for (int i = 0; i < document.Pages.Count; i++)
            {
                document.Pages[i].Graphics.DrawString("JavaScript actions:", font, blackBrush, 400, 480);

                document.Pages[i].Graphics.DrawRectangle(blackPen, 400, 500, 200, 20);
                slo.X = 500;
                slo.Y = 510;
                document.Pages[i].Graphics.DrawString("Click me", sao, slo);

                // Create a link annotation on top of the widget.
                PdfLinkAnnotation link = new PdfLinkAnnotation();
                document.Pages[i].Annotations.Add(link);
                link.VisualRectangle = new PdfVisualRectangle(400, 500, 200, 20);

                // Create a Javascript action and attach it to the link.
                PdfJavaScriptAction jsAction = new PdfJavaScriptAction();
                jsAction.Script = "app.alert({cMsg: \"JavaScript action: you are now on page " + (i + 1) + "\", cTitle: \"Xfinium.Pdf Actions Sample\"});";
                link.Action = jsAction;
            }
        }
Exemple #17
0
        public static void updateEffectiveDate(string strSiteUrl, string strUserId, string strPassword, string strEffectiveListName, string strDcrDocId)
        {
            try
            {
                using (var context = new ClientContext(strSiteUrl))
                {
                    SecureString passWord = new SecureString();
                    foreach (char c in strPassword.ToCharArray())
                    {
                        passWord.AppendChar(c);
                    }
                    context.Credentials = new SharePointOnlineCredentials(strUserId, passWord);
                    // Gets list object using the list Url
                    List      oList     = context.Web.Lists.GetByTitle(strEffectiveListName);
                    CamlQuery camlQuery = new CamlQuery();
                    camlQuery.ViewXml = "<View><Query><Where><Eq><FieldRef Name='CE_DCRDocID'/>" +
                                        "<Value Type='Lookup'>" + strDcrDocId +
                                        "</Value></Eq></Where></Query></View>";
                    ListItemCollection collListItem = oList.GetItems(camlQuery);
                    context.Load(collListItem);
                    context.ExecuteQuery();
                    foreach (ListItem item in collListItem)
                    {
                        var filePath = item["FileRef"];
                        docFileName = (string)item["FileLeafRef"];


                        Microsoft.SharePoint.Client.File file = item.File;
                        docLinkUrl = new Uri(context.Url).GetLeftPart(UriPartial.Authority) + filePath;
                        if (file != null)
                        {
                            //Loading Uploaded file
                            context.Load(file);
                            context.ExecuteQuery();
                            string dskFilePath = System.IO.Path.Combine(@"C:\Srini\Celitotech\Dev\PDF files\", file.Name);
                            using (System.IO.FileStream Local_stream = System.IO.File.Open(dskFilePath, System.IO.FileMode.CreateNew, System.IO.FileAccess.ReadWrite))
                            {
                                var fileInformation = Microsoft.SharePoint.Client.File.OpenBinaryDirect(context, file.ServerRelativeUrl);
                                var Sp_Stream       = fileInformation.Stream;
                                Sp_Stream.CopyTo(Local_stream);
                            }

                            PdfLoadedDocument loadedDocument = new PdfLoadedDocument(dskFilePath);
                            PdfDocument       document       = new PdfDocument();
                            document.ImportPageRange(loadedDocument, 0, loadedDocument.Pages.Count - 1);
                            document.Template.Top    = AddHeader(document, spHeaderLine1, spHeaderLine2, spHeaderLine3, spWaterMark, spExpiryDays);
                            document.Template.Bottom = AddFooter(document, spFooterLine1, spFooterLine2, spFooterLine3);

                            for (int i = 0; i < document.Pages.Count; i++)
                            {
                                PdfPageBase loadedPage = document.Pages[i];
                                PdfGraphics graphics   = loadedPage.Graphics;
                                PdfFont     font       = new PdfStandardFont(PdfFontFamily.Helvetica, 45);

                                //Add watermark text
                                PdfGraphicsState state = graphics.Save();
                                graphics.SetTransparency(0.25f);
                                graphics.RotateTransform(-40);
                                string text = spWaterMark;
                                SizeF  size = font.MeasureString(text);
                                graphics.DrawString(spWaterMark, font, PdfPens.Gray, PdfBrushes.Gray, new PointF(-150, 450));
                            }

                            DateTime            currentTime          = DateTime.Now;
                            Double              dbleExpiryDays       = Convert.ToDouble(spExpiryDays);
                            DateTime            addDaysToCurrentTime = currentTime.AddDays(dbleExpiryDays);
                            PdfJavaScriptAction scriptAction         = new PdfJavaScriptAction("function Expire(){ var currentDate = new Date();  var expireDate = new Date(2021, 3, 8);      if (currentDate < expireDate) {  app.alert(\"This Document has Expired.  You need a new one.\"); this.closeDoc();   }  } Expire(); ");
                            document.Actions.AfterOpen = scriptAction;

                            document.Save(docFileName);
                            document.Close(true);
                            loadedDocument.Close(true);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
Exemple #18
0
        public ActionResult CreatePdf(FormCollection collection)
        {
            // create a PDF document
            PdfDocument document = new PdfDocument();

            // set a demo serial number
            document.SerialNumber = "YCgJMTAE-BiwJAhIB-EhlWTlBA-UEBRQFBA-U1FOUVJO-WVlZWQ==";

            // create the true type fonts that can be used in document
            System.Drawing.Font ttfFont           = new System.Drawing.Font("Times New Roman", 10, System.Drawing.GraphicsUnit.Point);
            PdfFont             newTimesFont      = document.CreateFont(ttfFont);
            PdfFont             newTimesFontEmbed = document.CreateFont(ttfFont, true);

            // create page 1
            PdfPage page1 = document.AddPage();
            // create a text object to be laid out on this page
            PdfText text1 = new PdfText(10, 10, "This is the Page 1 of the document with Open action", newTimesFontEmbed);

            // layout the text
            page1.Layout(text1);

            // create page 2
            PdfPage page2 = document.AddPage();
            // create a text object to be laid out on this page
            PdfText text2 = new PdfText(10, 10, "This is the Page 2 of the document with Open action", newTimesFontEmbed);

            // layout the text
            page2.Layout(text2);

            // create page 1
            PdfPage page3 = document.AddPage();
            // create a text object to be laid out on this page
            PdfText text3 = new PdfText(10, 10, "This is the Page 3 of the document with Open action", newTimesFontEmbed);

            // layout the text
            page3.Layout(text3);

            if (collection["ActionType"] == "radioButtonJavaScript")
            {
                // display an alert message when the document is opened

                string alertMessage   = collection["textBoxAlertMessage"];
                string javaScriptCode = "app.alert({cMsg: \"" + alertMessage + "\", cTitle: \"Open Document JavaScript Action\"});";

                // create the JavaScript action to display the alert
                PdfJavaScriptAction javaScriptAction = new PdfJavaScriptAction(javaScriptCode);

                // set the document JavaScript open action
                document.SetOpenAction(javaScriptAction);
            }
            else
            {
                // go to a given page in document and set the given zoom level when the document is opened

                int pageIndex = collection["PageNumber"] == "radioButtonPage1" ? 0 : (collection["PageNumber"] == "radioButtonPage2" ? 1 : 2);
                int zoomLevel = int.Parse(collection["textBoxZoomLevel"]);

                PdfDestination openDestination = new PdfDestination(document.Pages[pageIndex], new System.Drawing.PointF(10, 10));
                openDestination.Zoom = zoomLevel;
                PdfGoToAction goToAction = new PdfGoToAction(openDestination);

                // set the document GoTo open action
                document.SetOpenAction(goToAction);
            }

            try
            {
                // write the PDF document to a memory buffer
                byte[] pdfBuffer = document.WriteToMemory();

                FileResult fileResult = new FileContentResult(pdfBuffer, "application/pdf");
                fileResult.FileDownloadName = "OpenAction.pdf";

                return(fileResult);
            }
            finally
            {
                document.Close();
            }
        }
        /// <summary>
        /// Main method for running the sample.
        /// </summary>
        public static SampleOutputInfo[] Run()
        {
            PdfFixedDocument document  = new PdfFixedDocument();
            PdfStandardFont  helvetica = new PdfStandardFont(PdfStandardFontFace.Helvetica, 12);
            PdfBrush         brush     = new PdfBrush();

            PdfPage page = document.Pages.Add();

            // First name
            page.Graphics.DrawString("First name:", helvetica, brush, 50, 50);
            PdfTextBoxField firstNameTextBox = new PdfTextBoxField("firstname");

            page.Fields.Add(firstNameTextBox);
            firstNameTextBox.Widgets[0].Font            = helvetica;
            firstNameTextBox.Widgets[0].VisualRectangle = new PdfVisualRectangle(150, 45, 200, 20);
            firstNameTextBox.Widgets[0].BorderColor     = PdfRgbColor.Black;
            firstNameTextBox.Widgets[0].BorderWidth     = 1;

            // Last name
            page.Graphics.DrawString("Last name:", helvetica, brush, 50, 80);
            PdfTextBoxField lastNameTextBox = new PdfTextBoxField("lastname");

            page.Fields.Add(lastNameTextBox);
            lastNameTextBox.Widgets[0].Font            = helvetica;
            lastNameTextBox.Widgets[0].VisualRectangle = new PdfVisualRectangle(150, 75, 200, 20);
            lastNameTextBox.Widgets[0].BorderColor     = PdfRgbColor.Black;
            lastNameTextBox.Widgets[0].BorderWidth     = 1;

            // Sex
            page.Graphics.DrawString("Sex:", helvetica, brush, 50, 110);
            PdfRadioButtonField  sexRadioButton = new PdfRadioButtonField("sex");
            PdfRadioButtonWidget maleRadioItem  = new PdfRadioButtonWidget();

            sexRadioButton.Widgets.Add(maleRadioItem);
            PdfRadioButtonWidget femaleRadioItem = new PdfRadioButtonWidget();

            sexRadioButton.Widgets.Add(femaleRadioItem);
            page.Fields.Add(sexRadioButton);

            page.Graphics.DrawString("Male", helvetica, brush, 180, 110);
            maleRadioItem.ExportValue     = "M";
            maleRadioItem.CheckStyle      = PdfCheckStyle.Circle;
            maleRadioItem.VisualRectangle = new PdfVisualRectangle(150, 105, 20, 20);
            maleRadioItem.BorderColor     = PdfRgbColor.Black;
            maleRadioItem.BorderWidth     = 1;

            page.Graphics.DrawString("Female", helvetica, brush, 280, 110);
            femaleRadioItem.ExportValue     = "F";
            femaleRadioItem.CheckStyle      = PdfCheckStyle.Circle;
            femaleRadioItem.VisualRectangle = new PdfVisualRectangle(250, 105, 20, 20);
            femaleRadioItem.BorderColor     = PdfRgbColor.Black;
            femaleRadioItem.BorderWidth     = 1;

            // First car
            page.Graphics.DrawString("First car:", helvetica, brush, 50, 140);
            PdfComboBoxField firstCarList = new PdfComboBoxField("firstcar");

            firstCarList.Items.Add(new PdfListItem("Mercedes", "Mercedes"));
            firstCarList.Items.Add(new PdfListItem("BMW", "BMW"));
            firstCarList.Items.Add(new PdfListItem("Audi", "Audi"));
            firstCarList.Items.Add(new PdfListItem("Volkswagen", "Volkswagen"));
            firstCarList.Items.Add(new PdfListItem("Porsche", "Porsche"));
            firstCarList.Items.Add(new PdfListItem("Honda", "Honda"));
            firstCarList.Items.Add(new PdfListItem("Toyota", "Toyota"));
            firstCarList.Items.Add(new PdfListItem("Lexus", "Lexus"));
            firstCarList.Items.Add(new PdfListItem("Infiniti", "Infiniti"));
            firstCarList.Items.Add(new PdfListItem("Acura", "Acura"));
            page.Fields.Add(firstCarList);
            firstCarList.Widgets[0].Font            = helvetica;
            firstCarList.Widgets[0].VisualRectangle = new PdfVisualRectangle(150, 135, 200, 20);
            firstCarList.Widgets[0].BorderColor     = PdfRgbColor.Black;
            firstCarList.Widgets[0].BorderWidth     = 1;

            // Second car
            page.Graphics.DrawString("Second car:", helvetica, brush, 50, 170);
            PdfListBoxField secondCarList = new PdfListBoxField("secondcar");

            secondCarList.Items.Add(new PdfListItem("Mercedes", "Mercedes"));
            secondCarList.Items.Add(new PdfListItem("BMW", "BMW"));
            secondCarList.Items.Add(new PdfListItem("Audi", "Audi"));
            secondCarList.Items.Add(new PdfListItem("Volkswagen", "Volkswagen"));
            secondCarList.Items.Add(new PdfListItem("Porsche", "Porsche"));
            secondCarList.Items.Add(new PdfListItem("Honda", "Honda"));
            secondCarList.Items.Add(new PdfListItem("Toyota", "Toyota"));
            secondCarList.Items.Add(new PdfListItem("Lexus", "Lexus"));
            secondCarList.Items.Add(new PdfListItem("Infiniti", "Infiniti"));
            secondCarList.Items.Add(new PdfListItem("Acura", "Acura"));
            page.Fields.Add(secondCarList);
            secondCarList.Widgets[0].Font            = helvetica;
            secondCarList.Widgets[0].VisualRectangle = new PdfVisualRectangle(150, 165, 200, 60);
            secondCarList.Widgets[0].BorderColor     = PdfRgbColor.Black;
            secondCarList.Widgets[0].BorderWidth     = 1;

            // I agree
            page.Graphics.DrawString("I agree:", helvetica, brush, 50, 240);
            PdfCheckBoxField agreeCheckBox = new PdfCheckBoxField("agree");

            page.Fields.Add(agreeCheckBox);
            agreeCheckBox.Widgets[0].Font = helvetica;
            (agreeCheckBox.Widgets[0] as PdfCheckWidget).ExportValue = "YES";
            (agreeCheckBox.Widgets[0] as PdfCheckWidget).CheckStyle  = PdfCheckStyle.Check;
            agreeCheckBox.Widgets[0].VisualRectangle = new PdfVisualRectangle(150, 235, 20, 20);
            agreeCheckBox.Widgets[0].BorderColor     = PdfRgbColor.Black;
            agreeCheckBox.Widgets[0].BorderWidth     = 1;

            // Sign here
            page.Graphics.DrawString("Sign here:", helvetica, brush, 50, 270);
            PdfSignatureField signHereField = new PdfSignatureField("signhere");

            page.Fields.Add(signHereField);
            signHereField.Widgets[0].Font            = helvetica;
            signHereField.Widgets[0].VisualRectangle = new PdfVisualRectangle(150, 265, 200, 60);

            // Submit form
            PdfPushButtonField submitBtn = new PdfPushButtonField("submit");

            page.Fields.Add(submitBtn);
            submitBtn.Widgets[0].VisualRectangle = new PdfVisualRectangle(450, 45, 150, 30);
            (submitBtn.Widgets[0] as PdfPushButtonWidget).Caption = "Submit form";
            submitBtn.Widgets[0].BackgroundColor = PdfRgbColor.LightGray;
            PdfSubmitFormAction submitFormAction = new PdfSubmitFormAction();

            submitFormAction.DataFormat = PdfSubmitDataFormat.FDF;
            submitFormAction.Fields.Add("firstname");
            submitFormAction.Fields.Add("lastname");
            submitFormAction.Fields.Add("sex");
            submitFormAction.Fields.Add("firstcar");
            submitFormAction.Fields.Add("secondcar");
            submitFormAction.Fields.Add("agree");
            submitFormAction.Fields.Add("signhere");
            submitFormAction.SubmitFields = true;
            submitFormAction.Url          = "http://www.xfiniumsoft.com/";
            submitBtn.Widgets[0].MouseUp  = submitFormAction;

            // Reset form
            PdfPushButtonField resetBtn = new PdfPushButtonField("reset");

            page.Fields.Add(resetBtn);
            resetBtn.Widgets[0].VisualRectangle = new PdfVisualRectangle(450, 85, 150, 30);
            (resetBtn.Widgets[0] as PdfPushButtonWidget).Caption = "Reset form";
            resetBtn.Widgets[0].BackgroundColor = PdfRgbColor.LightGray;
            PdfResetFormAction resetFormAction = new PdfResetFormAction();

            resetBtn.Widgets[0].MouseUp = resetFormAction;

            // Print form
            PdfPushButtonField printBtn = new PdfPushButtonField("print");

            page.Fields.Add(printBtn);
            printBtn.Widgets[0].VisualRectangle = new PdfVisualRectangle(450, 125, 150, 30);
            (printBtn.Widgets[0] as PdfPushButtonWidget).Caption = "Print form";
            printBtn.Widgets[0].BackgroundColor = PdfRgbColor.LightGray;
            PdfJavaScriptAction printAction = new PdfJavaScriptAction();

            printAction.Script          = "this.print(true);\n";
            printBtn.Widgets[0].MouseUp = printAction;

            SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.formgenerator.pdf") };
            return(output);
        }
Exemple #20
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document
            PdfDocument doc = new PdfDocument();

            //Set 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;

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

            float y = 10;

            //Title
            PdfBrush        brush1  = PdfBrushes.Black;
            PdfTrueTypeFont font1   = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold));
            PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Center);

            page.Canvas.DrawString("Part List", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1);
            y = y + font1.MeasureString("Part List", format1).Height;
            y = y + 2;

            //Table top
            PdfDestination tableTopDest = new PdfDestination(page);

            tableTopDest.Location = new PointF(0, y);
            tableTopDest.Mode     = PdfDestinationMode.Location;
            tableTopDest.Zoom     = 1f;

            //Draw table
            PdfTrueTypeFont buttonFont        = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Bold));
            float           buttonWidth       = 70;
            float           buttonHeight      = buttonFont.Height * 1.5f;
            float           tableTop          = y;
            PdfLayoutResult tableLayoutResult = DrawTable(page, y + buttonHeight + 5);

            //Table bottom
            PdfDestination tableBottomDest = new PdfDestination(tableLayoutResult.Page);

            tableBottomDest.Location = new PointF(0, tableLayoutResult.Bounds.Bottom);
            tableBottomDest.Mode     = PdfDestinationMode.Location;
            tableBottomDest.Zoom     = 1f;

            //Go to table bottom
            float           x            = page.Canvas.ClientSize.Width - buttonWidth;
            PdfStringFormat format2      = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            RectangleF      buttonBounds = new RectangleF(x, tableTop, buttonWidth, buttonHeight);

            page.Canvas.DrawRectangle(PdfBrushes.DarkGray, buttonBounds);
            page.Canvas.DrawString("To Bottom", buttonFont, PdfBrushes.CadetBlue, buttonBounds, format2);
            PdfGoToAction       action1 = new PdfGoToAction(tableBottomDest);
            PdfActionAnnotation annotation1
                = new PdfActionAnnotation(buttonBounds, action1);

            annotation1.Border = new PdfAnnotationBorder(0.75f);
            annotation1.Color  = Color.LightGray;
            (page as PdfNewPage).Annotations.Add(annotation1);

            //Go to table top
            float tableBottom = tableLayoutResult.Bounds.Bottom + 5;

            buttonBounds = new RectangleF(x, tableBottom, buttonWidth, buttonHeight);
            tableLayoutResult.Page.Canvas.DrawRectangle(PdfBrushes.DarkGray, buttonBounds);
            tableLayoutResult.Page.Canvas.DrawString("To Top", buttonFont, PdfBrushes.CadetBlue, buttonBounds, format2);
            PdfGoToAction       action2 = new PdfGoToAction(tableTopDest);
            PdfActionAnnotation annotation2
                = new PdfActionAnnotation(buttonBounds, action2);

            annotation2.Border = new PdfAnnotationBorder(0.75f);
            annotation2.Color  = Color.LightGray;
            (tableLayoutResult.Page as PdfNewPage).Annotations.Add(annotation2);

            //Go to last page
            PdfNamedAction action3 = new PdfNamedAction(PdfActionDestination.LastPage);

            doc.AfterOpenAction = action3;

            //Script
            String script
                = "app.alert({"
                  + "    cMsg: \"Oh no, you want to leave me.\","
                  + "    nIcon: 3,"
                  + "    cTitle: \"JavaScript Action\""
                  + "});";
            PdfJavaScriptAction action4 = new PdfJavaScriptAction(script);

            doc.BeforeCloseAction = action4;

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

            //Launch the Pdf file
            PDFDocumentViewer("Action.pdf");
        }
Exemple #21
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

            //Set margins
            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;

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

            float           y    = 100;
            float           x    = 10;
            PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Lucida Sans Unicode", 14));

            String          label  = "Simple Text Link: ";
            PdfStringFormat format = new PdfStringFormat();

            format.MeasureTrailingSpaces = true;
            page.Canvas.DrawString(label, font, PdfBrushes.Orange, 0, y, format);
            x = font.MeasureString(label, format).Width;
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Lucida Sans Unicode", 14, FontStyle.Underline));
            String          url1  = "http://www.e-iceblue.com";

            page.Canvas.DrawString(url1, font1, PdfBrushes.CadetBlue, x, y);
            y = y + font1.MeasureString(url1).Height + 25;

            label = "Web Link: ";
            page.Canvas.DrawString(label, font, PdfBrushes.Orange, 0, y, format);
            x = font.MeasureString(label, format).Width;
            String         text  = "E-iceblue home";
            PdfTextWebLink link2 = new PdfTextWebLink();

            link2.Text  = text;
            link2.Url   = url1;
            link2.Font  = font1;
            link2.Brush = PdfBrushes.CadetBlue;
            link2.DrawTextWebLink(page.Canvas, new PointF(x, y));
            y = y + font1.MeasureString(text).Height + 30;

            label = "URI Annonation: ";
            page.Canvas.DrawString(label, font, PdfBrushes.Orange, 0, y, format);
            x    = font.MeasureString(label, format).Width;
            text = "Google";
            PointF           location   = new PointF(x, y);
            SizeF            size       = font1.MeasureString(text);
            RectangleF       linkBounds = new RectangleF(location, size);
            PdfUriAnnotation link3      = new PdfUriAnnotation(linkBounds);

            link3.Border = new PdfAnnotationBorder(0);
            link3.Uri    = "http://www.google.com";
            (page as PdfNewPage).Annotations.Add(link3);
            page.Canvas.DrawString(text, font1, PdfBrushes.CadetBlue, x, y);
            y = y + size.Height + 30;

            label = "URI Annonation Action: ";
            page.Canvas.DrawString(label, font, PdfBrushes.Orange, 0, y, format);
            x          = font.MeasureString(label, format).Width;
            text       = "JavaScript Action (Click Me)";
            location   = new PointF(x - 2, y - 2);
            size       = font1.MeasureString(text);
            size       = new SizeF(size.Width + 5, size.Height + 5);
            linkBounds = new RectangleF(location, size);
            PdfUriAnnotation link4 = new PdfUriAnnotation(linkBounds);

            link4.Border = new PdfAnnotationBorder(0.75f);
            link4.Color  = Color.CadetBlue;
            //Script
            String script
                = "app.alert({"
                  + "    cMsg: \"Hello.\","
                  + "    nIcon: 3,"
                  + "    cTitle: \"JavaScript Action\""
                  + "});";
            PdfJavaScriptAction action = new PdfJavaScriptAction(script);

            link4.Action = action;
            (page as PdfNewPage).Annotations.Add(link4);
            page.Canvas.DrawString(text, font1, PdfBrushes.CadetBlue, x, y);
            y = y + size.Height + 30;

            label = "Need Help:  ";
            page.Canvas.DrawString(label, font, PdfBrushes.Orange, 0, y, format);
            x           = font.MeasureString(label, format).Width;
            text        = "Go to forum to ask questions";
            link2       = new PdfTextWebLink();
            link2.Text  = text;
            link2.Url   = "https://www.e-iceblue.com/forum/components-f5.html";
            link2.Font  = font1;
            link2.Brush = PdfBrushes.CadetBlue;
            link2.DrawTextWebLink(page.Canvas, new PointF(x, y));
            y = y + font1.MeasureString(text).Height + 30;

            label = "Contct us:  ";
            page.Canvas.DrawString(label, font, PdfBrushes.Orange, 0, y, format);
            x           = font.MeasureString(label, format).Width;
            text        = "Send an email";
            link2       = new PdfTextWebLink();
            link2.Text  = text;
            link2.Url   = "mailto:[email protected]";
            link2.Font  = font1;
            link2.Brush = PdfBrushes.CadetBlue;
            link2.DrawTextWebLink(page.Canvas, new PointF(x, y));
            y = y + font1.MeasureString(text).Height + 30;

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

            //Launch the file.
            PDFDocumentViewer("Link.pdf");
        }
Exemple #22
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);
        }
Exemple #23
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;

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

            float y = 10;

            //title
            PdfBrush brush1 = PdfBrushes.Black;
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold));
            PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Center);
            page.Canvas.DrawString("Part List", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1);
            y = y + font1.MeasureString("Part List", format1).Height;
            y = y + 2;

            //table top
            PdfDestination tableTopDest = new PdfDestination(page);
            tableTopDest.Location = new PointF(0, y);
            tableTopDest.Mode = PdfDestinationMode.Location;
            tableTopDest.Zoom = 1f;

            //Draw table            
            PdfTrueTypeFont buttonFont = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Bold));
            float buttonWidth = 70;
            float buttonHeight = buttonFont.Height * 1.5f;
            float tableTop = y;
            PdfLayoutResult tableLayoutResult = DrawTable(page, y + buttonHeight + 5);

            //table bottom
            PdfDestination tableBottomDest = new PdfDestination(tableLayoutResult.Page);
            tableBottomDest.Location = new PointF(0, tableLayoutResult.Bounds.Bottom);
            tableBottomDest.Mode = PdfDestinationMode.Location;
            tableBottomDest.Zoom = 1f;

            //go to table bottom
            float x = page.Canvas.ClientSize.Width - buttonWidth;
            PdfStringFormat format2 = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            RectangleF buttonBounds = new RectangleF(x, tableTop, buttonWidth, buttonHeight);
            page.Canvas.DrawRectangle(PdfBrushes.DarkGray, buttonBounds);
            page.Canvas.DrawString("To Bottom", buttonFont, PdfBrushes.CadetBlue, buttonBounds, format2);
            PdfGoToAction action1 = new PdfGoToAction(tableBottomDest);
            PdfActionAnnotation annotation1
                = new PdfActionAnnotation(buttonBounds, action1);
            annotation1.Border = new PdfAnnotationBorder(0.75f);
            annotation1.Color = Color.LightGray;
            (page as PdfNewPage).Annotations.Add(annotation1);

            //go to table top
            float tableBottom = tableLayoutResult.Bounds.Bottom + 5;
            buttonBounds = new RectangleF(x, tableBottom, buttonWidth, buttonHeight);
            tableLayoutResult.Page.Canvas.DrawRectangle(PdfBrushes.DarkGray, buttonBounds);
            tableLayoutResult.Page.Canvas.DrawString("To Top", buttonFont, PdfBrushes.CadetBlue, buttonBounds, format2);
            PdfGoToAction action2 = new PdfGoToAction(tableTopDest);
            PdfActionAnnotation annotation2
                = new PdfActionAnnotation(buttonBounds, action2);
            annotation2.Border = new PdfAnnotationBorder(0.75f);
            annotation2.Color = Color.LightGray;
            (tableLayoutResult.Page as PdfNewPage).Annotations.Add(annotation2);

            //goto last page
            PdfNamedAction action3 = new PdfNamedAction(PdfActionDestination.LastPage);
            doc.AfterOpenAction = action3;

            //script
            String script
                = "app.alert({"
                + "    cMsg: \"Oh no, you want to leave me.\","
                + "    nIcon: 3,"
                + "    cTitle: \"JavaScript Action\""
                + "});";
            PdfJavaScriptAction action4 = new PdfJavaScriptAction(script);
            doc.BeforeCloseAction = action4;

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

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