Ejemplo n.º 1
0
METHOD_RETURN_TYPE DictionaryContextDriver::WriteRectangleValue(const ARGS_TYPE& args)
{
	CREATE_ISOLATE_CONTEXT;
	CREATE_ESCAPABLE_SCOPE;

    // can accept array or four numbers
    if( (args.Length() != 1 && args.Length() != 4) ||
       (args.Length() == 1 && !args[0]->IsArray()) ||
       (args.Length() == 4 && (!args[0]->IsNumber() || !args[1]->IsNumber() || !args[2]->IsNumber() || !args[3]->IsNumber())))
    {
		THROW_EXCEPTION("Wrong arguments, provide an array of 4 numbers, or 4 numbers");
        SET_FUNCTION_RETURN_VALUE(UNDEFINED);
        
    }
    
    DictionaryContextDriver* driver = ObjectWrap::Unwrap<DictionaryContextDriver>(args.This());
    
    if(!driver->DictionaryContextInstance)
    {
		THROW_EXCEPTION("dictinoarycontext object not initialized, create using objectscontext.startDictionary");
        SET_FUNCTION_RETURN_VALUE(UNDEFINED);
    }
    
    if(args.Length() == 1)
    {
        // array version. verify that there are 4 numbers
        if(args[0]->ToObject()->Get(NEW_STRING("length"))->ToObject()->Uint32Value() != 4)
        {
            THROW_EXCEPTION("Wrong arguments, provide an array of 4 numbers, or 4 numbers");
            SET_FUNCTION_RETURN_VALUE(UNDEFINED);
        }
        
        driver->DictionaryContextInstance->WriteRectangleValue(PDFRectangle(
                                                      args[0]->ToObject()->Get(0)->ToNumber()->Value(),
                                                      args[0]->ToObject()->Get(1)->ToNumber()->Value(),
                                                      args[0]->ToObject()->Get(2)->ToNumber()->Value(),
                                                      args[0]->ToObject()->Get(3)->ToNumber()->Value()));
        
    }
    else
    {
        // 4 numbers version
        driver->DictionaryContextInstance->WriteRectangleValue(PDFRectangle(
                                                                            args[0]->ToNumber()->Value(),
                                                                            args[1]->ToNumber()->Value(),
                                                                            args[2]->ToNumber()->Value(),
                                                                            args[3]->ToNumber()->Value()));
    }
    
    
    SET_FUNCTION_RETURN_VALUE(args.This());
}
METHOD_RETURN_TYPE DocumentCopyingContextDriver::GetCopiedObjectID(const ARGS_TYPE& args)
{
	CREATE_ISOLATE_CONTEXT;
	CREATE_ESCAPABLE_SCOPE;

    DocumentCopyingContextDriver* copyingContextDriver = ObjectWrap::Unwrap<DocumentCopyingContextDriver>(args.This());
    
    if(!copyingContextDriver->CopyingContext)
    {
		THROW_EXCEPTION("copying context object not initialized, create using pdfWriter.createPDFCopyingContext or PDFWriter.createPDFCopyingContextForModifiedFile");
        SET_FUNCTION_RETURN_VALUE(UNDEFINED);
    }
    
    if(args.Length() != 1 ||
       !args[0]->IsNumber())
    {
		THROW_EXCEPTION("Wrong arguments. provide 1 arugment, an object ID to check");
        SET_FUNCTION_RETURN_VALUE(UNDEFINED);
    }
        
    EStatusCodeAndObjectIDType result = copyingContextDriver->CopyingContext->GetCopiedObjectID(args[0]->ToNumber()->Uint32Value());
    if(result.first != eSuccess)
		THROW_EXCEPTION("Unable to find element");
    SET_FUNCTION_RETURN_VALUE(NEW_NUMBER(result.second));
    
}
Ejemplo n.º 3
0
METHOD_RETURN_TYPE CreateReader(const ARGS_TYPE& args)
{
    CREATE_ISOLATE_CONTEXT;
	CREATE_ESCAPABLE_SCOPE;
    Handle<Value> instance = PDFReaderDriver::GetNewInstance(args);
    
    PDFReaderDriver* driver = ObjectWrap::Unwrap<PDFReaderDriver>(instance->ToObject());
    
	if (args.Length() != 1 || (!args[0]->IsString() && !args[0]->IsObject()))
    {
		THROW_EXCEPTION("Wrong arguments, provide 1 string - path to file read, or a read stream object");
		SET_FUNCTION_RETURN_VALUE(UNDEFINED);
	}
        
    PDFHummus::EStatusCode status;
        
    if(args[0]->IsObject())
        status = driver->StartPDFParsing(args[0]->ToObject());
    else
        
        status = driver->StartPDFParsing(std::string(*String::Utf8Value(args[0]->ToString())));
    if(status != PDFHummus::eSuccess)
    {
		THROW_EXCEPTION("Unable to start parsing PDF file");
		SET_FUNCTION_RETURN_VALUE(UNDEFINED);
    }
    SET_FUNCTION_RETURN_VALUE(instance);
}
METHOD_RETURN_TYPE DocumentCopyingContextDriver::CopyDirectObjectWithDeepCopy(const ARGS_TYPE& args)
{
	CREATE_ISOLATE_CONTEXT;
	CREATE_ESCAPABLE_SCOPE;

    DocumentCopyingContextDriver* copyingContextDriver = ObjectWrap::Unwrap<DocumentCopyingContextDriver>(args.This());
    
    if(!copyingContextDriver->CopyingContext)
    {
		THROW_EXCEPTION("copying context object not initialized, create using pdfWriter.createPDFCopyingContext or PDFWriter.createPDFCopyingContextForModifiedFile");
        SET_FUNCTION_RETURN_VALUE(UNDEFINED);
    }
    
    if(args.Length() != 1) // need to sometimes check that this is a PDFObject
    {
		THROW_EXCEPTION("Wrong arguments. provide 1 arugment, which is PDFObject to copy");
        SET_FUNCTION_RETURN_VALUE(UNDEFINED);
    }
    
    EStatusCodeAndObjectIDTypeList result = copyingContextDriver->CopyingContext->CopyDirectObjectWithDeepCopy(ObjectWrap::Unwrap<PDFObjectDriver>(args[0]->ToObject())->GetObject());
    if(result.first != eSuccess)
		THROW_EXCEPTION("Unable to copy object, parhaps the object id is wrong");

    Local<Array> resultObjectIDs = NEW_ARRAY((unsigned int)result.second.size());
    unsigned int index = 0;
    
    ObjectIDTypeList::iterator it = result.second.begin();
    for(; it != result.second.end();++it)
        resultObjectIDs->Set(NEW_NUMBER(index++),NEW_NUMBER(*it));
    
    SET_FUNCTION_RETURN_VALUE(resultObjectIDs);
}
METHOD_RETURN_TYPE DocumentCopyingContextDriver::CopyDirectObjectAsIs(const ARGS_TYPE& args)
{
	CREATE_ISOLATE_CONTEXT;
	CREATE_ESCAPABLE_SCOPE;

    DocumentCopyingContextDriver* copyingContextDriver = ObjectWrap::Unwrap<DocumentCopyingContextDriver>(args.This());
    
    if(!copyingContextDriver->CopyingContext)
    {
		THROW_EXCEPTION("copying context object not initialized, create using pdfWriter.createPDFCopyingContext or PDFWriter.createPDFCopyingContextForModifiedFile");
        SET_FUNCTION_RETURN_VALUE(UNDEFINED);
    }
    
    if(args.Length() != 1) // need to sometimes check that this is a PDFObject
    {
		THROW_EXCEPTION("Wrong arguments. provide 1 arugment, which is PDFObject to copy");
        SET_FUNCTION_RETURN_VALUE(UNDEFINED);
    }
    
    EStatusCode status = copyingContextDriver->CopyingContext->CopyDirectObjectAsIs(ObjectWrap::Unwrap<PDFObjectDriver>(args[0]->ToObject())->GetObject());
    if(status != eSuccess)
		THROW_EXCEPTION("Unable to merge page index to form. parhaps the page index is wrong");
    SET_FUNCTION_RETURN_VALUE(UNDEFINED);
    
}
METHOD_RETURN_TYPE DocumentCopyingContextDriver::MergePDFPageToFormXObject(const ARGS_TYPE& args)
{
	CREATE_ISOLATE_CONTEXT;
	CREATE_ESCAPABLE_SCOPE;

    DocumentCopyingContextDriver* copyingContextDriver = ObjectWrap::Unwrap<DocumentCopyingContextDriver>(args.This());
    
    if(!copyingContextDriver->CopyingContext)
    {
		THROW_EXCEPTION("copying context object not initialized, create using pdfWriter.createPDFCopyingContext");
        SET_FUNCTION_RETURN_VALUE(UNDEFINED);
    }
    
    if(args.Length() != 2 ||
       !FormXObjectDriver::HasInstance(args[0]) ||
       !args[1]->IsNumber())
    {
		THROW_EXCEPTION("Wrong arguments. provide 2 arugments, where the first is a form, and the second is a page index to merge");
        SET_FUNCTION_RETURN_VALUE(UNDEFINED);
    }
    
    EStatusCode status = copyingContextDriver->CopyingContext->MergePDFPageToFormXObject(
                                                                                  ObjectWrap::Unwrap<FormXObjectDriver>(args[0]->ToObject())->FormXObject,
                                                                                  args[1]->ToNumber()->Uint32Value());
    
    if(status != eSuccess)
		THROW_EXCEPTION("Unable to merge page index to form. parhaps the page index is wrong");
    SET_FUNCTION_RETURN_VALUE(UNDEFINED);

}
METHOD_RETURN_TYPE DocumentCopyingContextDriver::AppendPDFPageFromPDF(const ARGS_TYPE& args)
{
	CREATE_ISOLATE_CONTEXT;
	CREATE_ESCAPABLE_SCOPE;

    DocumentCopyingContextDriver* copyingContextDriver = ObjectWrap::Unwrap<DocumentCopyingContextDriver>(args.This());
    
    if(!copyingContextDriver->CopyingContext)
    {
		THROW_EXCEPTION("copying context object not initialized, create using pdfWriter.createPDFCopyingContext");
        SET_FUNCTION_RETURN_VALUE(UNDEFINED);
    }
    
    if(args.Length() != 1 ||
       !args[0]->IsNumber())
    {
		THROW_EXCEPTION("Wrong arguments. provide a page index to append");
        SET_FUNCTION_RETURN_VALUE(UNDEFINED);
    }
    
    EStatusCodeAndObjectIDType result = copyingContextDriver->CopyingContext->AppendPDFPageFromPDF(args[0]->ToNumber()->Uint32Value());
    
    if(result.first != eSuccess)
    {
		THROW_EXCEPTION("Unable to append page. parhaps the page index is wrong");
        SET_FUNCTION_RETURN_VALUE(UNDEFINED);
    }
    
    Local<Number> idValue = NEW_NUMBER(result.second);
    SET_FUNCTION_RETURN_VALUE(idValue);
    
}
Ejemplo n.º 8
0
METHOD_RETURN_TYPE DictionaryContextDriver::WriteLiteralStringValue(const ARGS_TYPE& args)
{
	CREATE_ISOLATE_CONTEXT;
	CREATE_ESCAPABLE_SCOPE;

    if(!(args.Length() == 1) ||
       (!args[0]->IsString() && !args[0]->IsArray()))
    {
		THROW_EXCEPTION("wrong arguments, pass 1 argument that is a literal string (string) or an array");
		SET_FUNCTION_RETURN_VALUE(UNDEFINED);
        
    }

    DictionaryContextDriver* driver = ObjectWrap::Unwrap<DictionaryContextDriver>(args.This());
    
    if(!driver->DictionaryContextInstance)
    {
		THROW_EXCEPTION("dictinoarycontext object not initialized, create using objectscontext.startDictionary");
        SET_FUNCTION_RETURN_VALUE(UNDEFINED);
    }

	if(args[0]->IsArray())
	{
		std::string string;
		unsigned long arrayLength = (args[0]->ToObject()->Get(NEW_STRING("length")))->ToObject()->Uint32Value();
		for(unsigned long i=0;i<arrayLength;++i)
			string.push_back((unsigned char)args[0]->ToObject()->Get(i)->ToNumber()->Value());
		driver->DictionaryContextInstance->WriteLiteralStringValue(string);
	}
	else
    {
		driver->DictionaryContextInstance->WriteLiteralStringValue(*String::Utf8Value(args[0]->ToString()));
	}
    SET_FUNCTION_RETURN_VALUE(args.This());
}
Ejemplo n.º 9
0
METHOD_RETURN_TYPE DictionaryContextDriver::WriteNameValue(const ARGS_TYPE& args)
{
	CREATE_ISOLATE_CONTEXT;
	CREATE_ESCAPABLE_SCOPE;

    if(!(args.Length() == 1) ||
       !args[0]->IsString())
    {
		THROW_EXCEPTION("Wrong arguments, provide a string to write");
        SET_FUNCTION_RETURN_VALUE(UNDEFINED);
        
    }
    
    DictionaryContextDriver* driver = ObjectWrap::Unwrap<DictionaryContextDriver>(args.This());
    
    if(!driver->DictionaryContextInstance)
    {
		THROW_EXCEPTION("dictinoarycontext object not initialized, create using objectscontext.startDictionary");
        SET_FUNCTION_RETURN_VALUE(UNDEFINED);
    }
    
    driver->DictionaryContextInstance->WriteNameValue(*String::Utf8Value(args[0]->ToString()));
    
    SET_FUNCTION_RETURN_VALUE(args.This());
}
Ejemplo n.º 10
0
METHOD_RETURN_TYPE ByteReaderDriver::Read(const ARGS_TYPE& args)
{
	CREATE_ISOLATE_CONTEXT;
	CREATE_ESCAPABLE_SCOPE;

    // k. i'll just read the number of bytes and return an array of them
    if(args.Length() != 1 ||
       !args[0]->IsNumber())
    {
		THROW_EXCEPTION("Wrong arguments. pass the number of bytes to read");
        SET_FUNCTION_RETURN_VALUE(UNDEFINED);
    }
    
    ByteReaderDriver* element = ObjectWrap::Unwrap<ByteReaderDriver>(args.This());
    IOBasicTypes::LongBufferSizeType bufferSize = args[0]->ToNumber()->Uint32Value();
    Byte* buffer = new Byte[bufferSize];
    
    bufferSize = element->mInstance->Read(buffer,(int)bufferSize); // reading int cause that's the maximum that can read (use should read till notended anyways)

    Local<Array> outBuffer = NEW_ARRAY((int)bufferSize);
    
    for(LongBufferSizeType i=0;i<bufferSize;++i)
		outBuffer->Set(NEW_NUMBER(i), NEW_NUMBER(buffer[i]));
    
    delete[] buffer;
    
    SET_FUNCTION_RETURN_VALUE(outBuffer);
}
METHOD_RETURN_TYPE DocumentCopyingContextDriver::CopyNewObjectsForDirectObject(const ARGS_TYPE& args)
{
	CREATE_ISOLATE_CONTEXT;
	CREATE_ESCAPABLE_SCOPE;

    DocumentCopyingContextDriver* copyingContextDriver = ObjectWrap::Unwrap<DocumentCopyingContextDriver>(args.This());
    
    if(!copyingContextDriver->CopyingContext)
    {
		THROW_EXCEPTION("copying context object not initialized, create using pdfWriter.createPDFCopyingContext or PDFWriter.createPDFCopyingContextForModifiedFile");
        SET_FUNCTION_RETURN_VALUE(UNDEFINED);
    }
    
    if(args.Length() != 1 ||
       !args[0]->IsArray())
    {
		THROW_EXCEPTION("Wrong arguments. provide 1 arugment, which is an array of object IDs");
        SET_FUNCTION_RETURN_VALUE(UNDEFINED);
    }
    
    ObjectIDTypeList objectIDs;
    Handle<Object> objectIDsArray = args[0]->ToObject();

    unsigned int length = objectIDsArray->Get(v8::NEW_STRING("length"))->ToObject()->Uint32Value();
    
    for(unsigned int i=0;i <length;++i)
        objectIDs.push_back(objectIDsArray->Get(i)->ToNumber()->Uint32Value());
    
    EStatusCode status = copyingContextDriver->CopyingContext->CopyNewObjectsForDirectObject(objectIDs);
    if(status != eSuccess)
		THROW_EXCEPTION("Unable to copy elements");
    SET_FUNCTION_RETURN_VALUE(UNDEFINED);
    
}
Ejemplo n.º 12
0
METHOD_RETURN_TYPE InputFileDriver::OpenFile(const ARGS_TYPE& args)
{
    CREATE_ISOLATE_CONTEXT;
	CREATE_ESCAPABLE_SCOPE;
 
    if(args.Length() != 1 || !args[0]->IsString())
    {
		THROW_EXCEPTION("wrong arguments. please provide a string for the file path");
        SET_FUNCTION_RETURN_VALUE(UNDEFINED);
    }

    InputFileDriver* driver = ObjectWrap::Unwrap<InputFileDriver>(args.This());

    
    if(!driver)
    {
		THROW_EXCEPTION("no driver created...please create one through Hummus");
        SET_FUNCTION_RETURN_VALUE(UNDEFINED);
        
    }
    
    if(driver->OpenFile(*String::Utf8Value(args[0]->ToString())) != PDFHummus::eSuccess)
    {
		THROW_EXCEPTION("can't open file. make sure path exists");
        SET_FUNCTION_RETURN_VALUE(UNDEFINED);
    }
    
    SET_FUNCTION_RETURN_VALUE(UNDEFINED);
}
Ejemplo n.º 13
0
METHOD_RETURN_TYPE PDFDictionaryDriver::QueryObject(const ARGS_TYPE& args)
{
    CREATE_ISOLATE_CONTEXT;
	CREATE_ESCAPABLE_SCOPE;
    
    if(args.Length() != 1 || !args[0]->IsString())
    {
		THROW_EXCEPTION("wrong arguments, pass 1 argument which is a string key");
		SET_FUNCTION_RETURN_VALUE(UNDEFINED);
        
    }
    
    std::string key = *String::Utf8Value(args[0]->ToString());

    PDFDictionaryDriver* driver = ObjectWrap::Unwrap<PDFDictionaryDriver>(args.This());
    
    if(!driver->TheObject->Exists(key))
    {
		THROW_EXCEPTION("key not found");
		SET_FUNCTION_RETURN_VALUE(UNDEFINED);
    }
    
    RefCountPtr<PDFObject> anObject = driver->TheObject->QueryDirectObject(key);
    Handle<Value> result = PDFObjectDriver::CreateDriver(anObject.GetPtr());
    
    SET_FUNCTION_RETURN_VALUE(result);
}
METHOD_RETURN_TYPE ByteWriterWithPositionDriver::Write(const ARGS_TYPE& args)
{
	CREATE_ISOLATE_CONTEXT;
	CREATE_ESCAPABLE_SCOPE;

    // k. i'll just read the number of bytes and return an array of them
    if(args.Length() != 1 ||
       !args[0]->IsArray())
    {
		THROW_EXCEPTION("Wrong arguments. pass an array of bytes to write");
        SET_FUNCTION_RETURN_VALUE(UNDEFINED);
    }
    
    ByteWriterWithPositionDriver* element = ObjectWrap::Unwrap<ByteWriterWithPositionDriver>(args.This());
    int bufferSize = args[0]->ToObject()->Get(NEW_STRING("length"))->ToObject()->Uint32Value();
    Byte* buffer = new Byte[bufferSize];
    
    for(int i=0;i<bufferSize;++i)
        buffer[i] = args[0]->ToObject()->Get(i)->ToObject()->Uint32Value();
    
    bufferSize = (int)element->mInstance->Write(buffer,bufferSize);
    
    delete[] buffer;
    
    SET_FUNCTION_RETURN_VALUE(NEW_NUMBER(bufferSize));
}
Ejemplo n.º 15
0
METHOD_RETURN_TYPE InputFileDriver::OpenFile(const ARGS_TYPE& args)
{
    CREATE_ISOLATE_CONTEXT;
	CREATE_ESCAPABLE_SCOPE;
 
    if(args.Length() != 1 || !args[0]->IsString())
    {
		THROW_EXCEPTION("wrong arguments. please provide a string for the file path");
        SET_FUNCTION_RETURN_VALUE(UNDEFINED)
    }
Ejemplo n.º 16
0
METHOD_RETURN_TYPE InputFileDriver::New(const ARGS_TYPE& args)
{
    CREATE_ISOLATE_CONTEXT;
	CREATE_ESCAPABLE_SCOPE;
    
    InputFileDriver* inputFile = new InputFileDriver();
    
    if(args.Length() == 1 && args[0]->IsString())
        inputFile->OpenFile(*String::Utf8Value(args[0]->ToString()));
    
    inputFile->Wrap(args.This());
	SET_FUNCTION_RETURN_VALUE(args.This());
}
Ejemplo n.º 17
0
METHOD_RETURN_TYPE InputFileDriver::New(const ARGS_TYPE& args)
{
    CREATE_ISOLATE_CONTEXT;
	CREATE_ESCAPABLE_SCOPE;
    EXPOSE_EXTERNAL_ARGS(ConstructorsHolder, externalHolder)
    
    InputFileDriver* inputFile = new InputFileDriver();

    inputFile->holder = externalHolder;
    
    if(args.Length() == 1 && args[0]->IsString())
        inputFile->OpenFile(*UTF_8_VALUE(args[0]->TO_STRING()));
    
    inputFile->Wrap(args.This());
	SET_FUNCTION_RETURN_VALUE(args.This())
}
METHOD_RETURN_TYPE ByteReaderWithPositionDriver::SetPositionFromEnd(const ARGS_TYPE& args)
{
	CREATE_ISOLATE_CONTEXT;
	CREATE_ESCAPABLE_SCOPE;

    if(args.Length() != 1 ||
       !args[0]->IsNumber())
    {
		THROW_EXCEPTION("Wrong arguments. pass the position");
        SET_FUNCTION_RETURN_VALUE(UNDEFINED);
    }
    
    
    ByteReaderWithPositionDriver* element = ObjectWrap::Unwrap<ByteReaderWithPositionDriver>(args.This());
    element->mInstance->SetPositionFromEnd(args[0]->ToNumber()->Uint32Value());
    
    SET_FUNCTION_RETURN_VALUE(args.This());
}
Ejemplo n.º 19
0
METHOD_RETURN_TYPE ResourcesDictionaryDriver::AddProcsetResource(const ARGS_TYPE& args)
{
    CREATE_ISOLATE_CONTEXT;
    CREATE_ESCAPABLE_SCOPE;

    if(args.Length() != 1 || !args[0]->IsString())
    {
        THROW_EXCEPTION("wrong arguments, pass 1 argument which is the procset name");
        SET_FUNCTION_RETURN_VALUE(UNDEFINED);
    }

    ResourcesDictionaryDriver* resourcesDictionaryDriver = ObjectWrap::Unwrap<ResourcesDictionaryDriver>(args.This());

    resourcesDictionaryDriver->ResourcesDictionaryInstance->AddProcsetResource(*String::Utf8Value(args[0]->ToString()));

    SET_FUNCTION_RETURN_VALUE(UNDEFINED);

}
Ejemplo n.º 20
0
METHOD_RETURN_TYPE PDFDictionaryDriver::Exists(const ARGS_TYPE& args)
{
    CREATE_ISOLATE_CONTEXT;
	CREATE_ESCAPABLE_SCOPE;
    
    PDFDictionaryDriver* driver = ObjectWrap::Unwrap<PDFDictionaryDriver>(args.This());

    if(args.Length() != 1 || !args[0]->IsString())
    {
		THROW_EXCEPTION("wrong arguments, pass 1 argument which is a string key");
		SET_FUNCTION_RETURN_VALUE(UNDEFINED);
        
    }
    
    Handle<Boolean> result = NEW_BOOLEAN(driver->TheObject->Exists(*String::Utf8Value(args[0]->ToString())));
    
    SET_FUNCTION_RETURN_VALUE(result);
}
Ejemplo n.º 21
0
METHOD_RETURN_TYPE ResourcesDictionaryDriver::AddShadingMapping(const ARGS_TYPE& args)
{
    CREATE_ISOLATE_CONTEXT;
    CREATE_ESCAPABLE_SCOPE;

    if(args.Length() != 1 || !args[0]->IsNumber())
    {
        THROW_EXCEPTION("wrong arguments, pass 1 argument which is the shading object id");
        SET_FUNCTION_RETURN_VALUE(UNDEFINED);
    }

    ResourcesDictionaryDriver* resourcesDictionaryDriver = ObjectWrap::Unwrap<ResourcesDictionaryDriver>(args.This());

    Local<String> name = NEW_STRING(
                             resourcesDictionaryDriver->ResourcesDictionaryInstance->AddShadingMapping(
                                 (ObjectIDType)(args[0]->ToUint32()->Value())).c_str());

    SET_FUNCTION_RETURN_VALUE(name);
}
METHOD_RETURN_TYPE DocumentCopyingContextDriver::ReplaceSourceObjects(const ARGS_TYPE& args)
{
    // getting a dictionary mapping source to target object, translating to the C++ map...and on we go
	CREATE_ISOLATE_CONTEXT;
	CREATE_ESCAPABLE_SCOPE;

    DocumentCopyingContextDriver* copyingContextDriver = ObjectWrap::Unwrap<DocumentCopyingContextDriver>(args.This());
    
    if(!copyingContextDriver->CopyingContext)
    {
		THROW_EXCEPTION("copying context object not initialized, create using pdfWriter.createPDFCopyingContext or PDFWriter.createPDFCopyingContextForModifiedFile");
        SET_FUNCTION_RETURN_VALUE(UNDEFINED);
    }
    
    if(args.Length() != 0 ||
       !args[0]->IsObject())
    {
 		THROW_EXCEPTION("Wrong arguments. provide 1 arugment, which is an object mapping source object ids to map to target object IDs");
        SET_FUNCTION_RETURN_VALUE(UNDEFINED);
    }
    
    // create an object that will serve as the map
    ObjectIDTypeToObjectIDTypeMap resultMap;
    
    Handle<Object> anObject = args[0]->ToObject();
    
    Handle<Array> objectKeys = anObject->GetOwnPropertyNames();
    
    for(unsigned long i=0; i < objectKeys->Length(); ++i)
    {
        Handle<String> key  = objectKeys->Get(NEW_NUMBER(0))->ToString();
        Handle<Value> value = anObject->Get(key);
        
        resultMap.insert(ObjectIDTypeToObjectIDTypeMap::value_type(ObjectIDTypeObject(*String::Utf8Value(key)),value->ToNumber()->Uint32Value()));
        
    }
    
    copyingContextDriver->CopyingContext->ReplaceSourceObjects(resultMap);
    
    SET_FUNCTION_RETURN_VALUE(UNDEFINED);
}
Ejemplo n.º 23
0
METHOD_RETURN_TYPE GetTypeLabel(const ARGS_TYPE& args)
{
    CREATE_ISOLATE_CONTEXT;
	CREATE_ESCAPABLE_SCOPE;
	if (args.Length() != 1 || !args[0]->IsNumber())
    {
		THROW_EXCEPTION("Wrong arguments, provide a single enumerator value of a PDF Object type");
		SET_FUNCTION_RETURN_VALUE(UNDEFINED);
	}
    
    unsigned long value = args[0]->ToNumber()->Uint32Value();
    
    if(value > PDFObject::ePDFObjectSymbol)
    {
		THROW_EXCEPTION("Wrong arguments, provide a single enumerator value of a PDF Object type");
		SET_FUNCTION_RETURN_VALUE(UNDEFINED);
    }
    
    Handle<Value> result = NEW_STRING(PDFObject::scPDFObjectTypeLabel[(PDFObject::EPDFObjectType)value]);
    
    SET_FUNCTION_RETURN_VALUE(result);
}
Ejemplo n.º 24
0
METHOD_RETURN_TYPE PDFArrayDriver::QueryObject(const ARGS_TYPE& args)
{
    CREATE_ISOLATE_CONTEXT;
	CREATE_ESCAPABLE_SCOPE;
    
    if(args.Length() != 1 || !args[0]->IsNumber())
    {
		THROW_EXCEPTION("wrong arguments, pass 1 argument which is an index in the array");
		SET_FUNCTION_RETURN_VALUE(UNDEFINED);
        
    }
    
    PDFArrayDriver* arrayDriver = ObjectWrap::Unwrap<PDFArrayDriver>(args.This());
    if(args[0]->ToNumber()->Uint32Value() >= arrayDriver->TheObject->GetLength())
    {
		THROW_EXCEPTION("wrong arguments, pass 1 argument which is a valid index in the array");
		SET_FUNCTION_RETURN_VALUE(UNDEFINED);
    }
    
    RefCountPtr<PDFObject> anObject = arrayDriver->TheObject->QueryObject(args[0]->ToNumber()->Uint32Value());
    Handle<Value> result = PDFObjectDriver::CreateDriver(anObject.GetPtr());
    
    SET_FUNCTION_RETURN_VALUE(result);
}
METHOD_RETURN_TYPE DocumentCopyingContextDriver::CreateFormXObjectFromPDFPage(const ARGS_TYPE& args)
{
	CREATE_ISOLATE_CONTEXT;
	CREATE_ESCAPABLE_SCOPE;

    DocumentCopyingContextDriver* copyingContextDriver = ObjectWrap::Unwrap<DocumentCopyingContextDriver>(args.This());
    
    if(!copyingContextDriver->CopyingContext)
    {
		THROW_EXCEPTION("copying context object not initialized, create using pdfWriter.createPDFCopyingContext");
        SET_FUNCTION_RETURN_VALUE(UNDEFINED);
    }
    
    if(args.Length() < 2 ||
       args.Length() > 3 ||
       !args[0]->IsNumber() ||
       (!args[1]->IsNumber() && !args[1]->IsArray()) ||
       (args.Length() == 3 && !args[2]->IsArray()))
    {
		THROW_EXCEPTION("Wrong arguments. provide 2 or 3 arugments, where the first is a 0 based page index, and the second is a EPDFPageBox enumeration value or a 4 numbers array defining an box. a 3rd parameter may be provided to deisgnate the result form matrix");
        SET_FUNCTION_RETURN_VALUE(UNDEFINED);
    }
 
    double matrixBuffer[6];
    double* transformationMatrix = NULL;
    
    if(args.Length() == 3)
    {
        Handle<Object> matrixArray = args[2]->ToObject();
        if(matrixArray->Get(v8::NEW_STRING("length"))->ToObject()->Uint32Value() != 6)
        {
            THROW_EXCEPTION("matrix array should be 6 numbers long");
            SET_FUNCTION_RETURN_VALUE(UNDEFINED);
        }
        
        for(int i=0;i<6;++i)
            matrixBuffer[i] = matrixArray->Get(i)->ToNumber()->Value();
        transformationMatrix = matrixBuffer;
    }
    
    
    EStatusCodeAndObjectIDType result;
    
    if(args[0]->IsNumber())
    {
        result = copyingContextDriver->CopyingContext->CreateFormXObjectFromPDFPage(args[0]->ToNumber()->Uint32Value(),
                                                                       (EPDFPageBox)args[1]->ToNumber()->Uint32Value(),
                                                                                    transformationMatrix);
    }
    else
    {
        Handle<Object> boxArray = args[1]->ToObject();
        if(boxArray->Get(v8::NEW_STRING("length"))->ToObject()->Uint32Value() != 4)
        {
            THROW_EXCEPTION("box dimensions array should be 4 numbers long");
            SET_FUNCTION_RETURN_VALUE(UNDEFINED);
        }
        
        PDFRectangle box(boxArray->Get(0)->ToNumber()->Value(),
                         boxArray->Get(1)->ToNumber()->Value(),
                         boxArray->Get(2)->ToNumber()->Value(),
                         boxArray->Get(3)->ToNumber()->Value());
        
        result = copyingContextDriver->CopyingContext->CreateFormXObjectFromPDFPage(args[0]->ToNumber()->Uint32Value(),
                                                                                    box,
                                                                                    transformationMatrix);

    }
        
    
    if(result.first != eSuccess)
    {
		THROW_EXCEPTION("Unable to create form xobject from PDF page, parhaps the page index does not fit the total pages count");
        SET_FUNCTION_RETURN_VALUE(UNDEFINED);
    }
    
    Local<Number> idValue = NEW_NUMBER(result.second);
    
    SET_FUNCTION_RETURN_VALUE(idValue);
}
Ejemplo n.º 26
0
METHOD_RETURN_TYPE CreateWriter(const ARGS_TYPE& args)
{
    CREATE_ISOLATE_CONTEXT;
	CREATE_ESCAPABLE_SCOPE;
    Handle<Value> instance = PDFWriterDriver::GetNewInstance(args);
    
    PDFWriterDriver* driver = ObjectWrap::Unwrap<PDFWriterDriver>(instance->ToObject());

	if (args.Length() < 1 || args.Length() > 2) {
		THROW_EXCEPTION("Wrong number of arguments, Provide one argument stating the location of the output file, and an optional options object");
		SET_FUNCTION_RETURN_VALUE(UNDEFINED);
	}
    
	if (!args[0]->IsString() && !args[0]->IsObject()) {
		THROW_EXCEPTION("Wrong arguments, please provide a path to a file as the first argument or a stream object");
		SET_FUNCTION_RETURN_VALUE(UNDEFINED);
	}
    
    EPDFVersion pdfVersion = ePDFVersion13;
    bool compressStreams = true;
    LogConfiguration logConfig = LogConfiguration::DefaultLogConfiguration;
    
    if(args.Length() == 2 && args[1]->IsObject())
    {
        Handle<Object> anObject = args[1]->ToObject();
        if(anObject->Has(NEW_STRING("version")) && anObject->Get(NEW_STRING("version"))->IsNumber())
        {
            long pdfVersionValue = anObject->Get(NEW_STRING("version"))->ToNumber()->Int32Value();
            
            if(pdfVersionValue < ePDFVersion10 || ePDFVersionMax < pdfVersionValue)
            {
                THROW_EXCEPTION("Wrong argument for PDF version, please provide a valid PDF version");
                SET_FUNCTION_RETURN_VALUE(UNDEFINED);
            }
            pdfVersion = (EPDFVersion)pdfVersionValue;
        }
            
        if(anObject->Has(NEW_STRING("compress")) && anObject->Get(NEW_STRING("compress"))->IsBoolean())
            compressStreams = anObject->Get(NEW_STRING("compress"))->ToBoolean()->Value();

        if(anObject->Has(NEW_STRING("log")) && anObject->Get(NEW_STRING("log"))->IsString())
        {
            logConfig.ShouldLog = true;
            logConfig.LogFileLocation = *String::Utf8Value(anObject->Get(NEW_STRING("log"))->ToString());
        }

    }
    
    EStatusCode status;
    
    if(args[0]->IsObject())
    {
        status = driver->StartPDF(args[0]->ToObject(), pdfVersion,logConfig,PDFCreationSettings(compressStreams,true));
    }
    else
    {
        status = driver->StartPDF(std::string(*String::Utf8Value(args[0]->ToString())), pdfVersion,logConfig,PDFCreationSettings(compressStreams,true));
    }
    
    if(status != PDFHummus::eSuccess)
    {
		THROW_EXCEPTION("Unable to create PDF file, make sure that output file target is available");
		SET_FUNCTION_RETURN_VALUE(UNDEFINED);
    }
    SET_FUNCTION_RETURN_VALUE(instance);

}
Ejemplo n.º 27
0
METHOD_RETURN_TYPE CreateWriterToContinue(const ARGS_TYPE& args)
{
    CREATE_ISOLATE_CONTEXT;
	CREATE_ESCAPABLE_SCOPE;
    Handle<Value> instance = PDFWriterDriver::GetNewInstance(args);
    
    PDFWriterDriver* driver = ObjectWrap::Unwrap<PDFWriterDriver>(instance->ToObject());
    
	if ((args.Length() != 2  && args.Length() !=3)||
            (!args[0]->IsString() && !args[0]->IsObject()) ||
            !args[1]->IsString() ||
            ((args.Length() == 3) && !args[2]->IsObject())) {
		THROW_EXCEPTION("Wrong arguments, provide 2 strings - path to file to continue, and path to state file (provided to the previous shutdown call. You may also add an options object");
		SET_FUNCTION_RETURN_VALUE(UNDEFINED);
	}
    
    std::string alternativePath;
    Handle<Object> alternativeStream;
    LogConfiguration logConfig = LogConfiguration::DefaultLogConfiguration;
   
    if(args.Length() == 2 && args[1]->IsObject())
    {
        Handle<Object> anObject = args[1]->ToObject();
        
        if(anObject->Has(NEW_STRING("modifiedFilePath")) && anObject->Get(NEW_STRING("modifiedFilePath"))->IsString())
            alternativePath = *String::Utf8Value(anObject->Get(NEW_STRING("modifiedFilePath"))->ToString());

        if(anObject->Has(NEW_STRING("modifiedStream")) && anObject->Get(NEW_STRING("modifiedStream"))->IsObject())
            alternativeStream = anObject->Get(NEW_STRING("modifiedStream"))->ToObject();
        
        
        if(anObject->Has(NEW_STRING("log")))
        {
            Handle<Value> value = anObject->Get(NEW_STRING("log"));
            if(value->IsString())
            {
                logConfig.ShouldLog = true;
                logConfig.LogFileLocation = *String::Utf8Value(anObject->Get(NEW_STRING("log"))->ToString());
                logConfig.LogStream = NULL;
            }
            else if(value->IsObject())
            {
                logConfig.ShouldLog = true;
                logConfig.LogFileLocation = "";
                ObjectByteWriter proxy(value->ToObject());
                logConfig.LogStream = &proxy;
            }
        }
    }
    
    EStatusCode status;
    
    if(args[0]->IsObject())
    {
        status = driver->ContinuePDF(args[0]->ToObject(),
                                     *String::Utf8Value(args[1]->ToString()),
                                     alternativeStream,
                                     logConfig);
    }
    else
    {
        status = driver->ContinuePDF(*String::Utf8Value(args[0]->ToString()),
                                             *String::Utf8Value(args[1]->ToString()),
                                             alternativePath,
                                             logConfig);
    }
    
    if(status != PDFHummus::eSuccess)
    {
		THROW_EXCEPTION("Unable to continue PDF file, make sure that output file target is available and state file exists");
		SET_FUNCTION_RETURN_VALUE(UNDEFINED);
    }
    SET_FUNCTION_RETURN_VALUE(instance);
}
Ejemplo n.º 28
0
METHOD_RETURN_TYPE CreateWriterToModify(const ARGS_TYPE& args)
{
    CREATE_ISOLATE_CONTEXT;
	CREATE_ESCAPABLE_SCOPE;
    Handle<Value> instance = PDFWriterDriver::GetNewInstance(args);
    
    PDFWriterDriver* driver = ObjectWrap::Unwrap<PDFWriterDriver>(instance->ToObject());
    
    if(args.Length() < 1 ||
       (!args[0]->IsString() && !args[0]->IsObject()) ||
       (args[0]->IsString() && args.Length() > 2) ||
       (args[0]->IsObject() && (!args[1]->IsObject() || args.Length() > 3)))
    {
		THROW_EXCEPTION("Wrong arguments, please path a path to modified file, or a pair of stream - first for the source, and second for destination. in addition you can optionally add an options object");
		SET_FUNCTION_RETURN_VALUE(UNDEFINED);
	}
    
    
    EPDFVersion pdfVersion = ePDFVersion10;
    bool compressStreams = true;
    std::string alternativePath;
    Handle<Value> alternativeStream;
    LogConfiguration logConfig = LogConfiguration::DefaultLogConfiguration;
    
    int optionsObjectIndex = args[0]->IsString() ? 1:2;
    
    if(args.Length() == (optionsObjectIndex+1) && args[optionsObjectIndex]->IsObject())
    {
        Handle<Object> anObject = args[optionsObjectIndex]->ToObject();
        if(anObject->Has(NEW_STRING("version")) && anObject->Get(NEW_STRING("version"))->IsString())
        {
            long pdfVersionValue = anObject->Get(NEW_STRING("version"))->ToNumber()->Int32Value();
            
            if(pdfVersionValue < ePDFVersion10 || ePDFVersionMax < pdfVersionValue)
            {
                THROW_EXCEPTION("Wrong argument for PDF version, please provide a valid PDF version");
                SET_FUNCTION_RETURN_VALUE(UNDEFINED);
            }
            pdfVersion = (EPDFVersion)pdfVersionValue;
        }
        
        if(anObject->Has(NEW_STRING("compress")) && anObject->Get(NEW_STRING("compress"))->IsBoolean())
            compressStreams = anObject->Get(NEW_STRING("compress"))->ToBoolean()->Value();
        
        if(anObject->Has(NEW_STRING("modifiedFilePath")) && anObject->Get(NEW_STRING("modifiedFilePath"))->IsString())
            alternativePath = *String::Utf8Value(anObject->Get(NEW_STRING("modifiedFilePath"))->ToString());

        if(anObject->Has(NEW_STRING("log")) && anObject->Get(NEW_STRING("log"))->IsString())
        {
            logConfig.ShouldLog = true;
            logConfig.LogFileLocation = *String::Utf8Value(anObject->Get(NEW_STRING("log"))->ToString());
        }
    }
    
    EStatusCode status;
    
    if(args[0]->IsObject())
    {
        status = driver->ModifyPDF(args[0]->ToObject(),
                                   args[1]->ToObject(),
                                   pdfVersion,
                                   logConfig,
                                   PDFCreationSettings(compressStreams,true));
    }
    else
    {
        status = driver->ModifyPDF(*String::Utf8Value(args[0]->ToString()),
                               pdfVersion,alternativePath,logConfig,
                               PDFCreationSettings(compressStreams,true));
    }
    
    if(status != PDFHummus::eSuccess)
    {
		THROW_EXCEPTION("Unable to modify PDF file, make sure that output file target is available and that it is not protected");
		SET_FUNCTION_RETURN_VALUE(UNDEFINED);
    }
    SET_FUNCTION_RETURN_VALUE(instance);
}