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

Question

Question

sdk export

asked on April 7, 2017

I want to simply export a tiff image from my repository to a windows directory.  How can I do this via sdk script in C#?

*NOTE - I want the tiff, not a pdf.

 

Thanks!

Benjamin

0 0

Answer

SELECTED ANSWER
replied on April 10, 2017

If you're doing this in Workflow, then you'll need a SDK script activity. In it, you need to add references to Laserfiche.DocumentServices (the version should match the version of Laserfiche.RepositoryAccess, which matches the version of your Workflow installation) and System.IO. In the Script's Default Entry section in the activity's properties, set the entry you want exported. If using Find Entry, then pick the entry you found:

The script looks like this:

DocumentInfo doc = (DocumentInfo)this.BoundEntryInfo;
DocumentExporter docExporter = new DocumentExporter();
string exportPath = @"c:\temp\test.tif";
int pageNumber = 1;
docExporter.PageFormat = DocumentPageFormat.Tiff;

using (FileStream fs = File.OpenWrite(exportPath))
   docExporter.ExportPage(doc, pageNumber, fs);

The Workflow server service user needs write access to the folder where you'll be saving these files.

If you're not running this code in Workflow, then you need to make your own connection to Laserfiche and "%(SearchRepository_FirstResult_ID)" is just a string. 

1 0

Replies

replied on April 7, 2017

Use the DocumentExporter class in Laserfiche.DocumentServices. Here is a simple example:

DocumentInfo doc = Document.GetDocumentInfo(docId, session);
DocumentExporter docExporter = new DocumentExporter();
string exportPath = @"c:\test.tif";
docExporter.PageFormat = DocumentPageFormat.Tiff;

using (FileStream fs = File.OpenWrite(exportPath))
    docExporter.ExportPage(doc, pageNumber, fs);

You can also export the raw image directly by using doing doc.GetPageInfo(pageNum).ReadPagePart(PagePart.Image), but the DocumentExporter method is the recommended way.

1 0
replied on April 10, 2017

I cannot find any way to successfully reference DocumentInfo.  How can I select the document for export without that option?  Or am I missing an include/using statement?

.ExportPage seems to be deprecated unless it is related to the above issue.

 

Thanks!

0 0
replied on April 10, 2017
DocumentInfo doc = (DocumentInfo)this.BoundEntryInfo;

 

0 0
replied on April 10, 2017

The problem is that I can't get 

DocumentInfo doc = (DocumentInfo)this.BoundEntryInfo;

to resolve.  What using statement or reference is/are necessary for documentinfo?

0 0
replied on April 10, 2017

Are you using a Script or SDK script activity?

0 0
replied on April 10, 2017

DocumentInfo comes from the Laserfiche.RepositoryAccess assembly, e.g.

using Laserfiche.RepositoryAccess;

 

replied on April 10, 2017

I was simply including sdk references in a visual studio c# project.  Can a tiff be exported directly from a workflow script?  That would solve my problem.

0 0
replied on April 10, 2017

Wait, you tagged this thread as Workflow. You're not using Workflow to run the script?

The code Robert pasted above assumes you have established a session to the repository ("session") and have a the ID of the document you want to retrieve ("docId"). Do you have those in your code?

If you choose to run this script from Workflow, the SDK Script activity takes care of establishing the connection and retrieving the entry info for you.

 

 

 

0 0
replied on April 10, 2017

I'm quite amenable to swapping this over to a workflow script if that eliminates some steps.  How do I get the docId and session for his first statement?

0 0
replied on April 10, 2017

Maybe you can give more details on what this code is trying to accomplish? When is it supposed to run, how will it know which documents to export?


// Using the overloaded RepositoryRegistration constructor
RepositoryRegistration myRepoReg = new RepositoryRegistration("MyServerName", "MyRepositoryName");
Session session = new Session();
session.LogIn("MyUserName", "MyPassword", myRepoReg);

 

0 0
replied on April 10, 2017

The idea is as follows:

A form has been filled out by a user and saved down to the repository as a tiff image file.  All I want to do is export that file to a windows directory, such as C:

There will only ever be one entry at the specified path, so I'm using a Find Entry command and giving it the full path.

What would be the best way to go about this?

0 0
replied on April 10, 2017
DocumentExporter exp = new DocumentExporter();
DocumentInfo doc = Document.GetDocumentInfo("%(SearchRepository_FirstResult_ID)", RASession);
exp.ExportPages(doc,doc.AllPages,@"C:\test.tiff");

So, this is the code I'm working with at the moment.  It gives me Entry not found. [9001][9001], despite the obvious presence of the file in question.  When running a workflowapi.trackinformation for the path of the first result, I get an accurate response.  What am I doing wrong?

0 0
replied on April 10, 2017 Show version history

You are passing in the untranslated token value for the entry ID. You need to get the actual integer ID from the token value.

0 0
replied on April 10, 2017 Show version history

Attempting to parse the ID via Int32.parse(token) yields: "Input string was not in a correct format."

0 0
replied on April 10, 2017

