Ejemplo n.º 1
0
def convert_pdf2swf(pdf_doc):

    if not isinstance(pdf_doc, basestring):
        try:
            pdf_doc = pdf_doc.read()
        except AttributeError:
            return None
    pdf_temp_file = tempfile.NamedTemporaryFile(delete=False)
    swf_temp_file = tempfile.NamedTemporaryFile(delete=False)

    pdf_temp_filename = pdf_temp_file.name
    swf_temp_filename = swf_temp_file.name

    pdf_temp_file.write(pdf_doc)
    pdf_temp_file.close()
    swf_temp_file.close()
    gfx.setparameter('poly2bitmap', '1')
    doc = gfx.open("pdf", pdf_temp_filename)
    swf = gfx.SWF()
    swf.setparameter('flashversion', '9')
    buf = StringIO.StringIO()
    for pagenr in range(1, doc.pages + 1):
        page = doc.getPage(pagenr)
        swf.startpage(page.width, page.height)
        page.render(swf)
        swf.endpage()
    swf.save(swf_temp_filename)

    os.unlink(pdf_temp_filename)

    return open(swf_temp_filename, 'r')
Ejemplo n.º 2
0
    def tryOcr(self, pdfFn):
        doc = gfx.open('pdf', pdfFn)
        gfx.setparameter('zoom', '160')
        method = gfx.OCR()

        txt = self.txtFromDoc(doc, method)
        return self.getDoiFromTxt(txt)
Ejemplo n.º 3
0
    def tryTxt(self, pdfFn):
        
        doc = gfx.open('pdf', pdfFn)
        method = gfx.PlainText()

        txt = self.txtFromDoc(doc, method)
        return self.getDoiFromTxt(txt)
Ejemplo n.º 4
0
def convert_pdf2swf(pdf_doc):

    if not isinstance(pdf_doc, basestring):
        try:
            pdf_doc = pdf_doc.read()
        except AttributeError:
            return None
    pdf_temp_file = tempfile.NamedTemporaryFile(delete=False)
    swf_temp_file = tempfile.NamedTemporaryFile(delete=False)

    pdf_temp_filename = pdf_temp_file.name
    swf_temp_filename = swf_temp_file.name

    pdf_temp_file.write(pdf_doc)
    pdf_temp_file.close()
    swf_temp_file.close()
    gfx.setparameter('poly2bitmap', '1')    
    doc = gfx.open("pdf", pdf_temp_filename)
    swf = gfx.SWF()
    swf.setparameter('flashversion', '9')
    buf = StringIO.StringIO()
    for pagenr in range(1,doc.pages+1):
        page = doc.getPage(pagenr)
        swf.startpage(page.width, page.height)
        page.render(swf)
        swf.endpage()
    swf.save(swf_temp_filename)

    os.unlink(pdf_temp_filename)

    return open(swf_temp_filename, 'r')
