Community

Export Batch from tif to PDF

I have a custom export workflow that convert all documents definition into a pdf stream via SaveAsStream and Export Option are setup to as pdf format but I would like to also do the same for the original file witch come in as TIF. Let me explain a little better so we receive a TIF file into a hot folder then it gets recognize it seperate document once verified I create an XML with the data and convert each document into a stream (converted into PDF) and create an XML with that but I can't seem to find a way to have save the original file into PDF.

I was able to create 1 page with the FCTOOLS loadImage andSaveAs but it only does the first page or the page specified not the whole document and I'm trying to avoid any other libraries like iTextSharp.

Thanks
0

Comments

19 comments

  • Avatar
    Katja Ovcharova
    Hello psquare,

    What you described is possible with the Batch processing script which should be launched after the document export to XML and PDF is complete. This script is to be implemented in a custom stage of type Automatic, and this stage should be added to your Advanced workflow directly after the usual export.
    This script should do the following:
    1. Remove all document recognition results with the Batch.CleanRecognitionResults method.
    2. Assemble documents having one image source (check the Page.ImageSource) into one document using the Batch.MovePage method.
    3. Export the resulting merged document to PDF with the Document.SaveAs().

    Another variant is:
    1. Set up the document import (Image import profile) so a new document is created for each image file (that is, the whole incoming Tiff is considered a document).
    2. In your workflow after the import stage add a custom stage with a Batch processing script where you export the document to PDF using Document.SaveAs. In the same script you will then need to disassemble the document back. For that please Add a code where a new document will be created for every page (with CreateDocumentFromPage) and set for every document IsExcludedFromAutomaticAssembling = false (this will force FC to consider these documents disassembled, so they will be assembled according to the document definition at the following stage).
    3. Add usual Recognition stage and Export stage where your documents will be exported to XML/PDF.

    Hope this helps.
    0
  • Avatar
    psquare
    Hi Katja,

    Would you have a code example for the first solution?
    0
  • Avatar
    Katja Ovcharova
    Hello psquare,

    The sample script is below.

    for(int i = 0;i<>
    Batch.CleanRecognitionResults(Documents);

    System.Collections.Generic.List files = new System.Collections.Generic.List();
    for(int i=0;i<>
    {
    for(int j=0;j<>.Pages.Count;j++)
    {
    if (!files.Contains(Documents.Pages[j].ImageSource))
    {
    files.Add(Documents.Pages[j].ImageSource);
    }
    }
    }

    System.Collections.Generic.List pages = new System.Collections.Generic.List();
    for(int k = 0;k<>
    {
    for(int i=0;i<>
    for(int j=0;j<>.Pages.Count;j++)
    if (Documents.Pages[j].ImageSource == files[k])
    pages.Add(Documents.Pages[j]);
    IDocument doc = Batch.CreateDocumentFromPage(0,pages[0]);
    for(int i = 1;i<>
    Batch.MovePage(pages.Document,doc,pages[0].Index,doc.Pages.Count);
    pages.Clear();
    }

    string FilePath = "C:\\test\\Result_{0}.pdf"; //here you can implement your own file naming
    IExportImageSavingOptions exportSettings = FCTools.NewImageSavingOptions();
    exportSettings.Format = "pdf";
    for(int i = 0;i<>
    {
    Batch.Documents.SaveAs(string.Format(FilePath,i),exportSettings);
    }


    Please adjust it according to your needs.
    0
  • Avatar
    psquare
    Thank you I tweak it to my needs seems to work so far but if we are moving all the pages into one document in which case would there be more than one. hence why this line.
    for(int i = 0;i
    0
  • Avatar
    psquare
    Also now my batches stay on the verification station with an unprocessed document. How do I delete this document
    0
  • Avatar
    Katja Ovcharova
    Hello,

    Thank you I tweak it to my needs seems to work so far but if we are moving all the pages into one document in which case would there be more than one. hence why this line.
    for(int i = 0;i

    This line is for the case when you import images from different source files into the same batch, that is, for example put several multipage tiffs into the input folder.

    Also now my batches stay on the verification station with an unprocessed document. How do I delete this document

    Please use appropriate methods from the IBatch object, e.g. DeleteDocument.
    0
  • Avatar
    psquare
    k so I used the Batch.DeleteDocument(Batch.Documents(0)) but is there a way I can force the batch to the process stage because now if I go in project setup station and show all batches except processed I see my batch but it contains no document and the stage is empty.

    Thank you
    0
  • Avatar
    Timur
    Hello,

    Note that in order for the solution above to work properly, script stage should be added after usual export stage. In order to have batches routed to this stage after standard export stage, you need to make sure Exit Routes settings in both stages are correct.

    -Export stage should route batches to the next stage

    -Your second Export stage should route batches to the next stage or to processed.

    If the batch is visible after applying "show all batches except processed" filter, that means this batch was probably never routed to "Proccessed" stage and routing settings are incorrect somewhere

    You can find more information about stage and exit routes properties in help file:ABBYY FlexiCapture Help-Program settings-Set up ABBYY FlexiCapture Complex-Editing Stage properties-Exit Routes tab

    Please provide screenshots of your workflow settings if you encounter any further difficulties, so it is possible locate any possible mistakes if there was any misunderstanding.





    0
  • Avatar
    psquare
    Okay I understand what you are saying Timur but I'm not very familiar with the stage process.

    I create a customExport of UserType where a script is called and I perform the above but I think I'm missing an Exit Route to the processed stage.

    Basically when the customExport stage finishes it should check if the batch contains document if so send to exception if not send to processed (since I delete the document after processing it in the customExport Stage there is not more document in the batch so I know that everything worked out).

    How can I achieve this?
    0
  • Avatar
    Timur
    Hello,

    As you can see, there are two options in exit stages:
    1.By routing schema
    This type uses default settings, when batch is processed successfulle it is sent to the next stage otherwise - to excpetions.

    2.Custom
    Allows to specify multiple exit stages with diffrent conditions, conditions can be chosen from a list or created by scripts.


    To solve your task, try using the following approach:
    1.Use the "By routing schema option"

    2.Add a documents count check in the end of your second export:
    if(Batches.Documents.Count!=0)
    {
    Processing.ReportError("Documents count:"+Batches.Documents.Count.ToString());
    }

    If any documents are left, an error will be thrown and batch will be routed to exceptions instead of the next stage.












    0
  • Avatar
    psquare
    The problem is that after my custom export stage I do a Batch.DeleteDocument(Batch.Documents(0)) so that the document that was moved into 1 and and converted to PDF is now delete. But then there is nothing left in my batch.

    So I think that the routing is not being triggered because the batch contains nothing so it ends up just staying there with no stage.
    0
  • Avatar
    Timur
    Hello,
    Could you please provide a copy of your project for analysis?

    0
  • Avatar
    psquare
    I attached the workflow screenshot. So after verification it goes to CustomExport and I have script to process the batch processing CreateCustomExport(Batch, Documents, Processing).

    in the function CreateCustomExport I do a few things and that's where I run given by Katja but I modified it a little bit in which I added the following code
    p_docContentBytes = Batch.Documents(0).SaveAsStream(exportOptions)
    Batch.DeleteDocument(Batch.Documents(0))


    And i think that the fact that I delete de document at the end it leaves the batch with no document (like in the screenshot of my previous post) is causing this behavior. So my question is can i force the batch to Processed Stage programmatically? if not how can I force it to processed stage?

    Thanks
    0
  • Avatar
    Timur
    It looks like empty batches cannot be routed in any way, try creating an additional empty document definition and add an empty document at the of your script.
    0
  • Avatar
    psquare
    I do not need to delete the document I only deleted it because i do not want it to be treated as a unprocessed document but if I have control of the flow the I can send the batch to Processed? Is this possible?

    0
  • Avatar
    psquare
    I tried linking the processed stage to the previous and now the batch as stage processed but stays there?
    0
  • Avatar
    Herr Gerritsen
    Hello psquare,

    If you have done all the actions you would like to do with a batch it will end up in the final stage processed.
    In the project settings (or batch type settings) you can specify how long processed batches should stay in FlexiCapture. Standard Processed batches will stay in the system for 14 days. This gives you time to go back to a batch should something have gone wrong.


    0
  • Avatar
    psquare
    Yes I sent this to 1 day and it does not clear the batches that have nothing in them. They just stay there until i delete them manually.

    But instead of taking the processed file and copy them to a new document and then saving as PDF is there a way to do it with the original TIF file that I receive? I still have access to the original file as we keep them in case something happens. So would there be something in FCTOOL that i can take the image file and convert to pdf and leave my batch the way it is so that it gets processed properly?
    0
  • Avatar
    psquare
    I decided to try something and it seemed to work I don't know why because I had tried this before. Instead of deleting the document at the end I leave it there as unprocessed and the batch ends up in the processed stage like I wanted. So I guess thank all for your help it seems to work great.
    0

Please sign in to leave a comment.