If someone could please respond with a full answer in c#, instead of instructions, that would be great.  I honestly don't much care how this export is accomplished.  Only that it is accomplished and that I can reverse engineer the answer for understanding.  I'm kind of stuck here.

 

Thanks!

0 0
replied on April 10, 2017 Show version history

Try this to resolve the token value:

int docId = Int32.Parse(this.GetTokenValue("SearchRepository_FirstResult_ID"));

Correction: I think you don't pass in the token surrounded by %().

0 0
SELECTED ANSWER
replied on April 10, 2017

If you're doing this in Workflow, then you'll need a SDK script activity. In it, you need to add references to Laserfiche.DocumentServices (the version should match the version of Laserfiche.RepositoryAccess, which matches the version of your Workflow installation) and System.IO. In the Script's Default Entry section in the activity's properties, set the entry you want exported. If using Find Entry, then pick the entry you found:

The script looks like this:

DocumentInfo doc = (DocumentInfo)this.BoundEntryInfo;
DocumentExporter docExporter = new DocumentExporter();
string exportPath = @"c:\temp\test.tif";
int pageNumber = 1;
docExporter.PageFormat = DocumentPageFormat.Tiff;

using (FileStream fs = File.OpenWrite(exportPath))
   docExporter.ExportPage(doc, pageNumber, fs);

The Workflow server service user needs write access to the folder where you'll be saving these files.

If you're not running this code in Workflow, then you need to make your own connection to Laserfiche and "%(SearchRepository_FirstResult_ID)" is just a string. 

1 0
replied on August 10, 2017

Hi, i'm trying your solution to export in PDF but it looks like this extension is not valide. How can I do ?

0 0
replied on August 10, 2017

Are you trying to export the images as PDF or the PDF component of the document?

0 0
replied on August 10, 2017

PDF component

0 0
replied on August 10, 2017 Show version history

Then this not the script you're looking for. You'll need to use DocumentExporter.ExportElecDoc instead.

1 0
replied on August 14, 2017

Thank you, that's working.

 

Regards

0 0
replied on September 14, 2017 Show version history

Hello all,

I'm following your tutorial on exporting a document from the Repository. It works if I export a tiff, but not with an XML. It comes empty.

I tried setting docExporter.PageFormat = DocumentPageFormat.Text; and this downloads the XML with the content in it, but as text, not XML. There are no tags in it.

Here is what I've tried so far. What should I adjust to be able to export XMLs from the repository? 

            string thisFile = GetTokenValue("ForEachEntryForeachxmlfilefound_CurrentEntry_Name").ToString();

           /* */
            DocumentInfo doc = (DocumentInfo)this.BoundEntryInfo;
            DocumentExporter docExporter = new DocumentExporter();
            string exportPath = @"\\server\share\Temp\success\" + thisFile + ".xml";
            int pageNumber = 1;
            docExporter.PageFormat = DocumentPageFormat.Text;

            using (FileStream fs = File.OpenWrite(exportPath))
            docExporter.ExportPage(doc, pageNumber, fs);

 

Administrator edit: removed server name as it contained personal identifying information.

replied on September 15, 2017

Hello all,

I'm following your tutorial on exporting a document from the Repository. It works if I export a tiff, but not with an XML. It comes empty.

I tried setting docExporter.PageFormat = DocumentPageFormat.Text; and this downloads the XML with the content in it, but as text, not XML. There are no tags in it.

Here is what I've tried so far. What should I adjust to be able to export XMLs from the repository? 

 

 string thisFile = GetTokenValue("ForEachEntryForeachxmlfilefound_CurrentEntry_Name").ToString();

/* */
 DocumentInfo doc = (DocumentInfo)this.BoundEntryInfo;
 DocumentExporter docExporter = new DocumentExporter();
 string exportPath = @"\\server\share\Temp\success\" + thisFile + ".xml";
 int pageNumber = 1;
 docExporter.PageFormat = DocumentPageFormat.Text;

 using (FileStream fs = File.OpenWrite(exportPath))
 docExporter.ExportPage(doc, pageNumber, fs);

 

0 0
replied on September 15, 2017

The xml content is in the electronic file portion of the LF document (not in the LF pages portion), so you would export it like this:

string exportPath = @"\\server\share\Temp\success\" + thisFile + ".xml";

docExporter.ExportElecDoc(documentInfo, exportLocation);

 

1 0
replied on September 15, 2017

Good morning Robert, hey thank you! That did the trick. 

Thanks again,

 

Raul Gonzalez

0 0
replied on September 15, 2017 Show version history

Hey, now I'm trying to download a PDF using the same strategy, but what happens is that it creates a PDF with the XML content inside, instead of the PDF content.

 

