Exemplo n.º 1
0
def create_objs(context, tree):
    try: 
        app = build_pdf_objects.create_app_obj(tree)
        context.eval("app = " + str(app) + ";")
        context.eval("app.doc.syncAnnotScan = function () {}")
        context.eval("app.doc.getAnnots = function () { return app.doc.annots;}")
        context.eval("app.eval = function (string) { eval(string);}")
        context.eval("app.newDoc = function () { return '';}")
        context.eval("app.getString = function () { ret = \"\"; for(var prop in app){ ret += app[prop]; } return ret;}")
    except Exception as e:
        #print "App: " + e.message
        pass
    try:
        info = build_pdf_objects.create_info_obj(tree)  
        context.eval("this.info = " + str(info) + ";")
        for key in info:
            context.eval("this." + key + "= '" + re.escape(info[key]) + "';")
        context.eval("this.eval = eval")
        #print info
    except Exception as e:
        print "Info: " + e.message
        pass
    try:
        event = build_pdf_objects.create_event_obj(tree)
        context.eval("event = " + str(event) + ";")
        context.eval("event.target.info = this.info")
    except Exception as e:
        #print "Event: " + e.message
        pass
Exemplo n.º 2
0
def create_objs(context, tree):
    """

    Mimic native Adobe objects and add them to the context
    :param context: JavaScript context, like a namespace at runtime
    :param tree: XML tree of the pdf to reference objects
    :return:
    """
    try:
        app = build_pdf_objects.create_app_obj(tree)
        context.eval("app = " + str(app) + ";")
        context.eval("app.doc.syncAnnotScan = function () {}")
        context.eval(
            "app.doc.getAnnots = function () { return app.doc.annots;}")
        context.eval("app.eval = function (string) { eval(string);}")
        context.eval("app.newDoc = function () { return '';}")
        context.eval(
            "app.getString = function () { ret = \"\"; for(var prop in app){ ret += app[prop]; } return ret;}"
        )
    except Exception as e:
        # print "App: " + e.message
        pass
    try:
        info = build_pdf_objects.create_info_obj(tree)
        context.eval("this.info = " + str(info) + ";")
        for key in info:
            context.eval("this." + key + "= '" + re.escape(info[key]) + "';")
        context.eval("this.eval = eval")
        # print info
    except Exception as e:
        print "Info: " + e.message
        pass
    try:
        event = build_pdf_objects.create_event_obj(tree)
        context.eval("event = " + str(event) + ";")
        context.eval("event.target.info = this.info")
    except Exception as e:
        # print "Event: " + e.message
        pass
Exemplo n.º 3
0
def create_objs(context, tree):
    """

    Mimic native Adobe objects and add them to the context
    :param context: JavaScript context, like a namespace at runtime
    :param tree: XML tree of the pdf to reference objects
    :return:
    """
    try:
        app = build_pdf_objects.create_app_obj(tree)
        context.eval("app = " + str(app) + ";")
        context.eval("app.doc.syncAnnotScan = function () {}")
        context.eval("app.doc.getAnnots = function () { return app.doc.annots;}")
        context.eval("app.eval = function (string) { eval(string);}")
        context.eval("app.newDoc = function () { return '';}")
        context.eval("app.getString = function () { ret = \"\"; for(var prop in app){ ret += app[prop]; } return ret;}")
    except Exception as e:
        # print "App: " + e.message
        pass
    try:
        info = build_pdf_objects.create_info_obj(tree)
        context.eval("this.info = " + str(info) + ";")
        for key in info:
            context.eval("this." + key + "= '" + re.escape(info[key]) + "';")
        context.eval("this.eval = eval")
        # print info
    except Exception as e:
        print "Info: " + e.message
        pass
    try:
        event = build_pdf_objects.create_event_obj(tree)
        context.eval("event = " + str(event) + ";")
        context.eval("event.target.info = this.info")
    except Exception as e:
        # print "Event: " + e.message
        pass