Using libopc to read xps file, read content, extract/handle pieces

Oct 10, 2014 at 7:23 PM
Edited Oct 10, 2014 at 7:23 PM
Hi,
I was looking at the example given for this discussion, which is very similar to the sample given in documentation. How can I tell if I'm handling the pieces and how would I test this? See my code ex. below, which uses a simple square xps document.

I'm not sure what the line in the discussion example is doing with 1.fpage. Is it something I can look at, and where is it?
 opcXmlReaderOpen(c, &reader, _X("/Documents/1/Pages/1.fpage
#include <opc/opc.h>

static void dumpText(mceTextReader_t *reader) {
    mce_skip_attributes(reader);
    mce_start_children(reader) {
        mce_start_element(reader, _X("http://schemas.microsoft.com/xps/2005/06"), _X("Glyphs")) {
            mce_start_attributes(reader) {
                mce_start_attribute(reader, NULL, _X("UnicodeString")) {
                    for (const xmlChar *txt = xmlTextReaderConstValue(reader->reader); 0 != *txt; txt++) {
                        switch (*txt) {
                        case '<':
                            printf("&lt;");
                            break;
                        case '>':
                            printf("&gt;");
                            break;
                        case '&':
                            printf("&amp;");
                            break;
                        default:
                            putc(*txt, stdout);
                            break;
                        }
                    }
                }
            } mce_end_attributes(reader);
            mce_skip_children(reader);
        } mce_end_element(reader);
        mce_start_element(reader, NULL, NULL) {
            dumpText(reader);
        } mce_end_element(reader);
    } mce_end_children(reader);
}


int main(int argc, const char* argv[])
{
    //cout << "here" << endl;
    opcInitLibrary();
    //open container for reading
    opcContainer *c = opcContainerOpen(_X("E:\\Op\\op\\TestFiles\\SimpleSquare.xps"), OPC_OPEN_READ_ONLY, NULL, NULL);
    if (NULL != c) {
        mceTextReader_t reader;
        //open word/document.xml stream found in docx files
        if (OPC_ERROR_NONE == opcXmlReaderOpen(c, &reader, _X("/Documents/1/Pages/1.fpage"), NULL, 0, 0)) {
            mce_start_document(&reader) {
                mce_start_element(&reader, NULL, NULL) {
                    printf("<html>\n");
                    printf("<head>\n");
                    printf("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n");
                    printf("</head>\n");
                    printf("<body>\n");
                    dumpText(&reader);
                    printf("<body>\n");
                    printf("</html>\n");
                } mce_end_element(&reader);
            } mce_end_document(&reader);
            mceTextReaderCleanup(&reader);
        }
        opcContainerClose(c, OPC_CLOSE_NOW);
    }
    opcFreeLibrary();
    return 0;
}
Oct 13, 2014 at 2:31 PM
Well, it looks like I got it working. I discovered that I can use winzip to unzip/open an xps file to see the contents (try to open xps file, select other format, select winzip), including 1.fpage. Plus, I found out all xps files don't have that info in them. I'm stepping through in visual studio to see the contents in the dump method of *.txt/default and comparing to the original document 1.fpage.
Marked as answer by michCl on 10/13/2014 at 7:05 AM