Save PDFDOc in a stream

392 views
Skip to first unread message

epo...@gmail.com

unread,
Feb 19, 2014, 8:41:52 AM2/19/14
to pdfne...@googlegroups.com
Hi,
I am developing a Windows Store App with PDFNet SDK.

After open my file, the user adds annotations.

Windows.Storage.Streams.IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.ReadWrite);
using (var outStream = stream.GetOutputStreamAt(0))
{
doc = new pdftron.PDF.PDFDoc(stream, file.Path);
}

At the end, the user save this modficiations, but I want to save all the modifications in a new stream, not in a local file.
Is it possible ?

Thanks

Tomas Hofmann

unread,
Feb 19, 2014, 12:49:47 PM2/19/14
to pdfne...@googlegroups.com
Hi epokinc,

If you just want to save the Annotations, I think you want to take a look at XFDF documents. It's basically a XML document with annotation information. You can take a look at the FDFTest sample in the PDFNetWinRTSamples project for a demo on how to use this. You can export annotations from a PDF document and then save them as XFDF.

If this does not solve your problem, could you please add some details as to what your scenario looks like, and we will be happy to help.

Best Regards,
Tomas Hofmann

Aaron Gravesdale

unread,
Feb 19, 2014, 12:59:08 PM2/19/14
to pdfne...@googlegroups.com
Note that, if you're simply asking how to save a modified PDFDoc to a stream instead of a file, you can do so with the following API:

http://www.pdftron.com/pdfnet/PDFNet/html/M_pdftron_PDF_PDFDoc_Save_1.htm

Please let us know whether this helps and if you have further questions.

epo...@gmail.com

unread,
Feb 20, 2014, 3:28:26 AM2/20/14
to pdfne...@googlegroups.com
Thanks for your answers,
This is exactly what I need, but I don't find this method  in SDK for windows store app, 

I have only this 3 methods :

       
        public void Save(string path, SDFDocSaveOptions flags);
       
        public IAsyncAction SaveAsync(SDFDocSaveOptions flags);
      
        public IAsyncAction SaveAsync(IStorageFile path, SDFDocSaveOptions flags);


I need to save my document, with all annotations in a Stream and send this stream to other service for encryption.
Do you know how I can get a stream with PDFDoc without creating a local file?

Aaron Gravesdale

unread,
Feb 20, 2014, 1:44:34 PM2/20/14
to pdfne...@googlegroups.com
My mistake, my link was to the .Net API.  The WinRT API does not currently contain a method for saving a PDFDoc to a stream (http://www.pdftron.com/pdfnet/mobile/PDFWinRTDoc/html/dc571dbf-15e2-c6c0-fd61-e08d772a9d55.htm).  We will start the process of adding them and let you know when we have a new build for you to try.

epo...@gmail.com

unread,
Feb 21, 2014, 4:49:17 PM2/21/14
to pdfne...@googlegroups.com
Ok, 
as it is not possible, I look at XFDF documents.
I save my annotation in XFDF and I can merge this annotation with my original pdf.

But I want to delegate the saving (for Encryption) and the opening (for decryption) to my service.

FDFDoc fdf = doc.FDFExtract(PDFDocExtractFlag.e_both);
var outputFilePath = Path.Combine(path, "File1.xfdf");
fdf.SetPdfFileName(outputFilePath);
var s = fdf.SaveAsXFDF();

//My method to save
WriteFile("File1.xfdf", s);


then I open my pdf and merge with File1.xfdf.

If I open directly my file without my service, it's ok :

String input_file_path = filefdf.Path;
FDFDoc fdf_doc1 = new FDFDoc(FDFDoc.CreateFromXFDF(input_file_path));
doc.FDFMerge(fdf_doc1);


If I use my service ReadFile 

byte[] bytexfdf = ReadFile("File1.xfdf");
FDFDoc fdfDoc = new FDFDoc(bytexfdf, bytexfdf.Length);

I have this error :

WinRT information: Exception: 

Message: Header not found

Conditional expression: false

Filename   : Parser.cpp

Function   : trn::SDF::Parser::SkipHeader

Linenumber : 718


How could I create a FDFDoc with a stream of xfdf file ?

Support

unread,
Feb 21, 2014, 5:43:36 PM2/21/14
to pdfne...@googlegroups.com

FYI : The extra Save() method(s) will be added as part of PDFNet v.6.2 (to be released in first weeks of March).
In the meantime you could load XFDF from a string:

pdftron.FDF.FDFDoc.CreateFromXFDF("<?xml version=\"1.0\" encoding=\"UTF-8\" ?><xfdf xmlns=\"http://ns.adobe.com/xfdf\...");

Check out the FDF sample project:
Reply all
Reply to author
Forward
0 new messages