Community

Export Photo using script

Hi,
I have some document to capture data, crop a photo from each document and export those document to a folder location as .pdf file and the photo's .jpg file. But i need to export those photo's and the pdf file in same name format. Like if a document which is caring SL value "9999", i need to export this document and the photo also as name of "9999.pdf"(for document) and "9999.jpg"(for cropping photo). Unfortunately in ABBYY Flexicapture i didn't get any option to define a different export location for cropped photo.
I'm using Flexicapture 9.0 for my project.
Now do i need to use a script for getting this result? (I never write any script on image, so if i need to use script for this then i will be really helpful for me if i get any sample script)
Thank's in advance

Was this article helpful?

0 out of 0 found this helpful

Comments

6 comments

  • Avatar
    Katja Ovcharova
    Dear Rasel,

    If I understood you right, you are going to export image field to some location different from the default, that is, the sibfolder of the main document export folder (please correct me if I am wrong).
    If so, then you will indeed need to implement an export script.
    In the Document definition properties, Export settings click Add... and choose Custom export (script), then insert your code there.

    dim fso, folderName
    set fso = CreateObject("Scripting.FileSystemObject")
    folderName = "c:\Temp\Output" 'here you write the desired output location

    ' check whether the folder exists and create if necessary

    if Not fso.FolderExists( folderName ) then
    fso.CreateFolder folderName
    end if

    ' create image saving options - choose the appropriate parameters
    ' please note that in FC9 jpeg cannot be saved as BlackAndWhite

    dim imageOptions
    set imageOptions = ExportTools.NewImageSavingOptions
    imageOptions.Format = "jpg"
    imageOptions.ColorType = "FullColor"
    imageOptions.Resolution = 200

    ' set the desired name and extension for the file depending on the selected format
    ' in my sample the file is named according to a text of some SL field from the document definition
    dim fileName
    fileName = fso.BuildPath( folderName, me.Field("Document Section 1\SL").Text & ".jpg" )
    ' here I use the field name that I see on your screenshot - probably a shorter alias would be more convenient
    me.Field("Document Section 1\National Life Insurance Co. Ltd").Value.SaveAs fileName, imageOptions


    You can find some additional information in the FlexiCapture 9 Help, section Appendix > Using scripts in ABBYY FlexiCapture >Sample scripts describing export (for samples themselves) / Using scripts to describe export (to see and understand the object model) and modify my sample script according to your needs.

    Hope this helps. Otherwise please dscribe your scenario in more details.
    0
  • Avatar
    Rasel
    Yes, that what i need. thank you so much.
    0
  • Avatar
    Rasel
    Hi there,

    I'm facing a new problem with this project. Here is a new case, I'm exporting all the document images by using above script. meanwhile we have some document set where the first page could be missing. now can anyone please help me to modify this script. i just need to set a simple condition into this script, And here is it: if the first page is not exist into the document set then it will export the rest images only.
    0
  • Avatar
    Vladislav Suvorov
    Hello,

    If I understood you right:
    1)Exported image field is always located on 1st page.
    2)You don't want script to work if 1st page is missing.
    The correction should be the following(please add first line before the existing script code and the second line at the very end - those lines are in bold):
    if me.Field("Document Section 1\National Life Insurance Co. Ltd").IsMatched then
    ' existing code
    end if

    Hope that helps,
    Vladislav
    0
  • Avatar
    Rasel
    Hello Suvorov,

    Thank you for your prompt replay. You understood absolutely what im looking for. I appreciate your input and i tried with your code. however Im still im getting this error "Index out of range" while exporting. im useing this following code:
    _______________________________________
    if me.Pages.Item(0).IsMatched then
    dim fso, folderName
    set fso = CreateObject("Scripting.FileSystemObject")
    folderName = "D:\Output files" 'here you write the desired output location

    if Not fso.FolderExists( folderName ) then
    fso.CreateFolder folderName
    end if


    dim imageOptions
    set imageOptions = ExportTools.NewImageSavingOptions
    imageOptions.Format = "jpg"
    imageOptions.ColorType = "FullColor"
    imageOptions.Resolution = 150


    dim fileName

    fileName = fso.BuildPath( folderName, me.Field("PAGE-1\AccNo").Text & "_" & me.Field("PAGE-1\CustomerID").Text & ".jpg" )
    me.Pages.Item(0).SaveAs fileName, imageOptions
    end if
    0
  • Avatar
    Vladislav Suvorov
    Hi Rasel,

    In this line of code
    if me.Pages.Item(0).IsMatched then
    you are referring to first page - please keep in mind if your document isn't empty there will always be the first page(meaning script will always work). But IPage does not have a method .IsMatched whatsoever. Thus your line of code basically generates an error and returns nothing.
    What I recommend is: please consider using
    if me.Field("Document Section 1\National Life Insurance Co. Ltd").IsMatched then
    because it checks if necessary field exists on the document and not if first page exists. Field name was taken from previous posts, please change it if you want to use another field.

    Hope that helps,
    Vladislav
    0

Please sign in to leave a comment.