示例#1
0
        else:
            try:
                device.setOption("source", "Flatbed")
                device.setOption("batch-scan", False)
            except scanext.error:
                log.debug(
                    "Error setting source or batch-scan option (this is probably OK)."
                )

        if 'file' in dest and not output:
            log.warn("File destination enabled with no output file specified.")

            if adf:
                log.info("Setting output format to PDF for ADF mode.")
                output = utils.createSequencedFilename("hpscan", ".pdf")
                output_type = 'pdf'
            else:
                if scan_mode == 'gray':
                    log.info(
                        "Setting output format to PNG for greyscale mode.")
                    output = utils.createSequencedFilename("hpscan", ".png")
                    output_type = 'png'
                else:
                    log.info(
                        "Setting output format to JPEG for color/lineart mode."
                    )
                    output = utils.createSequencedFilename("hpscan", ".jpg")
                    output_type = 'jpeg'

            log.warn("Defaulting to '%s'." % output)
示例#2
0
def documentmerge(adf_page_files,ext,output_path):
    import numpy as np
    from PIL import Image
    from PyPDF2 import PdfFileMerger
    #print(output_type)
    #adf_page_files2 = []
    list_im = []
    i = 0
    if ext == ".pdf":
        merger = PdfFileMerger()
    '''if ext == ".pdf":
        merger = PdfFileMerger()
        for p in adf_page_files:
            output = utils.createSequencedFilename("hpscan", ".png", output_path)
            cmd = "convert %s %s" %(p,output)
            status = utils.run(cmd)
            #print (status[0])
            #print (status[1])
            if status[0] == -1:
                #print ("entered status -1")  
                log.error("Convert command not found.")
                sys.exit(6)
            adf_page_files2.append(output)
        #print(adf_page_files2)
        for p in adf_page_files:
            os.unlink(p) 
        adf_page_files = adf_page_files2
        #del adf_page_files2[:]
        #print(adf_page_files)'''      	
    while i < len(adf_page_files):       
        list_im = [adf_page_files[i], adf_page_files[i+1]]        	
        imgs    = [Image.open(y) for y in list_im ]
        # pick the image which is the smallest, and resize the others to match it (can be arbitrary image shape here)
        min_shape = sorted( [(np.sum(z.size), z.size ) for z in imgs])[0][1]
        imgs_comb = np.hstack( (np.asarray( w.resize(min_shape) ) for w in imgs ) )

        # save that beautiful picture
        imgs_comb = Image.fromarray( imgs_comb)
        for p in list_im:
            os.remove(p)        
        '''if ext == ".pdf":
            temp = 'temp.pdf'
            imgs_comb = imgs_comb.convert("RGB")
            imgs_comb.save( temp )
            merger.append(open(temp,'rb'))
            cmd = 'rm -f ' + temp
            utils.run(cmd)
        else:'''
        if ext == ".pdf":
            temp = 'temp.pdf'
            imgs_comb = imgs_comb.convert("RGB")
            imgs_comb.save( temp )
            merger.append(open(temp,'rb'))
            cmd = 'rm -f ' + temp
            utils.run(cmd)
            #adf_page_files2.append(temp)
            #merger = PdfFileMerger()
        else:
            temp = utils.createSequencedFilename("hpscandoc", ext, output_path)
            imgs_comb.save( temp )
        i = i + 2
    if ext == ".pdf":
        output = utils.createSequencedFilename("hpscandoc", ext, output_path)
        with open(output, 'wb') as fout:
            merger.write(fout)
        '''del adf_page_files2[:]
        del adf_page_files[:]'''
        return output
    else:
        return None
示例#3
0
                sys.exit(1)

        else:
            try:
                device.setOption("source", "Flatbed")
                device.setOption("batch-scan", False)
            except scanext.error:
                log.debug("Error setting source or batch-scan option (this is probably OK).")


        if 'file' in dest and not output:
            log.warn("File destination enabled with no output file specified.")

            if adf:
               log.info("Setting output format to PDF for ADF mode.")
               output = utils.createSequencedFilename("hpscan", ".pdf")
               output_type = 'pdf'
            else:
               if scan_mode == 'gray':
                  log.info("Setting output format to PNG for greyscale mode.")
                  output = utils.createSequencedFilename("hpscan", ".png")
                  output_type = 'png'
               else:
                  log.info("Setting output format to JPEG for color/lineart mode.")
                  output = utils.createSequencedFilename("hpscan", ".jpg")
                  output_type = 'jpeg'

            log.warn("Defaulting to '%s'." % output)

        else:
            try:
示例#4
0
def documentmerge(adf_page_files,ext,output_path):
    import numpy as np
    from PIL import Image
    from PyPDF2 import PdfFileMerger
    #print(output_type)
    #adf_page_files2 = []
    list_im = []
    i = 0
    if ext == ".pdf":
        merger = PdfFileMerger()
    '''if ext == ".pdf":
        merger = PdfFileMerger()
        for p in adf_page_files:
            output = utils.createSequencedFilename("hpscan", ".png", output_path)
            cmd = "convert %s %s" %(p,output)
            status = utils.run(cmd)
            #print (status[0])
            #print (status[1])
            if status[0] == -1:
                #print ("entered status -1")  
                log.error("Convert command not found.")
                sys.exit(6)
            adf_page_files2.append(output)
        #print(adf_page_files2)
        for p in adf_page_files:
            os.unlink(p) 
        adf_page_files = adf_page_files2
        #del adf_page_files2[:]
        #print(adf_page_files)'''      	
    while i < len(adf_page_files):       
        list_im = [adf_page_files[i], adf_page_files[i+1]]        	
        imgs    = [Image.open(y) for y in list_im ]
        # pick the image which is the smallest, and resize the others to match it (can be arbitrary image shape here)
        min_shape = sorted( [(np.sum(z.size), z.size ) for z in imgs])[0][1]
        imgs_comb = np.hstack( (np.asarray( w.resize(min_shape) ) for w in imgs ) )

        # save that beautiful picture
        imgs_comb = Image.fromarray( imgs_comb)
        for p in list_im:
            os.remove(p)        
        '''if ext == ".pdf":
            temp = 'temp.pdf'
            imgs_comb = imgs_comb.convert("RGB")
            imgs_comb.save( temp )
            merger.append(open(temp,'rb'))
            cmd = 'rm -f ' + temp
            utils.run(cmd)
        else:'''
        if ext == ".pdf":
            temp = 'temp.pdf'
            imgs_comb = imgs_comb.convert("RGB")
            imgs_comb.save( temp )
            merger.append(open(temp,'rb'))
            cmd = 'rm -f ' + temp
            utils.run(cmd)
            #adf_page_files2.append(temp)
            #merger = PdfFileMerger()
        else:
            temp = utils.createSequencedFilename("hpscandoc", ext, output_path)
            imgs_comb.save( temp )
        i = i + 2
    if ext == ".pdf":
        output = utils.createSequencedFilename("hpscandoc", ext, output_path)
        with open(output, 'wb') as fout:
            merger.write(fout)
        '''del adf_page_files2[:]
        del adf_page_files[:]'''
        return output
    else:
        return None