Wesley
Wesley

Reputation: 307

PDF submit button to ActionResult to RedirectToAction

I'm running in to an issue with PDF form submitting and I can't seem to find any help online, hopefully stackoverflow and can help me out.

I have a PDF form that the end-user will download. Once the download link is clicked, I'll dynamically insert a submit button in the PDF. The URL attached to the button points to an ActionResult I created called ProcessSubmit. It accepts 2 parameters, ID and Version.

After the user fills out the form and clicks Submit, I retrieve the FDF data from the Request.InputStream and update the PDF form on the server.

Up to this point everything works fine and dandy.

My issue comes in when I want to return to a page in my MVC project (Index, from the same controller I run ProcessSubmit from).

Different things happen from different scenarios:

Using Chrome to View the PDF:

Using Adobe PDF to View the PDF:

My Code:

    /// <summary>
    /// Requests the form.
    /// </summary>
    /// <param name="id">The identifier.</param>
    /// <param name="version">The version.</param>
    /// <returns></returns>
    public ActionResult RequestForm(Guid id, int version)
    {
        if (ControllerContext.HttpContext.Request.Url != null)
        {
            var processSubmitUriString =
                Url.Action("ProcessSubmit", "Forms", null, ControllerContext.HttpContext.Request.Url.Scheme);
            var processSubmitUrl = String.Format("{0}?id={1}&version={2}", processSubmitUriString, id, version);
            var source = _FormsProxy.GetPatientClinicalOrderStream(id, version, processSubmitUrl);
            if (source != null)
            {
                return File(source, "application/pdf", string.Format("YourForm_{0}.pdf", DateTime.Now.ToString("MMddyyyy-HHmmss")));
            }
        }
        return null;
    }

    /// <summary>
    /// Processes the submit.
    /// </summary>
    /// <param name="id">The identifier.</param>
    /// <param name="version">The version.</param>
    /// <returns></returns>
    public ActionResult ProcessSubmit(string id, int version)
    {
        using (var sr = new StreamReader(Request.InputStream))
        {
            var fdfStream = sr.ReadToEnd();
            var fields = FDFParser.Parse(fdfStream.Replace(">>", ">>\r\n"));
            _FormsProxy.UpdatePatientClinicalOrderFromSubmittedData(new Guid(id), version, fields.Fields);
        }
        return RedirectToAction("Index");
    }

Upvotes: 2

Views: 1542

Answers (1)

Heather
Heather

Reputation: 2652

I don't think you can do this. Your submission is coming from a POST from Acrobat, and so that's where the redirect is being sent to. Acrobat doesn't know what to do with a redirect.

What should work is if in your PDF in the click event of the "Submit" button you add an additional line after the code that does the actual submit:

app.launchURL("http://foo.com/Index/000 (your ID)", true);

(the "true" will cause Acrobat to open the URL in a new browser window, the default is "false", which loads the URL in Acrobat).

Upvotes: 1

Related Questions