Ejemplo n.º 5
0
def convertImageToPDF(_fileName, _swfslides, isDocin):
    print "convecting files to pdf..."
    pdfCanvas = canvas.Canvas("%s.pdf" % _fileName, pagesize=portrait(A4))
    # pdfCanvas.drawString(150,700,"Welcome to flash slides downloader");
    # pdfCanvas.drawString(180,680,"contact: [email protected]");
    # pdfCanvas.showPage()
    numberOfSlides = 1
    for iswf in _swfslides:
        doc = gfx.open("swf", iswf)
        print iswf
        if doc:
            if isDocin == False:
                for pagenr in range(1, doc.pages + 1):
                    page1 = doc.getPage(pagenr)
                    print "Page", pagenr, "has dimensions", page1.width, "x", page1.height
                    pdfCanvas.setPageSize((page1.width * 2, page1.height * 2))
                    imageName = "image-%s-%s.png" % (numberOfSlides, pagenr)
                    imgRGBBuf = page1.asImage(page1.width * 2, page1.height * 2)
                    im = Image.fromstring(
                        "RGB", (page1.width * 2, page1.height * 2), imgRGBBuf
                    )  # convert to PIL Object
                    # img = gfx.ImageList()
                    # 				img.setparameter("antialise", "4") # turn on antialisin
                    # img.setparameter("zoom", "100")
                    # img.startpage(page1.width,page1.height)
                    # 				page1.render(img)
                    # 				img.endpage()
                    # pageNumOfThisSwf+=1"thumbnail%s.png" % pagenr
                    # img.save(imageName)
                    # pdfCanvas.drawImage(imageName,0,0,width= page1.width,height= page1.height,mask='auto')
                    pdfCanvas.drawImage(
                        ImageReader(im), 0, 0, width=page1.width * 2, height=page1.height * 2, mask="auto"
                    )
                    pdfCanvas.showPage()
                    # os.remove(imageName) # delete temp image
            else:
                # damn docins bad header.
                page1 = doc.getPage(1)
                print "Page %d" % numberOfSlides, "has dimensions", page1.width, "x", page1.height
                pdfCanvas.setPageSize((page1.width * 2, page1.height * 2))
                imageName = "image-%s-%s.png" % (numberOfSlides, 1)
                imgRGBBuf = page1.asImage(page1.width * 2, page1.height * 2)
                im = Image.fromstring("RGB", (page1.width * 2, page1.height * 2), imgRGBBuf)  # convert to PIL Object
                # img = gfx.ImageList()
                # img.setparameter("antialise", "4") # turn on antialisin
                # img.setparameter("zoom", "100")
                # img.startpage(page1.width,page1.height)
                # page1.render(img)
                # img.endpage()
                # pageNumOfThisSwf+=1"thumbnail%s.png" % pagenr
                # img.save(imageName)
                # pdfCanvas.drawImage(imageName,0,0,width= page1.width,height= page1.height,mask='auto')
                pdfCanvas.drawImage(ImageReader(im), 0, 0, width=page1.width * 2, height=page1.height * 2, mask="auto")
                pdfCanvas.showPage()
                # os.remove(imageName) # delete temp image
        numberOfSlides += 1
        os.remove(iswf)  # delete temp swf
    pdfCanvas.save()
Ejemplo n.º 6
0
class _SaveSWFThread:
    def __init__(self, pdffilename, filename, one_page_per_file, doc, pages,
                 options):
        #self.__doc = doc
        filename = filename.encode(sys.getfilesystemencoding())
        self.__filename = filename
        self.__pdffilename = pdffilename
        self.__pages = pages or range(1, doc.pages + 1)
        self.__options = options
        self.__one_page_per_file = one_page_per_file

    def Start(self):
        self.__keep_running = self.__running = True
        thread.start_new_thread(self.Run, ())
        #self.Run()

    def Stop(self):
        self.__keep_running = False

    def IsRunning(self):
        return self.__running

    def Run(self):
        swf = gfx.SWF()

        try:
            plugin = self.__options.viewers.init(swf, self.__filename)
        except Exception, e:
            wx.CallAfter(Publisher.sendMessage, "PLUGIN_ERROR")
            self.__running = False
            return

        if self.__one_page_per_file and not plugin.one_page_per_file:
            wx.CallAfter(Publisher.sendMessage,
                         "PLUGIN_ONE_PAGE_PER_FILE_NOT_SUPPORTED", {
                             'plugin': plugin,
                         })
            self.__running = False
            return

        pages = len(self.__pages)
        wx.CallAfter(Publisher.sendMessage, "SWF_BEGIN_SAVE", {
            'pages': pages,
        })

        self.setparameters(gfx)
        self.__doc = gfx.open("pdf", self.__pdffilename)

        self.setparameters(swf)

        try:
            plugin.before_render()
        except Exception, e:
            wx.CallAfter(Publisher.sendMessage, "PLUGIN_ERROR")
            self.__running = False
            return
