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

Question

Question

SDK - DocumentImporter accepts correct parameters, but adds 1 extra page and can only find one TIF image (which it imports into incorrect page)

SDK
asked on September 9, 2019 Show version history

I'm getting some strange behavior from the SDK in a workflow designed to import one-page TIF files into a multi-page Laserfiche document.

The workflow looks like this:

 

And my custom query returns 50 results:

 

However, running the code below inserts 51 pages into my freshly created document (verified that it starts with 0 pages), and the only file path that I can get the DocumentImporter to import is from the first line of the database I'm looking up, and that imports into page 51. All other pages say there is no associated image.

            // Write your code here. The BoundEntryInfo property will access the entry, RASession will get the Repository Access session
            // Instantiates the current document as 'currentDocument'
            DocumentInfo currentDocument = Document.GetDocumentInfo(BoundEntryId, RASession);

            // The root path of the originating database/ cabinet files
            string rootPagePath = redacted;

            // The page in the directory (currently finds all file types, need to refactor to just find TIFs)
            string pagePath =
                rootPagePath
                + GetTokenValue("ForEachRow_subdir")
                + "\\"
                + GetTokenValue("ForEachRow_page_id")
                + ".TIF";

            // set the page number
            int pageNum = (int)GetTokenValue("ForEachRow_pagenum");
            PageRange pageRange = new PageRange(pageNum.ToString());

            // Write TIF page data to a new page

            //Create a new page at the end of the document
            PageInfo pInfo = currentDocument.InsertPage(pageNum);

            // Configure the document importer object
            DocumentImporter importer = new DocumentImporter();
            importer.Document = currentDocument;
            importer.OcrImages = false;

            // add the page to the new page
            importer.ImportImages(pagePath, pageRange); // puts the image (at the arg 1 path) into the document (at arg 2 path)

I can't find anything in the documentation that would explain this behavior, and I explicitly insert the pages at the desired index because I'm aware that some LF SDK methods start at a 1 index and I wanted to be sure.

My error logs also show that the pageNum and pagePath variables are completely correct, and pageNum never hits 51. It always stops exactly at 50, and each iteration has a correct pagePath as well. No errors are thrown.

I'm at a loss. Can anyone see anything incorrect about how I've gone about this?

0 0

Answer

SELECTED ANSWER
replied on September 9, 2019

I think you might be a little off base on what the parameters to ImportImages do.

On line 33 your comment reads: "puts the image (at the arg 1 path) into the document (at arg 2 path)"

However, the SDK documentation for the second argument reads: "A PageRange instance specifying which pages in the image file to import." So, if you are importing a file that contains three pages, you can specify a PageRange that only includes two of them.

Also, I'm pretty sure that ImportImages will create the necessary pages as it brings in each image, even if it's only a single image. Therefore, line 23 is unnecessary. There's a clue in the documentation for the other overloads of ImportImages: "If the image file contains multiple pages, then all of the pages will be imported in the order they appear in the file, with one page created in the document per image in the file." I'm assuming that the same is true of the versions that accept a PageRange, but it's not specified in the documentation. I've never used those versions, so I can't say for sure.

3 0

Replies

replied on September 10, 2019 Show version history

However, the SDK documentation for the second argument reads: "A PageRange instance specifying which pages in the image file to import." So, if you are importing a file that contains three pages, you can specify a PageRange that only includes two of them.

 

That sounds like exactly what my issue was. I interpreted it the opposite way - that I was selecting the pages of the destination document to import into, but in reality that parameter is for selecting the pages of the source image document to import. I removed that parameter and cleaned up some formatting lines, it's working beautifully now.

I was hesitant to trust the importer with inserting all pages in the correct order, but my logging and test cases are all working so I guess I have no choice but plenty of spot checks. Thanks again for your help!

0 0
replied on September 10, 2019

As long as the source has everything in the right order it should be fine. I just brought in 38 million multi-page TIFFs and didn't have any issues.

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

Sign in to reply to this post.