You are viewing limited content. For full access, please sign in.

Question

Question

Workflow Attach pdf eDoc to Document from Document's Pages

asked on October 16, 2015 • Show version history

Hello,

I cannot manage to have this script working that attaches a pdf eDoc to a document already stored in the repository, whereby the workflow (9.2.1.227) has to generate the pdf as the electronic counterpart of the document's pages.

The script is a mixture of Ed Heaney's code snippet as well as Devin Goble's. At this stage the script creates a non-empty memory stream and manages to attach a pdf file but the latter is empty (0 byte):

... despite the document has 1 page:

 

        protected override void Execute()
        {
            var de = new DocumentExporter();

            //Convert the documents to PDF and store in a memory stream
            var ms = new System.IO.MemoryStream();
            DocumentInfo docInfo = Document.GetDocumentInfo(this.BoundEntryId, this.RASession);

            de.ExportPdf(docInfo, docInfo.AllPages, PdfExportOptions.IncludeText, ms);
            this.SetTokenValue("MemoryStreamCount", ms.Length);

            //Don't want anybody else messing around while we're working
            docInfo.Lock(LockType.Exclusive);

            using (Stream edocStream = docInfo.WriteEdoc("application/pdf", ms.ToArray().Length))
            {
                edocStream.Write(ms.ToArray(), 0, 0);
            }
            docInfo.Extension = ".pdf";

            //Important
            docInfo.Save();
            //Cleanup
            docInfo.Unlock();
            docInfo.Dispose();
        }

Thanks in advance for advising,

Stéphane

0 0

Answer

SELECTED ANSWER
replied on October 16, 2015

Try this:

 var de = new DocumentExporter();
            //Convert the documents to PDF and store in a memory stream
            var ms = new System.IO.MemoryStream();
            DocumentInfo docInfo = Document.GetDocumentInfo(this.BoundEntryId, this.RASession);
            de.ExportPdf(docInfo, docInfo.AllPages, PdfExportOptions.IncludeText, ms);
            this.SetTokenValue("MemoryStreamCount", ms.Length);

            //Don't want anybody else messing around while we're working
            docInfo.Lock(LockType.Exclusive);
            using (Stream edocStream = docInfo.WriteEdoc("application/pdf", ms.ToArray().LongLength))
            {
                edocStream.Write(ms.ToArray(), 0, ms.ToArray().Length);
            }

            docInfo.Extension = ".pdf";
            //Important
            docInfo.Save();
            //Cleanup
            docInfo.Unlock();
            docInfo.Dispose();

You were close though where it has the edocStream change the second 0 to ms.ToArray().Length. I was able to do this and have the code working.

0 0

Replies

replied on October 16, 2015

Many thanks Cristobal: works perfect now !

 

Stéphane

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.