views:

145

answers:

3

I'm serving up PDFs from a SQL db and presenting them in the browser. I'm trying to figure out a way to embed a number in the PDF dynamically so that the recordID for that PDFs SQL record is available to me when the user submits the XML form data. The user hits the submit button on the form and the form submits its XML data to my submission page. If there is some way of changing the submission URL on the fly then I could do a query string to pass my self the recordID. I'm not generating the PDF in code, its being created by hand and then uploaded to my site.

Edit

User is given a link someServer.com/pdfLink.aspx?formID=5 they go there and that pages pulls a PDF from the DB and displays it. This pulls up acrobat in browser full size so my aspx page isn't in control of submitting the completed form, Acrobat is. The user fills out the form and hits the submit button in the form. This submit button was set up at form design time to point to another page someSite.com/pdfSubmit.aspx The submit button posts the XML data to that page and I can process it. I need the recordID in the query string for the someSite.com/pdfSubmit.aspx page. To do this I would need to modify the PDF to either add the recordID and query string to the submit button's submit URL, or embed it in the PDF else ware. The big question is how do I modify the PDF just before I display it via someServer.com/pdfLink.aspx?formID=5 to do either of these two options.

A: 

The querystring is read-only so you cannot dynamically change it at runtime. However can you:

  1. Add the recordID to the form at the time the submit page is initially rendered

  2. Can you process the submit form and then do a Response.Redirect or Server.Transfer to the correct page with the recordid parameter added to the querystring

bechbd
I don't think you quite understood the question. I've added more of an explanation to help.
jamone
+1  A: 

Embedding a number in PDF is not exactly kosher, but there are some things that you can do that will honor the spec.

The current PDF spec says that "The last line of the file shall contain only the end-of-file marker

%%EOF

but there is some wiggle room - the implementation details say that it doesn't technically have to be the last line of the file, but only has to appear in the last 1K and, generally speaking, if you don't muck with things too much, most compliant readers won't even blink. If I had to do this, I would be inclined to add a newline (if there isn't one), then a % (which is a PDF comment), a marker to let me know it's mine, and finally the number. So something like:

// assume we already know it ends with %%EOF
void AppendNumberToPdf(Stream stm, int number, bool addNewline)
{
    stm.Seek(0, SeekOrigin.End); // go to EOF
    StreamWriter writer = new StreamWriter(stm, new ASCIIEncoding(), 1024);
    writer.WriteLine(string.Format("{0}% {1} {2}", (addNewLine ? "\n" : ""), kMyMarkerString, number));
    writer.Flush();
}

kMyMarkerString should be something like "MyApplicationDocumentIdentifier:" or some such thing that will make it easy to identify your tracks.

plinth
This seems reasonable. I'm trying it now.
jamone
A: 

While trying @plinth's suggestion I realized I had to change from XML submission (since his data was on the PDF directly. So I changed the form to submit as XDP which has XML data + embedded PDF. When I did this and viewed the raw XDP that the form submitted I ran across this.

  <?xml version="1.0" encoding="UTF-8" ?> 
  <?xfa generator="XFA2_4" APIVersion="3.0.8262.0"?> 
  <xdp:xdp xmlns:xdp="http://ns.adobe.com/xdp/" timeStamp="2010-05-04T15:15:00Z" uuid="6d0944c8-1573-442c-9c85-11e372bd38c3">
    <xfa:datasets xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/"&gt;
      <xfa:data>
         <form1>
           <TextField1>TestMe</TextField1> 
         </form1>
       </xfa:data>
    </xfa:datasets>
    <pdf href="ViewPDF.aspx?formID=10" xmlns="http://ns.adobe.com/xdp/pdf/" /> 
 </xdp:xdp>

Notice the 2nd to last line. It automatically includes the PDF's url which had the formID value that I needed. So all I had to do was get the XDP instead of pure XML post from the form and it gives me everything I needed.

jamone