コード例 #1
0
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);
    }
}
コード例 #2
0
ObjectIDType DCTDecodeFilterTest::FindDCTDecodedImageObject(PDFParser* inParser)
{
    ObjectIDType imageObject = 0;
    
    do
    {
        // find image by looking for the first image in the first page
        
        RefCountPtr<PDFDictionary> firstPage = inParser->ParsePage(0);
        if(!firstPage)
            break;
        
        PDFObjectCastPtr<PDFDictionary> resourceDictionary(inParser->QueryDictionaryObject(firstPage.GetPtr(),"Resources"));
        
        if(!resourceDictionary)
            break;
        
        PDFObjectCastPtr<PDFDictionary> xobjectDictionary(inParser->QueryDictionaryObject(resourceDictionary.GetPtr(), "XObject"));
        
        if(!xobjectDictionary)
            break;
        
        MapIterator<PDFNameToPDFObjectMap> it = xobjectDictionary->GetIterator();

        while(it.MoveNext())
        {
            if(it.GetValue()->GetType() == PDFObject::ePDFObjectIndirectObjectReference)
            {
                PDFObjectCastPtr<PDFStreamInput> image(
                                                       inParser->ParseNewObject(((PDFIndirectObjectReference*)it.GetValue())->mObjectID));
                RefCountPtr<PDFDictionary> imageDictionary = image->QueryStreamDictionary();
                
                PDFObjectCastPtr<PDFName> objectType = imageDictionary->QueryDirectObject("Subtype");
                if(!objectType || objectType->GetValue() != "Image")
                    continue;
                
                RefCountPtr<PDFObject> filters = imageDictionary->QueryDirectObject("Filter");
                if(!filters)
                    break;
                
                if(filters->GetType() == PDFObject::ePDFObjectName &&
                   ((PDFName*)filters.GetPtr())->GetValue() == "DCTDecode")
                {
                    imageObject = ((PDFIndirectObjectReference*)it.GetValue())->mObjectID;
                    break;
                }
                
                PDFArray* filtersArray = (PDFArray*)filters.GetPtr();
                
                if(filtersArray->GetLength() == 1)
                {
                    PDFObjectCastPtr<PDFName> firstDecoder(filtersArray->QueryObject(0));
                    
                    if(firstDecoder->GetValue() == "DCTDecode")
                    {
                        imageObject = ((PDFIndirectObjectReference*)it.GetValue())->mObjectID;
                        break;
                    }
                }
            }
        }
        
    }
    while (false);
    
    return imageObject;
}