Q: We are trying to persist the form data from PDF in a database in
order to facilitate later retrieval by the user for printing, etc.. We
don't want to take the user through document creation work flow again
nor save a file on disk.
How we are trying to Extract FDF info from the document and persist in
the database. Is there a way to achieve this?
-----
A: Did you have a chance to take a look at FDF (Forms Data Format)
sample project (http://www.pdftron.com/net/samplecode.html#FDF)?
It shows how to extract FDF from PDF and merge FDF with PDF.
In case you want to save FDF format to memory or read it from memory
you can use the same technique (i.e. fdf.Save(mem_buffer)) used in
PDFDocMemory sample (http://www.pdftron.com/net/
samplecode.html#PDFDocMemory).
-------
Q: I had consulted those examples, however FDFDoc.Save only allows
saving to file not to memory stream. I could save to file, read it and
then create a stream out of it (as suggested in the samples) and then
store in db, but this is not a good option.
For now, I'm streaming the entire PDF document to the database
although this is not desirable as size of the doc far exceeds that of
the FDF. Is there an update available to PDFNet api that might allow
creating FDF streams? Sounds like a valuable enhancement.
----
A: The same approach applies to FDF doc. There are two versions of
FDFDoc.Save method. One accepts a filename, the other accepts a memory
buffer. You can use the latter version of FDFDoc.Save() method to
serialize the FDF in memory. For example:
// Extract data to FDF
try {
PDFDoc in_doc = new PDFDoc(output_path + "form1_filled.pdf");
in_doc.InitSecurityHandler();
FDFDoc doc = in_doc.FDFExtract();
// doc.SetPdfFileName("../form1.pdf");
byte[] buf = new byte[1];
int buf_sz = 1;
doc.Save(ref buf, ref buf_sz, SDFDoc.SaveOptions.e_remove_unused);
in_doc.Close();
} catch (PDFNetException e) {
Console.WriteLine(e.Message);
}