VBA Access Image Size and Resize Pages

I am writting a program that allows us to load all our old files from our archives and exports them out as PDFs and text files to load into our SQL database so we can search everything.  I have files dating back to Corel 5 which dont open in Corel 2019 so I loaded Corel X5 on my computer as well.  I have several questions.

#1, is there any API call to get the version of the File

#2 is there a way to recurse through the pages of the document do a select all on that page and get the page size.

#3 once i have the page size I will want to change the document paper size to match so that when it exports it doesnt cut off.

Does anyone know of such a method or can you point me in the right direction.

Thanks

Robert

  • #1  I can’t say for sure, but I think not. But you can check result of Import function

    #2 you can use this code:

    Dim p As Page, w#, h#

    For Each p In ActiveDocument.Pages

          p.GetSize w, h  'get width and height

    Next p

    #3 you have two option: a) change page size and export all shapes within current page; b) you can select  shapes you need and export selected shapes only. To change paper size use: p.SetSize width, height, where p As page

  • The information about the version is available in the CDR-File. But I have not yet a clue to read out this automatically.
    Maybe one other has more skills to automate the following steps:

    Method 1:
    If you go (at least under Win7 Pro, but most likely at least all newer windows versions) with the explorer to the folder where the files in question are located, do a right click (best thing on a free area, but not on the file name) in the head line and select 'ProductName', then you get a tag for each CDR-File with the Corel version used for this.

    Method 2: (more complicated, but provides even more information):
    You need a tool to un-compress packed files like 7-Zip or WinRar (with that I tested it), open in their File-Manager the folder with the CDR-Files in question and click on a CDR-File. Then you will see a sub folder structure with a folder called 'META-INF'. Go into this folder, inside you find a file Metadata.xml. Search there for '<cdr:ProductName>' and you will see the version behind.

    With that you have a – surly not really easy and fast – way to read out the 'ProductName' automatically:
    You need to have a tool installed on your PC where you may decompress a part of an archive with a command line interface. Although the Corel files are compressed with PKUnzip, other tools will work most likely as well. (I did similar actions with 7Zip, this comes by default with a CLI)
    Then you can create in VBA for each *.CDR-File a command line which advices the packer to extract from the CDR-'Archive' the file 'META-INF\metadata.xml' to somewhere on your PC. If this file is available, you can open it as a simple text file and search for <cdr:ProductName> and </cdr:ProductName> and cut out the part between and you have the needed information.

    One tip, if you want to follow this way: Do not send the command line directly with the VBA command 'Shell' to the operating system, write it in a small batch file and delete (with a line in the batch file) it afterwards. Then you can check after you started the batch file in VBA the presence of this file. As long as this file is available, the decompression isn't completed.

  • In X5 you can do something like this to get the version of a cdr file:

    Sub MyFileVersion()
        Dim v As Long, f As String
    
        f = "C:\Temp\Rects_7.cdr"
        v = CorelScript.GetCDRFileVersion(f)
    
        MsgBox v
    End Sub
    

    -Shelby

  • Regarding getting file version (Program name) I've found these on StackOverflow which might help get this info:

    https://stackoverflow.com/questions/50262556/vba-get-all-file-properties

    https://stackoverflow.com/questions/5651890/using-vba-to-get-extended-file-attributes

    One of these might give you something you could adapt to get the Program Name.

    I've quickly checked a couple of files on my own network and checked these properties and they show different versions depending on which version the file was saved in.

  • Regarding getting file version (Program name) I've found these on StackOverflow which might help get this info:

    https://stackoverflow.com/questions/50262556/vba-get-all-file-properties

    https://stackoverflow.com/questions/5651890/using-vba-to-get-extended-file-attributes

    One of these might give you something you could adapt to get the Program Name.

    I've quickly checked a couple of files on my own network and checked these properties and they show different versions depending on which version the file was saved in.