Ejemplo n.º 7
0
    def createLoaderScript(self):
        print "Building the loader... (" + self.loaderscript + ")"

        filescript=open(self.installpath + "/script.loader","r")
        filebuffer=filescript.read()
        filescript.close()

        filebuffer+="\n"

        while True:

            (start,end,param,var)=self.get_param(filebuffer)
            if start==-1:
                break

            if param=="program":
                if var=="version":
                   filebuffer=filebuffer[:start]+"supershow-generator-"+iRS_settings.version+filebuffer[end+1:]
                   continue

            if param=="filename":
                if var=="loader":
                   filebuffer=filebuffer[:start]+self.loader+filebuffer[end+1:]
                   continue
                if var=="first":
                    filebuffer=filebuffer[:start]+self.coverslidefile+filebuffer[end+1:]
                    continue
                if var=="installpath":
                    filebuffer=filebuffer[:start]+self.installpath+filebuffer[end+1:]
                    continue
                if var=="output":
                    filebuffer=filebuffer[:start]+os.path.basename(self.presentation)+filebuffer[end+1:]
                    continue

            if param=="presentation":
                swf_first_slide = gfx.open("swf", self.presentation)
                measurement_page = swf_first_slide.getPage(1)

                if var=="width":
                   filebuffer=filebuffer[:start]+str(measurement_page.width)+filebuffer[end+1:]
                   continue
                if var=="height":
                    filebuffer=filebuffer[:start]+str(measurement_page.height)+filebuffer[end+1:]
                    continue
                if var=="installpath":
                    filebuffer=filebuffer[:start]+self.installpath+filebuffer[end+1:]
                    continue

           # if not recognized, remove it
            filebuffer=filebuffer[:start]+filebuffer[end+1:]

        print "Saving the loader at " + self.loaderscript
        loader_file = open(self.loaderscript,"w")
        loader_file.write(filebuffer)
        loader_file.close()
Ejemplo n.º 8
0
def pdf2bitmap():
	print("Converting into bitmap...")
	doc = gfx.open("pdf", sys.argv[1])
	img = gfx.ImageList()
	img.setparameter("antialise", "1")
	page1 = doc.getPage(1)
	img.startpage(page1.width,page1.height)
	page1.render(img)
	img.endpage()
	img.save("temporal.png")
	print("Done!")
Ejemplo n.º 9
0
def _pdfthumbnail(infile, outfile):
    try:
        import gfx
    except ImportError:
        return None
    doc = gfx.open("pdf", infile)
    img = gfx.ImageList()
    img.setparameter("antialise", "1")  # turn on antialising
    page1 = doc.getPage(1)
    img.startpage(page1.width, page1.height)
    page1.render(img)
    img.endpage()
    img.save(outfile)
Ejemplo n.º 10
0
def _pdfthumbnail(infile, outfile):
    try:
        import gfx
    except ImportError:
        return None
    doc = gfx.open("pdf", infile)
    img = gfx.ImageList()
    img.setparameter("antialise", "1") # turn on antialising
    page1 = doc.getPage(1)
    img.startpage(page1.width, page1.height)
    page1.render(img)
    img.endpage()
    img.save(outfile)
Ejemplo n.º 11
0
    def Load(self, filename):
        self.__lastsavefile = self.__SwapExtension(filename, "swf")
        filename = filename.encode(sys.getfilesystemencoding())
        self.__pdffilename = filename

        #print 'Load',self.__preview_parameters
        for parameter, value in self.__preview_parameters:
            gfx.setparameter(parameter, value)

        try:
            self.__pdf = gfx.open("pdf", filename)
        except:
            Publisher.sendMessage("FILE_NOT_LOADED", {'filename': filename})
        else:
            Publisher.sendMessage("FILE_LOADED", {'pages': self.__pdf.pages})
Ejemplo n.º 12
0
    def Load(self, filename):
        self.__lastsavefile = self.__SwapExtension(filename, "swf")
        filename = filename.encode(sys.getfilesystemencoding())
        self.__pdffilename = filename

        #print 'Load',self.__preview_parameters
        for parameter, value in self.__preview_parameters:
            gfx.setparameter(parameter, value)

        try:
            self.__pdf = gfx.open("pdf", filename)
        except:
            Publisher.sendMessage("FILE_NOT_LOADED", {'filename': filename})
        else:
            Publisher.sendMessage("FILE_LOADED", {'pages': self.__pdf.pages})
