Free Support Forum - groupdocs.com

Saving Annotated PDF to database


#1

Hi,


I am evaluating annotation library for MVC. I have opened document from database as stream and shown.

After annotation I want to save document as file stream in SQL database. Please suggest how I will be able to achieve this.

#2

Hello Sumit,

Thank you for your interest in GroupDocs.Annotation for .NET. If we understand your scenario correct, you want to open a document from a database as a stream, add different annotations to it, obtain a new document with added annotations inside it, and save this new document to the database. If our assumption is correct, here is how you can do this.

1. For opening a document from database as a stream you should pass it into the “.Stream” method from the GroupDocs.Annotation widget. There are two overloads of this method, we suggest you to use the one, which obtains stream and filename (with extension). This filename will be useful for you in further.
2. Add different annotations onto it, as you want.
3. Make an export. Let’s say your filename is “filename.pdf”. In that case here is a source code:

String wrapped_filename = “temp\S\” + “filename.pdf”;
const string _groupdocsTemp = “Saaspose”;
Int64 sessionId = Groupdocs.Web.Annotation.FileSessionMapper.Instance[wrapped_filename];
if (sessionId == 0)
{
//file was not opened in the Annotation before this moment and cannot be exported
}
string tempFileName = AnnotationsExporter.Perform(sessionId, wrapped_filename);
string tempFilePath = Path.Combine(Path.GetTempPath(), _groupdocsTemp, tempFileName);

4. Now the “tempFilePath” string variable contains a full path to the PDF-version of the original document with annotations, which are embedded inside this file. Now you can read this file as a stream as you want: using File.Open, or FileStream, or by using any other method.

5. Save this stream to your database as usual.

That’s all.

If you will have more questions please feel free to contact us.


#3

Thanks for your response.


You assumption is correct, let me implement this solution, I will get back to you in case of any issue.

Thanks