예제 #1
0
def genSlideImages(instance):
    #print 'trying', settings.SITE_BASE_DIR + '/scripts/pdf2pngs',
    basepath = instance.getImageBasePath()
    #print 'trying', settings.SITE_BASE_DIR + '/scripts/pdf2pngs',
    print '-' * 40, 'genSlideImages: start'
    runCmd((settings.SITE_BASE_DIR + '/scripts/pdf2pngs', instance.pdf.path,
            basepath, str(settings.slideImgResolution),
            str(settings.slideImgOrigSize), str(
                settings.slideImgThumbSize), settings.slideImgThumbString),
           verbose=True)
    print '-' * 40, 'genSlideImages: done'
예제 #2
0
def genSlideImages(instance):
    #print 'trying', settings.SITE_BASE_DIR + '/scripts/pdf2pngs',
    basepath = instance.getImageBasePath()
    #print 'trying', settings.SITE_BASE_DIR + '/scripts/pdf2pngs',
    print '-'*40, 'genSlideImages: start'
    runCmd((settings.SITE_BASE_DIR + '/scripts/pdf2pngs',
            instance.pdf.path,
            basepath,
            str(settings.slideImgResolution),
            str(settings.slideImgOrigSize),
            str(settings.slideImgThumbSize),
            settings.slideImgThumbString),
           verbose = True)
    print '-'*40, 'genSlideImages: done'
예제 #3
0
def slidedeckPostSave(sender, instance, **kwargs):
    print 'slidedeckPostSave:', instance.pdf, instance.pdf.path
    print 'slidedeckPostSave:', sender
    print 'slidedeckPostSave:', instance
    print 'slidedeckPostSave:', kwargs

    if instance.pdf:
        # still need to process

        modified = False

        if instance.pages == -1:
            out, err = runCmd(
                ('gs', '-q', '-dNODISPLAY', '-c',
                 '(%s) (r) file runpdfbegin pdfpagecount = quit' %
                 instance.pdf.path))
            print 'Pages:', out
            try:
                instance.pages = int(out)
            except:
                raise Exception('expected int but got %s' % repr(out))

            print 'Skipping images!'
            #genSlideImages(instance)
            modified = True

        if instance.text == '':
            # extract text
            randFile = '/tmp/%s.tmp' % randomString(6)
            runCmd(('pdftotext', '-enc', 'UTF-8', instance.pdf.path, randFile))
            with open(randFile, 'r') as ff:
                uu = UnicodeDammit(ff.read())
            textUnicode = uu.unicode_markup
            instance.text = textUnicode.encode('ascii', 'ignore')
            modified = True
            print 'got text: %s...' % instance.text[:100]

        if instance.slug == '':
            instance.slug = os.path.split(instance.getImageBasePath())[-1]
            modified = True
            print 'set slug to:', instance.slug

        if modified:
            print 'saving'
            instance.save()
예제 #4
0
def slidedeckPostSave(sender, instance, **kwargs):
    print 'slidedeckPostSave:', instance.pdf, instance.pdf.path
    print 'slidedeckPostSave:', sender
    print 'slidedeckPostSave:', instance
    print 'slidedeckPostSave:', kwargs

    if instance.pdf:
        # still need to process

        modified = False
        
        if instance.pages == -1:
            out,err = runCmd(('gs', '-q', '-dNODISPLAY', '-c',
                              '(%s) (r) file runpdfbegin pdfpagecount = quit' % instance.pdf.path))
            print 'Pages:', out
            try:
                instance.pages = int(out)
            except:
                raise Exception('expected int but got %s' % repr(out))

            print 'Skipping images!'
            #genSlideImages(instance)
            modified = True
            
        if instance.text == '':
            # extract text
            randFile = '/tmp/%s.tmp' % randomString(6)
            runCmd(('pdftotext', '-enc', 'UTF-8', instance.pdf.path, randFile))
            with open(randFile, 'r') as ff:
                uu = UnicodeDammit(ff.read())
            textUnicode = uu.unicode_markup
            instance.text = textUnicode.encode('ascii', 'ignore')
            modified = True
            print 'got text: %s...' % instance.text[:100]

        if instance.slug == '':
            instance.slug = os.path.split(instance.getImageBasePath())[-1]
            modified = True
            print 'set slug to:', instance.slug

        if modified:
            print 'saving'
            instance.save()