IPXC_DocumentProps::SpecVersion /catalog/version v.s. /extensions/baseversion  SOLVED

PDF-XChange Editor SDK for Developers

Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Paul - PDF-XChange, Vasyl - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
zarkogajic
User
Posts: 1553
Joined: Thu Sep 05, 2019 12:35 pm

IPXC_DocumentProps::SpecVersion /catalog/version v.s. /extensions/baseversion

Post by zarkogajic »

Hi Support,

To get the PDF version for a document I use IPXC_DocumentProps.SpecVersion.

For a specific document the version returned is "1.7"

The same version is returned by EUEditor and Ad0be PRO. But, Ad0be Reader displays "1.3".

Now, the document does have "%PDF-1.3" in header.

And this is the catalog:

<</Type /Catalog/Pages 2 0 R/Outlines 81 0 R/Version /1.3/AcroForm 82 0 R/DSS 87 0 R/Extensions <</ESIC <</BaseVersion /1.7/ExtensionLevel 5>>/ADBE <</BaseVersion /1.7/ExtensionLevel 8>>>>>>

So (I guess), the SpecVersion implementation does look into /Extensions (/BaseVersion) and this is why the version returned is "1.7".

However, for what I need this - I need version 1.3 to be returned. That is: my way of needed determination is: look at header, then catalog and take higher value. Ignore /extensions.

Any chance you can provide some parameters to the SpecVersion implementation so that 1.3 is returned in this particular case?

p.s.
Or the answer will be: make your own implementation of SpecVersion ;)

-žarko
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 13001
Joined: Wed Jan 03, 2018 6:52 pm

Re: IPXC_DocumentProps::SpecVersion /catalog/version v.s. /extensions/baseversion

Post by Daniel - PDF-XChange »

Hello, zarkogajic

i have raised this with the Devs for an answer. Once one of them has a few moments, they should be along to help!

Kind regards,
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
[email protected]
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3608
Joined: Thu Jul 08, 2004 10:36 pm

Re: IPXC_DocumentProps::SpecVersion /catalog/version v.s. /extensions/baseversion

Post by Ivan - Tracker Software »

Unfortunately, there is no easy way to get the raw spec version. The Adobe Extension was taken into account for historical reasons.

And getting the spec version by your own code is not easy, as the API does not provide access to the version in the document header :(

We will try to come up with some solutions in the next versions.
PDF-XChange Co Ltd. (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.
zarkogajic
User
Posts: 1553
Joined: Thu Sep 05, 2019 12:35 pm

Re: IPXC_DocumentProps::SpecVersion /catalog/version v.s. /extensions/baseversion

Post by zarkogajic »

Hi Ivan,

Thanks.

Suggestion: allow to get all 3 versions: header, (last trailer) catalog and extension.

-žarko
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 13001
Joined: Wed Jan 03, 2018 6:52 pm

IPXC_DocumentProps::SpecVersion /catalog/version v.s. /extensions/baseversion

Post by Daniel - PDF-XChange »

:)
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
[email protected]
zarkogajic
User
Posts: 1553
Joined: Thu Sep 05, 2019 12:35 pm

Re: IPXC_DocumentProps::SpecVersion /catalog/version v.s. /extensions/baseversion  SOLVED

Post by zarkogajic »

Hi,

Actually, I can get the header/catalog version with some coding, so no need to bother :)

Consider "solved".

-žarko
zarkogajic
User
Posts: 1553
Joined: Thu Sep 05, 2019 12:35 pm

Re: IPXC_DocumentProps::SpecVersion /catalog/version v.s. /extensions/baseversion

Post by zarkogajic »

And here's C# code section for the future readers in need:

Code: Select all

using System;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using System.Text;
using System.Text.RegularExpressions;

private static double ParsePdfVersion(string s, string matchPrefix)
{
    Match match = Regex.Match(s, Regex.Escape(matchPrefix) + @"(\d+)\.(\d+)");

    if (match.Success)
    {
        return int.Parse(match.Groups[1].Value) + int.Parse(match.Groups[2].Value) / 10.0;
    }

    return 0.0;
}

private double GetVersion(double fromGetVersion)
{
    double result = fromGetVersion;

    // Files opened via IStream will have File_ == null.
    if (IDocument.SrcInfo.File_ == null)
        return result;

    IStream stream;
    IDocument.SrcInfo.File_.GetStream(out stream);

    double verFromHeader = 0.0;

    long oldPosition;
    byte[] buffer = new byte[128];
    IntPtr pcbRead = Marshal.AllocHGlobal(sizeof(int));

    try
    {
        stream.Seek(0, 1 /* STREAM_SEEK_CUR */, out oldPosition);
        stream.Seek(0, 0 /* STREAM_SEEK_SET */, out _);

        try
        {
            stream.Read(buffer, buffer.Length, pcbRead);

            int bytesRead = Marshal.ReadInt32(pcbRead);
            string s = Encoding.ASCII.GetString(buffer, 0, bytesRead);

            verFromHeader = ParsePdfVersion(s, "%PDF-");
        }
        finally
        {
            stream.Seek(oldPosition, 0 /* STREAM_SEEK_SET */, out _);
        }
    }
    finally
    {
        Marshal.FreeHGlobal(pcbRead);
    }

    double verFromCatalog = 0.0;

    IPXS_Document doc = IDocument.CosDocument;
    IPXS_PDFVariant root;
    doc.Get_Root(out root);

    if (root != null)
    {
        string verFromCatalogStr;
        if (root.Dict_GetName("Version", "0.0", out verFromCatalogStr) == 0) // S_OK
        {
            verFromCatalog = ParsePdfVersion(verFromCatalogStr, "");
        }
    }

    if (verFromCatalog > 0 && verFromCatalog > verFromHeader)
        result = verFromCatalog;
    else if (verFromHeader > 0)
        result = verFromHeader;

    return result;
}
Note:
- IDocument is IPXC_Document
- the fromGetVersion first retrieved via IPXC_DocumentProps.SpecVersion

-žarko