本文整理匯總了Python中rapuma.core.tools.Tools.mergePdfFilesPdftk方法的典型用法代碼示例。如果您正苦於以下問題:Python Tools.mergePdfFilesPdftk方法的具體用法?Python Tools.mergePdfFilesPdftk怎麽用?Python Tools.mergePdfFilesPdftk使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rapuma.core.tools.Tools
的用法示例。
在下文中一共展示了Tools.mergePdfFilesPdftk方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: ProjBackground
# 需要導入模塊: from rapuma.core.tools import Tools [as 別名]
# 或者: from rapuma.core.tools.Tools import mergePdfFilesPdftk [as 別名]
#.........這裏部分代碼省略.........
def turnOffDocInfo (self) :
'''Change the layout config settings to turn off the doc info in the background.'''
if self.tools.str2bool(self.layoutConfig['DocumentFeatures']['useDocInfo']) :
self.layoutConfig['DocumentFeatures']['useDocInfo'] = False
self.tools.writeConfFile(self.layoutConfig)
def addBackground (self, target) :
'''Add a background (watermark) to a rendered PDF file. This will
figure out what the background is to be composed of and create
a master background page. Using force will cause it to be remade.'''
# Do a quick check if the background needs to be remade
# The background normally is not remade if one already exists.
# If one is there, it can be remade if regenerate is set to
# to True. Obviously, if one is not there, it will be made.
if self.tools.str2bool(self.layoutConfig['DocumentFeatures']['regenerateBackground']) :
self.createBackground()
else :
# If there isn't one, make it
if not os.path.exists(self.local.backgroundFile) :
self.createBackground()
# Merge target with the project's background file in the Illustraton folder
self.log.writeToLog(self.errorCodes['1300'])
# Create a special name for the file with the background
# Then merge and save it
viewFile = self.tools.alterFileName(target, 'view')
shutil.copy(self.tools.mergePdfFilesPdftk(self.centerOnPrintPage(target), self.local.backgroundFile), viewFile)
# Not returning a file name would mean it failed
if os.path.exists(viewFile) :
return viewFile
def addDocInfo (self, target) :
'''Add (merge) document information to the rendered target doc.'''
# Initialize the process
docInfoText = self.layoutConfig['DocumentFeatures']['docInfoText']
timestamp = self.tools.tStamp()
if self.gid :
headerLine = self.pid + ' / ' + self.gid + ' / ' + timestamp
else :
headerLine = self.pid + ' / ' + timestamp
svgFile = tempfile.NamedTemporaryFile().name
## RENDERED PAGE DIMENSIONS (body)
# This can be determined with the pyPdf element
# "pdf.getPage(0).mediaBox", which returns a
# RectangleObject([0, 0, Width, Height]). The
# width and height are in points. Hopefully we will
# always be safe by measuring the gidPdfFile size.
#pdf = PdfFileReader(open(self.local.gidPdfFile,'rb'))
#var2 = pdf.getPage(0).mediaBox
#trimWidth = float(var2.getWidth())
#trimHeight = float(var2.getHeight())
trimWidth = float(self.layoutConfig['PageLayout']['pageWidth'])
trimHeight = float(self.layoutConfig['PageLayout']['pageHeight'])
# Printer page size
pps = self.printerPageSize()
示例2: ProjDiagnose
# 需要導入模塊: from rapuma.core.tools import Tools [as 別名]
# 或者: from rapuma.core.tools.Tools import mergePdfFilesPdftk [as 別名]
class ProjDiagnose (object) :
def __init__(self, pid, gid = None) :
'''Intitate the whole class and create the object.'''
# import pdb; pdb.set_trace()
self.pid = pid
self.gid = gid
self.local = ProjLocal(pid, gid)
self.tools = Tools()
self.proj_config = Config(pid, gid)
self.proj_config.getProjectConfig()
self.proj_config.getLayoutConfig()
self.layoutConfig = self.proj_config.layoutConfig
self.user = UserConfig()
self.userConfig = self.user.userConfig
self.log = ProjLog(pid)
# to [px] is 72/25.4
self.mmToPx = 72 / 25.4
# page width [px]
self.paperPxWidth = round(self.mmToPx * float(self.layoutConfig['PageLayout']['pageWidth']),1)
# page height [px]
self.paperPxHeight = round(self.mmToPx * float(self.layoutConfig['PageLayout']['pageHeight']),1)
# Log messages for this module
self.errorCodes = {
'0000' : ['MSG', 'Placeholder message'],
'1310' : ['WRN', 'Failed to add diagnostic component: [<<1>>] with error: [<<2>>]']
}
###############################################################################
############################### Create Functions ##############################
###############################################################################
######################## Error Code Block Series = 1000 #######################
###############################################################################
def turnOnDiagnostic (self) :
'''Change the layout config settings to turn on the diagnostic layer.'''
if not self.tools.str2bool(self.layoutConfig['DocumentFeatures']['useDiagnostic']) :
self.layoutConfig['DocumentFeatures']['useDiagnostic'] = True
self.tools.writeConfFile(self.layoutConfig)
def turnOffDiagnostic (self) :
'''Change the layout config settings to turn off the diagnostic layer.'''
if self.tools.str2bool(self.layoutConfig['DocumentFeatures']['useDiagnostic']) :
self.layoutConfig['DocumentFeatures']['useDiagnostic'] = False
self.tools.writeConfFile(self.layoutConfig)
def addTransparency (self, target, force = False) :
'''Add a transparent layer to a rendered PDF file. This will
add in diagnosing format issues. Using force will cause any
existing layer file to be remade.'''
# Do a quick check if the transparency needs to be remade
# The transparency normally is not remade if one already exists.
# If one is there, it can be remade in two ways, with a force
# or a regenerate command.
if force :
self.createDiagnostic()
elif self.tools.str2bool(self.layoutConfig['DocumentFeatures']['regenerateTransparency']) :
self.createDiagnostic()
else :
# If there isn't one, make it
if not os.path.exists(self.local.diagnosticFile) :
self.createDiagnostic()
# Create a special temp named file for the target
tmpTarget = tempfile.NamedTemporaryFile().name
# Copy the target to the tmpTarget
shutil.copy(target, tmpTarget)
# Overlay the transparency diagnostic file over the tmpTarget
self.tools.mergePdfFilesPdftk(tmpTarget, self.local.diagnosticFile)
# Create a special name for the file with the background
# Then merge and save it
viewFile = self.tools.alterFileName(target, 'view')
# Copy the results back to the target (should be done now)
shutil.copy(tmpTarget, viewFile)
# Not returning a file name would mean it failed
if os.path.exists(viewFile) :
return viewFile
def createDiagnostic (self) :
'''Create a diagnostic transparency (file) that will be
superimposed over the page contents to help diagnose format
issues. This will overwrite any existing transparency file and
will add each recognoized diagnostic type found in the
#.........這裏部分代碼省略.........