Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error: ‘ePDFObjectArray’ was not declared in this scope when deploying Parsing Sample #288

Open
raphael10-collab opened this issue Oct 22, 2024 · 1 comment

Comments

@raphael10-collab
Copy link

Following the indications found here: https://github.com/galkahana/PDF-Writer?tab=readme-ov-file#using-pdfhummus-in-your-own-project, in the CMakeLists.txt of my project I've added this FetchContent_Declare :

FetchContent_Declare(
  PDFHummus
  URL https://github.com/galkahana/PDF-Writer/archive/refs/tags/v4.6.2.tar.gz
  URL_HASH SHA256=0a36815ccc9d207028567f90039785c824b211169ba5da68de84d0c15455ab62
  DOWNLOAD_EXTRACT_TIMESTAMP FALSE
  FIND_PACKAGE_ARGS
)
FetchContent_MakeAvailable(PDFHummus)

and I added in the target_link_libraries :

target_link_libraries (${PROJECT_NAME} PUBLIC

    PDFHummus::PDFWriter
)

Starting from this usage example : https://github.com/galkahana/PDFWriterSamples/blob/master/Parsing/Parsing.cpp
I added in the header file :

#include "PDFParser.h"
#include "InputFile.h"
#include "RefCountPtr.h"
#include "PDFDictionary.h"
#include "PDFArray.h"
#include "PDFObjectCast.h"
#include "PDFInteger.h"
#include "PDFReal.h"
#include "PDFName.h"
#include "PDFIndirectObjectReference.h"
#include "PDFStreamInput.h"
#include "IByteReader.h"
#include "EStatusCode.h"


using namespace PDFHummus;

And in the source file these functions (taken from the sample Parsing.cpp ) :

void showPDFinfo(PDFParser& parser)
{
    std::cout << "PDF Header level = " << parser.GetPDFLevel() << std::endl;
    std::cout << "Number of objects in PDF = " << parser.GetObjectsCount() << std::endl;
    std::cout << "Number of pages in PDF = " << parser.GetPagesCount() << std::endl;
}

void showContentStream(PDFStreamInput* inStream,IByteReaderWithPosition* inPDFStream,PDFParser& inParser)
{
    IByteReader* streamReader = inParser.CreateInputStreamReader(inStream);
    Byte buffer[1000];
    if(streamReader)
    {
        inPDFStream->SetPosition(inStream->GetStreamContentStart());
        while(streamReader->NotEnded())
        {
            LongBufferSizeType readAmount = streamReader->Read(buffer,1000);
            std::cout.write((const char*)buffer,readAmount);
        }
        std::cout << std::endl;
    }
    else
    {
        std::cout << "Unable to read content stream" << std::endl;
    }
    delete streamReader;
}


void showPageContent(PDFParser& parser, RefCountPtr<PDFObject> contents, InputFile& pdfFile)
{
    if(contents->GetType() == ePDFObjectArray)
    {
        PDFObjectCastPtr<PDFIndirectObjectReference> streamReferences;
        SingleValueContainerIterator<PDFObjectVector> itContents = ((PDFArray*)contents.GetPtr())->GetIterator();
        // array of streams
        while(itContents.MoveNext())
        {
            streamReferences = itContents.GetItem();
            PDFObjectCastPtr<PDFStreamInput> stream = parser.ParseNewObject(streamReferences->mObjectID);
            showContentStream(stream.GetPtr(),pdfFile.GetInputStream(),parser);
        }
    }
    else
    {
        // stream
        showContentStream((PDFStreamInput*)contents.GetPtr(),pdfFile.GetInputStream(),parser);
    }
}


void showXObjectsPerPageInfo(PDFParser& parser,PDFObjectCastPtr<PDFDictionary> xobjects)
{
    RefCountPtr<PDFName> key;
    PDFObjectCastPtr<PDFIndirectObjectReference> value;
        MapIterator<PDFNameToPDFObjectMap> it = xobjects->GetIterator();
        while(it.MoveNext())
        {
        key = it.GetKey();
        value = it.GetValue();
        std::cout << "XObject named " << key->GetValue().c_str() << " is object " << value->mObjectID << " of type ";
        PDFObjectCastPtr<PDFStreamInput> xobject(parser.ParseNewObject(value->mObjectID));
        PDFObjectCastPtr<PDFDictionary> xobjectDictionary(xobject->QueryStreamDictionary());
        PDFObjectCastPtr<PDFName> typeOfXObject = xobjectDictionary->QueryDirectObject("Subtype");
       std::cout << typeOfXObject->GetValue().c_str() << std::endl;
    }
}


void checkXObjectRef(PDFParser& parser,RefCountPtr<PDFDictionary> page) 
{
    PDFObjectCastPtr<PDFDictionary> resources(parser.QueryDictionaryObject(page.GetPtr(),"Resources"));
    if (!resources)
    {
        std::wcout << "No XObject in this page\n";
        return;
    }

    PDFObjectCastPtr<PDFDictionary> xobjects(parser.QueryDictionaryObject(resources.GetPtr(),"XObject"));
    if(!xobjects)
    {
        std:: wcout << "No XObject in this page\n";
        return;
    }
    std::cout << "Displaying XObjects information for this page:\n";
    showXObjectsPerPageInfo(parser,xobjects);
}


void showPagesInfo(PDFParser& parser, InputFile& pdfFile, EStatusCode status)
{
    for(unsigned long i=0; i < parser.GetPagesCount() && eSuccess == status; ++i)
    {
        std::cout << "Showing info for page " << i << std::endl;

        // Parse page object
        RefCountPtr<PDFDictionary> page(parser.ParsePage(i));

        // check XObject referenences
        checkXObjectRef(parser,page);

        // show page content
        RefCountPtr<PDFObject> contents(parser.QueryDictionaryObject(page.GetPtr(),"Contents"));
        if(!contents)
        {
            std::cout << "No contents for this page" << std::endl;
            continue;
        }

        // content may be array or single
        std::cout << "Showing content of page:\n";
        showPageContent(parser,contents,pdfFile);
        std::cout << "End page content\n";
    }
}

I'm getting this error:

error: ‘ePDFObjectArray’ was not declared in this scope
     if(contents->GetType() == ePDFObjectArray)

But I've already included all the header files.... what am I missing or doing wrong?

@galkahana
Copy link
Owner

can you share the actual files? perhaps the part declaring "using namespace PDFHummus;" is scoped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants