示例#1
0
def convert(parms):
	
	start=datetime.datetime.utcnow()
	muPdf=MuPdf()
	muPdf.open(parms.inPdf)
	count=muPdf.getPageCount()
	for i in range(1, count+1):
		muPdf.loadPage(i)
		pngName="%s%d.png" %(parms.outPng,i)
		muPdf.render(pngName,angle=parms.angle, resolution=parms.resolution, xDelta=parms.xdelta, yDelta=parms.ydelta, aaLevel=parms.aalevel,maxWidth=parms.maxWidth, maxHeight=parms.maxHeight, colorSpace=parms.colorSpace)
		if parms.pcxPrefix:
			im=Image.open(pngName)
			pcxName="%s%d.pcx" %(parms.pcxPrefix,i)
			print pcxName
			im.save(pcxName)
			
		if parms.rllPrefix:
			rllName="%s%d.rll" %(parms.rllPrefix,i)
			print rllName
			RllConvert(pngName, rllName)
			
		if parms.prnPrefix:
			prnName="%s%d.prn"%(parms.prnPrefix, i)
			if parms.printer:
				printToFile(pngName, parms.printer, prnName,)
	muPdf.freePage()
	muPdf.close()
	muPdf.freeContext()
	
	end=datetime.datetime.utcnow()
	print end-start
示例#2
0
	def producePage(self):
		self.muPdf.loadPage(self.curPage)
						
		pngName=self.getTmpName(self.req.pngPrefix, "png")
							
		self.muPdf.render(pngName, angle=self.req.angle, resolution=self.req.resolution, xDelta=self.req.xdelta, yDelta=self.req.ydelta, aaLevel=self.req.aalevel)
		self.muPdf.freePage()
		
		if self.req.pcxPrefix:
			pcxName=self.getTmpName(self.req.pcxPrefix, "pcx")
			
			im=Image.open(pngName)
			im.save(pcxName)
			if not self.req.keep:
				os.unlink(pngName)
			return pcxName
			
		if self.req.rllPrefix:
			rllName=self.getTmpName(self.req.rllPrefix, "rll")
			RllConvert(pngName, rllName)
			if not self.req.keep:
				os.unlink(pngName)
			return rllName
			
		if self.req.printer:
			prnName=self.getTmpName(self.req.prnPrefix, "prn")
			if printToFile(pngName, self.req.printer, prnName):
				if not self.req.keep:
					os.unlink(pngName)
				return prnName
			else:
				return ""
		return pngName