We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

PdfJavaScriptAction : "this.saveAs('/ c / temp / temp.pdf');"

Below is my code where I am trying to add a Save button inside a pdf, I am attaching a JavaScript Action to it which basically saves the document with a new name. 

However the button click is not saving the document. Please see below my code. If I add a simple alert, it works fine. 

string fileName = "";
                PdfDocument document = new PdfDocument();
                document.PageSettings = new PdfPageSettings(new SizeF(300400));
                PdfPage page = document.Pages.Add();
                PdfGraphics graphics = page.Graphics;
                PdfImage image = PdfImage.FromStream(new MemoryStream(attachment.FILE_DATA));//PdfImage.FromFile(@"C:\\DevelopmentMobile\\action.png");
                PdfFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 8fPdfFontStyle.Bold);
                PdfForm frm = new PdfForm();
                graphics.DrawImage(image, 00);
 
                PdfButtonField submitButton = new PdfButtonField(page, "submitButton");
                submitButton.Bounds = new RectangleF(2516010020);
                submitButton.Text = "Apply";
                submitButton.BackColor = new PdfColor(181191203);
                //Create a new PdfJavaScriptAction
                PdfJavaScriptAction javaAction = new PdfJavaScriptAction("this.saveAs(\" / c / temp / temp.pdf\");");
                //Set the javaAction to submitButton
                submitButton.Actions.MouseDown = javaAction;
                //Add the submit button to the new document.
                document.Form.Fields.Add(submitButton);
                fileName = attachment.FILE_NAME.ToString().Replace(Path.GetExtension(attachment.FILE_NAME.ToString()), "");
                document.Save(@"C:\\DevelopmentMobile\\" + fileName + "_" + VZUserProfile.Instance.Username.ToString() + ".pdf");
                System.Diagnostics.Process.Start(@"C:\\DevelopmentMobile\\" + fileName + "_" + VZUserProfile.Instance.Username.ToString() + ".pdf");

2 Replies

GR Gayathri Ramalingam Syncfusion Team November 30, 2016 04:43 PM UTC

Hi Vikas, 
Thank you for using Syncfusion products. 
We will analyze the feasibility to achieve your requirement of “Adding button field in PDF document using Javascript action”. We will update you with the further details on 1st December, 2016. 

With Regards, 
Gayathri R 



GR Gayathri Ramalingam Syncfusion Team December 1, 2016 04:57 PM UTC

Hi Vikas, 
We are following Acrobat’s procedure to add action for form fields using Javascript action. After analyzing the issue “Adding button field in PDF document using Javascript action”, there is no support to add save action in button field using Java script action. We have reported the same to acrobat support team. We will update you once we got response from acrobat’s support team. 

With Regards, 
Gayathri R 


Loader.
Up arrow icon