IPXC_CState::Flags

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.
MiBa
User
Posts: 17
Joined: Fri Feb 19, 2016 1:30 pm

IPXC_CState::Flags

Post by MiBa »

Hallo everybody,

I want to enumerate all used colors on a page.

Code: Select all

public IEnumerable<ColorStateDto> GetColorStatesFromDocument() {
    for (uint pageIndex = 0; pageIndex < _pdfEditControl.Doc.CoreDoc.Pages.Count; pageIndex++) {
        var pageContent = _pdfEditControl.Doc.CoreDoc.Pages[pageIndex].GetContent(PXC_ContentAccessMode.CAccessMode_Readonly);
        for (uint cStateIndex = 0; cStateIndex < pageContent.CStatesCount; cStateIndex++) {
            var cstate = pageContent.GetCStateByIndex(cStateIndex);
            float c, m, y, k;
            float r, g, b;

            var cstateColor = cstate.FillColor[ColorType.ColorType_CMYK];      // <=== Exception
            cstateColor.GetCMYK(out c, out m, out y, out k);
            Color rgb = ColorTranslator.FromOle((int) cstate.FillColor.ValueRGB);
            var jjkColorState = new ColorStateDto()
            {
                Id = cStateIndex,
                PageNr = pageIndex,
                Typ = cstate.FillColor.CSType,
                IsUsed= CStateIsUsedOnPage(pageIndex, cstate),
                C = c,
                M = m,
                Y = y,
                K = k,
                Rgb = new ColorRgb{ R = rgb.R, G = rgb.G, B=rgb.B}
            };
            yield return jjkColorState;
        }
    }
}


private bool CStateIsUsedOnPage(uint pageIndex, IPXC_CState cstate) {
    var pagecontent = _pdfEditControl.Doc.CoreDoc.Pages[pageIndex].GetContent(PXC_ContentAccessMode.CAccessMode_Readonly);
    for (uint i = 0; i < pagecontent.Items.Count; i++) {
        var contentItem = pagecontent.Items[i];
        if (contentItem.GetCState().FillColor.CSHandle == cstate.FillColor.CSHandle) {
            return true;
        }
    }
    return false;
}

Unfortunately sometimes I get an Exception in the marked line. I think it has something to do with the flags of the cstate. I observed flags like 0x01000001, 0x01000003 and 0x01000007.

Does anybody know the meaning of these flags? I couldn't find anything in the wiki.

Thanks
MiBa
Sasha - PDF-XChange
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am

Re: IPXC_CState::Flags

Post by Sasha - PDF-XChange »

Hello MiBa,

You problem with the exception is because you use that property incorrectly.
The correct code is:

Code: Select all

PDFXEdit.IPXC_Color color = state.FillColor;
Because you were using

Code: Select all

var color = state.FillColor[PDFXEdit.ColorType.ColorType_CMYK];
The C# somehow reinterpreted this code into

Code: Select all

PDFXEdit.IColor color = state.FillColor[PDFXEdit.ColorType.ColorType_CMYK];
Thus you didn't know that you've made a mistake and the exceptions occurred.
So if you are using 'var' inside your code please double check whether the types and methods are used correctly so situations like these won't occur.

PS: I've updated the flags description here:
https://sdkhelp.pdf-xchange.com/vie ... tate_Flags

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