-1

I am writing a web app in asp.net using the bootstrap framework for style. The purpose is to have a pdf displayed, then the user fills out the pdf and it should get saved to a folder inside the solution for further processing after clicking the button below. I was able to embed the pdf and have it be fully editable, however, I am stuck trying to save it back to the solution. I have researched the web for answers, but the only thing that I think might be useful is the File.writeAllBytes() method. I just can't figure out how to implement it. Any help or suggestions on how to accomplish this is greatly appreciated.

Heres the UI code:

<%@ Page Language="C#" AutoEventWireup="true" masterpagefile="~/Site.Master" 
CodeBehind="RenderPDF.aspx.cs" Inherits="DocusignTest.RenderPDF" %>

<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<div class="row">
    <div class="col-lg-4">
        <div class="jumbotron">
            <label>First Name:</label>
            <input type="text" class="form-control"/>
            <label>Last Name:</label>
            <input type="text" class="form-control"/>
            <label>Email:</label>
            <input type="email" class="form-control"/>
        </div>
    </div>
    <div class="col-lg-8">
        <!-- this is the pdf the user needs to fill out -->
        <embed id="pdf" src="e-docs/PAF.pdf" style="width: 100%; height:1000px"/>
        <div class="pager">
            <asp:Button ID="eSignButton" runat="server" CssClass="btn btn-primary" Text="Sign" OnClick="eSign_Click" Enabled="false"/>
            <input type="checkbox" id="eSignCheckbox" onclick="enableButton();"/>I have filled out this document to the best of my abilities.
        </div>
    </div>
</div>

<script lang="javascript" type="text/javascript">
    var button = WebForm_GetElementById("MainContent_eSignButton")
    var checkbox = WebForm_GetElementById("eSignCheckbox")
    function enableButton() {
        if (checkbox.checked) {
            button.disabled = false;
        } else {
            button.disabled = true;
        }
    }
</script>

Here is the code-behind:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

namespace DocusignTest
{
    public partial class RenderPDF : System.Web.UI.Page
    {

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void eSign_Click(object sender, EventArgs e)
    {
        savePDF();
    }

    protected void savePDF()
    {
        //DO something. 
        //Maybe using File.writeAllBytes() to save the embedded PDF to folder in solution.
    }
}
Cai Cruz
  • 83
  • 1
  • 1
  • 11
  • Wouldn't the completed PDF file have to uploaded? – stuartd Aug 10 '17 at 17:00
  • @stuartd Uploaded to where? the server? why? I need it to be saved to a folder inside the solution to further process it and then I can save it to a server – Cai Cruz Aug 10 '17 at 17:03
  • _"I need it to be saved to a folder inside the solution"_ - you want to save the PDF within your code? That's very confusing. Wouldn't it be to a folder on the web server? As I see it, you have embedded a PDF in a web page, and your user is editing it in their browser. When they click the sign button, the filled PDF only exists in the browser, so wouldn't you have to upload it for further processing? – stuartd Aug 10 '17 at 17:15
  • @stuartd actually the pdf already exists in a folder inside the solution. The tag gets it from that folder. Now what I would like to do is get that filled out pdf and store it inside a different folder inside the solution. Similar to what an UploadFile controller would do if you specify a path to a solution's folder. [Check this out](https://www.youtube.com/watch?v=-I4e0ZZ6YuQ) – Cai Cruz Aug 10 '17 at 17:23
  • OK sorry I think I misunderstood. – stuartd Aug 10 '17 at 17:37
  • @stuartd That's ok. Any help really is great. You might be onto something though. How would you suggest uploading back the file to a server folder? Because if I can send it to a temp folder on a server and from there process it, that's ok with me. I am not married to the initial idea. – Cai Cruz Aug 10 '17 at 17:40

2 Answers2

0

Things that exist on the client side cannot be 'automatically' uploaded - that would be bad for a number of reasons.

An embed downloads the item to a temp folder on the users computer, and then displays it. In your instance, the PDF is downloaded to the temp folder, the user edits it and then it is possibly (as I really don't know how Adobe handles editible PDFs) saved back to the temp folder. It can only go back to where it was downloaded to.

The only way it would ever work is if the user physically uploaded the file back to the site.


EDIT

Your other option is this: Can a PDF fillable form post itself to an HTTPS URL? which seems quite promising...

Michael Coxon
  • 4,806
  • 1
  • 21
  • 49
  • Would you suggest adding a user promt to upload it back when they are done editing? a submit button maybe? – Cai Cruz Aug 10 '17 at 17:42
  • Definitely. The best way would be to give them a link to download the PDF and fill it out. Ask them to save it, and then upload it and tick the sign box. Depending on your requirements, you may need to check if the PDF was actually filled out or whether it is the same PDF. – Michael Coxon Aug 10 '17 at 17:47
  • Check out my edit you can possibly add the submit to the PDF like in this post https://stackoverflow.com/questions/4631008/can-a-pdf-fillable-form-post-itself-to-an-https-url – Michael Coxon Aug 10 '17 at 17:48
0

Any help really is great. You might be onto something though. How would you suggest uploading back the file to a server folder? Because if I can send it to a temp folder on a server and from there process it, that's ok with me. I am not married to the initial idea.

I have done similar application for a bank. It lets user fill out a loan application in PDF inside client-browser, and save it to database. Then loan officer can view, modify and print the PDF.

For that scenario, you will need a component to save the PDF back to server. I used ActivePDF at that time.

Win
  • 56,078
  • 13
  • 92
  • 167