I have both in the same code, I didn't know how to separate them.

 

            string thisFile = GetTokenValue("ForEachEntryForeachxmlfilefound_CurrentEntry_Name").ToString();
            string thisPDF = GetTokenValue("SearchRepositoryformatchingpdf_FirstResult_Name").ToString();

           /*Donwload the XML */
            DocumentInfo doc = (DocumentInfo)this.BoundEntryInfo;
            DocumentExporter docExporter = new DocumentExporter();
            string exportPath = @"\\server\share\Temp\success\" + thisFile + ".xml";
            int pageNumber = 1;
            docExporter.ExportElecDoc(doc, exportPath);
            //docExporter.PageFormat = DocumentPageFormat.Text;

            using (FileStream fs = File.OpenWrite(exportPath))
            docExporter.ExportPage(doc, pageNumber, fs);



            /*Donwload the PDF */
            DocumentInfo docPDF = (DocumentInfo)this.BoundEntryInfo;
            DocumentExporter docExporterPDF = new DocumentExporter();
            string exportPathPDF = @"\\server\share\Temp\success\" + thisPDF + ".pdf";
            int pageNumberPDF = 1;
            docExporterPDF.ExportElecDoc(docPDF, exportPathPDF);
            //docExporter.PageFormat = DocumentPageFormat.Text;

            using (FileStream fs = File.OpenWrite(exportPathPDF))
            docExporterPDF.ExportPage(docPDF, pageNumberPDF, fs)
0 0
replied on September 15, 2017

Use the DocumentExporter.ExportPdf method to export the image pages as a pdf.

0 0
replied on September 22, 2017 Show version history

Robert, when I try using it like this I get an error that says "No overload for method 'ExprotPdf' takes two arguments"

I'm guessing I'm using it incorrectly. Can you shed some light on how to properly use it?

           DocumentInfo doc = (DocumentInfo)this.BoundEntryInfo;
            DocumentExporter docExporter = new DocumentExporter();
            string exportPath = @"\\server\share\Temp\success\" + thisPDF + ".pdf";
            int pageNumber = 1;
            docExporter.ExportPdf(doc, exportPath);
            //docExporter.PageFormat = DocumentPageFormat.Text;

            using (FileStream fs = File.OpenWrite(exportPath))
            docExporter.ExportPage(doc, pageNumber, fs);

 

0 0
replied on September 22, 2017 Show version history

I updated it to this, based on another tutorial of your that I found out there. Hopefully this will work.

 

            DocumentInfo doc = (DocumentInfo)this.BoundEntryInfo;
            DocumentExporter docExporter = new DocumentExporter();
            string exportPath = @"\\server\share\Temp\success\" + thisPDF + ".pdf";
            int pageNumber = 1;
            docExporter.ExportElecDoc(doc, exportPath);
            //docExporter.PageFormat = DocumentPageFormat.Text;

            using (FileStream fs = File.OpenWrite(exportPath))
            //docExporter.ExportPage(doc, pageNumber, fs);
            docExporter.ExportPdf(doc, doc.AllPages, PdfExportOptions.None, fs);

 

0 0
replied on September 22, 2017 Show version history

The DocumentExporter.ExportPdf method requires 4 inputs:

    1.) DocumentInfo object  (Your "doc")

    2.) PageSet object  (Your "doc.AllPages")

    3.) PDFExportOptions  (Your "PdfExportOptions.None"

    4.) Path or Stream  (Your "fs")

 

Your code is placing the PDF into a FileStream .  The other option without a FileStream would be to export by providing the path.

To export to a path, remove your Using block and replace it with:

docExporter.ExportPdf(doc, doc.AllPages, PdfExportOptions.None, exportPath);

 

1 0
replied on September 26, 2017

Bert, that worked; thanks.

0 0
replied on October 2, 2020

I'm wanting to do something similar to this.

(Export a laserfiche file's metadata as an xml file so another program can use it)

 

I've been following the steps that other users have done here but I keep getting an error in the workflow when I run the SDK which says:

"Entry point was not found".

 

I'll attach the code I'm currently using, any pointers would be greatly appreciated as I'm a bit new to the SDK and C#

string thisFile = GetTokenValue("FindEntries_EntriesFoundCount").ToString();


                /* */
                DocumentInfo doc = (DocumentInfo)this.BoundEntryInfo;
                DocumentExporter docExporter = new DocumentExporter();
                //string exportPath = @"\\server\LF Dump\Temp\success\" + thisFile + ".xml";
                int pageNumber = 1;
                docExporter.PageFormat = DocumentPageFormat.Text;

                string exportLocation = @"\\c\LF Dump\Temp\success\" + thisFile + ".xml";
                //using (FileStream fs = File.OpenWrite(exportLocation))
                docExporter.ExportElecDoc(doc, exportLocation);

 

0 0
replied on October 5, 2020

That error message doesn't look like something returned by the LF SDK. Can you get more details about the error, maybe a call stack?

0 0
replied on October 5, 2020

Your code might be missing a reference to the Laserfiche.DocumentServices library.

0 0
replied on October 10, 2022

Hi Team,

 

I have a use case where I want to download all the version of the document. So let's say if a document has 4 version associated with it, represent 4 different documents but attached to single entry ID in laserfiche, how can i download the document using JRA SDK? 

Does anyone have any idea on this? 

The download API provided by SDK from document class is based on entry ID which will download the latest version in the tree. But no API method to download all the version or any specific version in the tree.

 

Any help on this would be appreciated. 

Thank you

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

Sign in to reply to this post.