Ejemplo n.º 13
0
def _pdfthumbnail(infile, outfile):
    print "Creating PDF thumbnail: '%s' '%s'" % (infile, outfile)
    print "sys.path=%s" % repr(sys.path)
    try:
        import gfx
    except ImportError:
        print >> sys.stderr, "Cannot import gfx"
        sys.exit(5)
    print "Starting"
    doc = gfx.open("pdf", infile)
    img = gfx.ImageList()
    img.setparameter("antialise", "1") # turn on antialising
    page1 = doc.getPage(1)
    img.startpage(page1.width, page1.height)
    page1.render(img)
    img.endpage()
    img.save(outfile)
Ejemplo n.º 14
0
def _pdfthumbnail(infile, outfile):
    print "Creating PDF thumbnail: '%s' '%s'" % (infile, outfile)
    print "sys.path=%s" % repr(sys.path)
    try:
        import gfx
    except ImportError:
        print >> sys.stderr, "Cannot import gfx"
        sys.exit(5)
    print "Starting"
    doc = gfx.open("pdf", infile)
    img = gfx.ImageList()
    img.setparameter("antialise", "1")  # turn on antialising
    page1 = doc.getPage(1)
    img.startpage(page1.width, page1.height)
    page1.render(img)
    img.endpage()
    img.save(outfile)
Ejemplo n.º 15
0
    def loadPDF(self,filename):
        self.filename = filename
        self.lastsavefile = swapextension(filename,"swf")
        self.lasthtmlfile = swapextension(filename,"html")

        self.pdf = gfx.open("pdf",filename)
        if(has_different_size_pages(self.pdf)):
            # just let the user know- for now, we can't handle this properly
            dlg = wx.MessageDialog(app.frame, """In this PDF, width or height are not the same for each page. This might cause problems if you export pages of different dimensions into the same SWF file.""", "Notice", style=wx.OK, pos=wx.DefaultPosition)
            dlg.ShowModal()
            dlg.Destroy()

        self.changePage(1)

        for type,f in self.listeners:
            if type&EVENT_PAGE_CHANGE or type&EVENT_FILE_CHANGE:
                f()
        self.setStatus("File loaded successfully.")
Ejemplo n.º 16
0
def convert(file_path, presentation_id, dir):
    print "-- helpers -- convert() -- wywolanie metody"
    doc = gfx.open("pdf", file_path)

    slide_list = list()

    for i in range(doc.pages):
        img = gfx.ImageList()
        page = doc.getPage(i + 1)
        img.startpage(page.width, page.height)
        page.render(img)
        img.endpage()
        name = str(presentation_id) + "_" + str(i) + ".png"
        path = dir + str(presentation_id) + "_" + str(i) + ".png"
        img.save(path)
        slide_list.append(name)
        print "-- helpers -- convert -- zapis pliku: " + path

    return slide_list
Ejemplo n.º 17
0
    def convert2Image(self,pdfFilePath,destinationPath):
        self.result = False;
        try:
            doc = gfx.open("pdf", pdfFilePath)
            img = gfx.ImageList()
            img.setparameter("antialise", "1") # turn on antialising
            page1 = doc.getPage(1)
            img.startpage(page1.width,page1.height)
            page1.render(img)
            img.endpage()
            img.save(destinationPath)
            self.result = True;
        
        except:
            pass;
        
        return self.result;
            
#pdf = WinPDF2Image();
#pdfFilePath = "d:\Tong\Code/code_python/file_python/test.pdf";
#destinationPath = "d:/Tong/Code/code_python/file_python/test12334";
#pdf.convert2Image(pdfFilePath, destinationPath);
 
        
swf = SWF(file)
# print SWF(file)
# create the SVG exporter
svg_exporter = SVGExporter()

# export!
svg = swf.export(svg_exporter)

# save the SVG
open('C:/Users/Hamed/IGC/Desktop/trash/1.svg', 'wb').write(svg.read())



import gfx

doc = gfx.open("swf", "C:/Users/Hamed/IGC/Desktop/trash/1.swf")
for pagenr in range(1,doc.pages+1):
    page = doc.getPage(pagenr)
    print "Page", pagenr, "has dimensions", page.width, "x", page.height

from PIL import Image
i = Image.open(image_address)

pixels2 = i.load() # this is not a list, nor is it list()'able
width, height = i.size

all_pixels = []
for x in range(width):
    for y in range(height):
        cpixel = pixels2[x, y]
        all_pixels.append(cpixel)
Ejemplo n.º 19
0
	
#!/usr/bin/python
import gfx

doc = gfx.open("pdf", "/home/hardik/Desktop/sample.pdf")

print "Author:", doc.getInfo("author")
print "Subject:", doc.getInfo("subject")
print "PDF Version:", doc.getInfo("version")
Ejemplo n.º 20
0
 def load_file(self,filename,page=None,do_clear=True,allowEncrypted=True):
     "Load a given file into memory (only the asked page if given, all the pages otherwise)"
     if allowEncrypted:
         sss = algorithms.stringFunctions.load_encrypted_data(filename)
         if sss is not None:
             if sss=='' : return False
             (__,ext) = os.path.splitext(filename)
             fle = tempfile.mkstemp(ext)
             with open(fle[1], "wb") as ff: ff.write(sss)
             os.close(fle[0])
             self.load_file(fle[1], page, do_clear,False)
             os.remove(fle[1])
             self.current_file=filename
             return True
             
     if do_clear : self.clear_all()
     self.is_modified=False
     self.current_file=filename
     
     try_pdf = filename.lower().endswith('.pdf')
     old_log_level = wx.Log.GetLogLevel()
     wx.Log.SetLogLevel(0)
     if wx.Image.CanRead(filename):
         nmax = wx.Image.GetImageCount(filename)
         if page:
             if page>=nmax:return
             R = [page]
         else :
             R = range(nmax)
         progressor = gui.utilities.ProgressDialog('MALODOS',_('Reading image data, please wait...'))
         for idx in R:
             try:
                 progressor.add_to_current_step(1.0/nmax)
                 wxi = wx.Image(filename,index=idx)
                 img = Image.new('RGB', (wxi.GetWidth(), wxi.GetHeight()))
                 img.fromstring(wxi.GetData())
                 self.nb_pages = nmax
                 self.add_image(img)
                 try_pdf=False
             except:
                 pass
         progressor.destroy()
     
     wx.Log.SetLogLevel(old_log_level)
     
     if not try_pdf:
         self.current_image=0
         return
     # This is executed only is try_pdf is TRUE --> loading file was not possible via wx
     progressor = gui.utilities.ProgressDialog('MALODOS',_('Reading image data, please wait...'))
     try:
         import locale
         l = locale.getdefaultlocale()
         doc = gfx.open("pdf", filename.encode(l[1]))
         #doc = gfx.open("pdf", filename)
         self.title=doc.getInfo("title")
         self.subject=doc.getInfo("subject")
         self.keywords=doc.getInfo("keywords")
         nmax = doc.pages
         if page:
             if page>=nmax:
                 progressor.destroy()
                 return
             R = [page]
         else :
             R = range(nmax)
         for pagenr in range(nmax):
             progressor.add_to_current_step(1.0/nmax)
             page = doc.getPage(pagenr+1)
             bm = page.asImage(page.width,page.height)
             I = Image.fromstring("RGB",(page.width,page.height),bm)
             self.nb_pages = nmax
             self.add_image(I)
         self.current_image=0
     except Exception,E:
         logging.exception("Unable to open the file " + str(filename) + " because " + str(E))
Ejemplo n.º 21
0
def convertImageToPDF(_fileName, _swfslides, isDocin):
    print "convecting files to pdf..."
    pdfCanvas = canvas.Canvas('%s.pdf' % _fileName, pagesize=portrait(A4))
    pdfCanvas.drawString(150, 700, "Welcome to flash slides downloader")
    pdfCanvas.drawString(180, 680, "contact: [email protected]")
    pdfCanvas.showPage()
    numberOfSlides = 1
    for iswf in _swfslides:
        doc = gfx.open("swf", iswf)
        print iswf
        if doc:
            if isDocin == False:
                for pagenr in range(1, doc.pages + 1):
                    page1 = doc.getPage(pagenr)
                    print "Page", pagenr, "has dimensions", page1.width, "x", page1.height
                    pdfCanvas.setPageSize((page1.width * 2, page1.height * 2))
                    imageName = 'image-%s-%s.png' % (numberOfSlides, pagenr)
                    imgRGBBuf = page1.asImage(page1.width * 2,
                                              page1.height * 2)
                    im = Image.fromstring("RGB",
                                          (page1.width * 2, page1.height * 2),
                                          imgRGBBuf)  # convert to PIL Object
                    # img = gfx.ImageList()
                    # 				img.setparameter("antialise", "4") # turn on antialisin
                    # img.setparameter("zoom", "100")
                    # img.startpage(page1.width,page1.height)
                    # 				page1.render(img)
                    # 				img.endpage()
                    # pageNumOfThisSwf+=1"thumbnail%s.png" % pagenr
                    # img.save(imageName)
                    # pdfCanvas.drawImage(imageName,0,0,width= page1.width,height= page1.height,mask='auto')
                    pdfCanvas.drawImage(ImageReader(im),
                                        0,
                                        0,
                                        width=page1.width * 2,
                                        height=page1.height * 2,
                                        mask='auto')
                    pdfCanvas.showPage()
                    # os.remove(imageName) # delete temp image
            else:
                # damn docins bad header.
                page1 = doc.getPage(1)
                print "Page %d" % numberOfSlides, "has dimensions", page1.width, "x", page1.height
                pdfCanvas.setPageSize((page1.width * 2, page1.height * 2))
                imageName = 'image-%s-%s.png' % (numberOfSlides, 1)
                imgRGBBuf = page1.asImage(page1.width * 2, page1.height * 2)
                im = Image.fromstring("RGB",
                                      (page1.width * 2, page1.height * 2),
                                      imgRGBBuf)  # convert to PIL Object
                # img = gfx.ImageList()
                # img.setparameter("antialise", "4") # turn on antialisin
                # img.setparameter("zoom", "100")
                # img.startpage(page1.width,page1.height)
                # page1.render(img)
                # img.endpage()
                # pageNumOfThisSwf+=1"thumbnail%s.png" % pagenr
                # img.save(imageName)
                # pdfCanvas.drawImage(imageName,0,0,width= page1.width,height= page1.height,mask='auto')
                pdfCanvas.drawImage(ImageReader(im),
                                    0,
                                    0,
                                    width=page1.width * 2,
                                    height=page1.height * 2,
                                    mask='auto')
                pdfCanvas.showPage()
                # os.remove(imageName) # delete temp image
        numberOfSlides += 1
        os.remove(iswf)  # delete temp swf
    pdfCanvas.save()
Ejemplo n.º 22
0
# load and parse the SWF
swf = SWF(file)
# print SWF(file)
# create the SVG exporter
svg_exporter = SVGExporter()

# export!
svg = swf.export(svg_exporter)

# save the SVG
open('C:/Users/Hamed/IGC/Desktop/trash/1.svg', 'wb').write(svg.read())

import gfx

doc = gfx.open("swf", "C:/Users/Hamed/IGC/Desktop/trash/1.swf")
for pagenr in range(1, doc.pages + 1):
    page = doc.getPage(pagenr)
    print "Page", pagenr, "has dimensions", page.width, "x", page.height

from PIL import Image
i = Image.open(image_address)

pixels2 = i.load()  # this is not a list, nor is it list()'able
width, height = i.size

all_pixels = []
for x in range(width):
    for y in range(height):
        cpixel = pixels2[x, y]
        all_pixels.append(cpixel)
Ejemplo n.º 23
0
import sys
import gfx
import subprocess

if len(sys.argv) != 3:
	print "Usage:  "+sys.argv[0]+" input.swf output.mp4"
	exit()
	
inp = os.path.abspath(sys.argv[1])

audio_file = os.path.join(os.path.dirname(inp), os.path.basename(inp) + ".TMP.wav")
frame_dir = os.path.join(os.path.dirname(inp), "output-{0}/".format(os.path.basename(inp)))
frame_format = frame_dir + "gnash-%d.png"

out = sys.argv[2]
swf = gfx.open("swf", inp)

print "Processing {0}".format(inp)

length = int(raw_input("Enter video length (seconds): "))
frames = swf.pages # the number of frames

print "FPS: {0}".format(frames/length)
print "Frames to write: "+str(frames)

print "Extracting audio..."
audio_result = subprocess.Popen(['gnash', '--once', '-A', audio_file, '-r', '2', inp], shell=True)
audio_result.wait()
if audio_result.returncode != 0:
	print "Something went wrong! "+str(ret)
	exit()
Ejemplo n.º 24
0
    def saveSWF(self, filename, progress, pages=None, html=0):
        if html:
            basename,ext = os.path.splitext(filename)
            if not ext:
                html = basename + ".html"
                filename = basename + ".swf"
            elif ext.lower() != ".swf":
                html = filename
                filename = basename + ".swf"
            else:
                html = basename + ".html"
                filename = filename

        steps = 100.0 / (self.pdf.pages*2 + 3)
        pos = [0]
        
        self.lastsavefile = filename
        if html:
            self.lasthtmlfile = html

        swf = gfx.SWF()
        for k,v in gfx_options.items():
            swf.setparameter(k,v)
        if pages is None:
            pages = range(1,self.pdf.pages+1)
        pdfwidth,pdfheight=0,0
        for pagenr in pages:
            page = self.pdf.getPage(pagenr)
            pdfwidth = page.width
            pdfheight = page.height
            swf.startpage(page.width, page.height)
            page.render(swf)
            swf.endpage()
        swf.save(filename)
        if not os.path.isfile(filename):
            error("Couldn't create file "+filename)

        if gfx_options.get("rfxview",None):
            rfxview = os.path.join(basedir, "rfxview.swf")
            if not os.path.isfile(rfxview):
                error("File rfxview.swf not found in working directory")
            else:
                size1 = os.stat(filename)[stat.ST_SIZE]
                swfcombine([rfxview,"viewport="+filename,"-o",filename])
                size2 = os.stat(filename)[stat.ST_SIZE]
                if size1 == size2:
                    error("Couldn't add viewer to file "+filename)
        
        if html:
            version = int(gfx_options.get("flashversion", "8"))
            swf = gfx.open("swf", filename)
            page1 = swf.getPage(1)

            width,height = str(page1.width),str(page1.height)


            w = gfx_options.get("rfxwidth","")
            if w == "fullscreen":    width = "100%"
            elif w == "same as PDF": width = pdfwidth+40
            elif w.isdigit():        width = w
            else:                    width = pdfwidth
            
            h = gfx_options.get("rfxheight","")
            if h == "fullscreen":    height = "100%"
            elif h == "same as PDF": height = pdfheight+70
            elif h.isdigit():        height = h
            else:                    height = pdfwidth

            flashvars = ""
            zoomtype = gfx_options.get("rfxzoomtype","")
            if zoomtype=="Original resolution":
                flashvars = "zoomtype=1"
            elif zoomtype=="Show all":
                flashvars = "zoomtype=2"
            elif zoomtype=="Maximum width/height":
                flashvars = "zoomtype=3"

            swffilename = os.path.basename(filename)
            fi = open(html, "wb")
            fi.write(HTMLTEMPLATE % locals())
            fi.close()
Ejemplo n.º 25
0
import sys
sys.path.append('C:\Program Files (x86)\SWFTools\python26')

import gfx

doc = gfx.open('pdf', '../test_prl.pdf')

a = 'title', 'subject', 'keywords', 'author', 'creator', 'producer', 'creationdate', 'moddate', 'linearized', 'tagged', 'encrypted', 'oktoprint', 'oktocopy', 'oktochange', 'oktoaddnotes', 'version'

for key in a:
    print doc.getInfo(key)

text = gfx.PlainText()
page = doc.getPage(1)
text.startpage(page.width, page.height)
page.render(text)
text.endpage()
#text.save("test.txt")