本文整理匯總了Python中rapuma.core.tools.Tools.convertSvgToPdfRsvg方法的典型用法代碼示例。如果您正苦於以下問題:Python Tools.convertSvgToPdfRsvg方法的具體用法?Python Tools.convertSvgToPdfRsvg怎麽用?Python Tools.convertSvgToPdfRsvg使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rapuma.core.tools.Tools
的用法示例。
在下文中一共展示了Tools.convertSvgToPdfRsvg方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: ProjBackground
# 需要導入模塊: from rapuma.core.tools import Tools [as 別名]
# 或者: from rapuma.core.tools.Tools import convertSvgToPdfRsvg [as 別名]
#.........這裏部分代碼省略.........
# 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()
ppsWidth = pps[0]
ppsHeight = pps[1]
ppsCenter = ppsWidth/2
# Write out SVG document text
with codecs.open(svgFile, 'wb') as fbackgr : # open file for writing
fbackgr.write( '''<svg xmlns="http://www.w3.org/2000/svg"
version="1.1" width = "''' + str(ppsWidth) + '''" height = "''' + str(ppsHeight) + '''">
<g><text x = "''' + str(ppsCenter) + '''" y = "''' + str(20) + '''" style="font-family:DejaVu Sans;font-style:regular;font-size:8;text-anchor:middle;fill:#000000;fill-opacity:1">''' + headerLine + '''</text></g>
<g><text x = "''' + str(ppsCenter) + '''" y = "''' + str(ppsHeight-30) + '''" style="font-family:DejaVu Sans;font-style:regular;font-size:8;text-anchor:middle;fill:#000000;fill-opacity:1">''' + self.tools.fName(target) + '''</text></g>
<g><text x = "''' + str(ppsCenter) + '''" y = "''' + str(ppsHeight-20) + '''" style="font-family:DejaVu Sans;font-style:regular;font-size:8;text-anchor:middle;fill:#000000;fill-opacity:1">''' + docInfoText + '''</text></g>
</svg>''')
# Merge target with the background
self.log.writeToLog(self.errorCodes['1305'])
# Create a special name for the file with the background
viewFile = self.tools.alterFileName(target, 'view')
# Compare the new file name with the target to see if we are
# already working with a background file
if viewFile == target :
# If the target is a BG file all we need to do is merge it
self.tools.mergePdfFilesPdftk(viewFile, self.tools.convertSvgToPdfRsvg(svgFile))
else :
# If not a BG file, we need to be sure the target is the same
# size as the print page to merge with pdftk
shutil.copy(self.tools.mergePdfFilesPdftk(self.centerOnPrintPage(target), self.tools.convertSvgToPdfRsvg(svgFile)), viewFile)
# Not returning a file name would mean it failed
if os.path.exists(viewFile) :
return viewFile
##### Background Creation Functions #####
def createBackground (self) :
'''Create a background file. This will overwrite any existing
background file and will add each recognized background type
found in the bacgroundComponents config setting.'''
self.createBlankBackground()
# Add each component to the blank background file
for comp in self.layoutConfig['DocumentFeatures']['backgroundComponents'] :
try :
getattr(self, 'merge' + comp.capitalize())()
except Exception as e :
self.log.writeToLog(self.errorCodes['1310'],[comp,str(e)])
pass
self.log.writeToLog(self.errorCodes['1320'])
return True
def createBlankBackground (self) :
示例2: ProjDiagnose
# 需要導入模塊: from rapuma.core.tools import Tools [as 別名]
# 或者: from rapuma.core.tools.Tools import convertSvgToPdfRsvg [as 別名]
#.........這裏部分代碼省略.........
# import pdb; pdb.set_trace()
self.createBlankTransparency()
# Add each component to the blank transparency file
for comp in self.layoutConfig['DocumentFeatures']['diagnosticComponents'] :
try :
getattr(self, 'merge' + comp.capitalize())()
except Exception as e :
self.log.writeToLog(self.errorCodes['1310'],[comp,str(e)])
pass
return True
def createBlankTransparency (self) :
'''Create a blank background page according to the trim size
specified.'''
# Set the temp svg file name
svgFile = tempfile.NamedTemporaryFile().name
# Be sure there is an illustrations folder in place
if not os.path.isdir(self.local.projIllustrationFolder) :
os.mkdir(self.local.projIllustrationFolder)
# Write out SVG document text
with codecs.open(svgFile, 'wb') as fbackgr : # open file for writing
fbackgr.write( '''<svg xmlns="http://www.w3.org/2000/svg"
version="1.1" width = "''' + str(self.paperPxWidth) + '''" height = "''' + str(self.paperPxHeight)+ '''">
</svg>''')
shutil.copy(self.tools.convertSvgToPdfRsvg(svgFile), self.local.diagnosticFile)
###############################################################################
############################# Component Functions #############################
###############################################################################
######################## Error Code Block Series = 2000 #######################
###############################################################################
def mergeLeading (self) :
'''Create a diagnostic page component that has lines to indicate
the text leading. This will be superimposed over the contents of
the trim page, not in the background like a watermark, etc.'''
# Initialize the process
svgFile = tempfile.NamedTemporaryFile().name
# PAGE DIMENSIONS
# The page dimensions extracted from layoutConfig are in [mm] and
# must be converted to pixels [px], the conversion factor for [mm]
# bodyFontSize [px]
bodyFontSize = self.layoutConfig['TextElements']['bodyFontSize']
bodyFontPxSize = round(float(bodyFontSize) * 72/72.27,3)
# bodyTextLeading [px]
bodyTextLeading = self.layoutConfig['TextElements']['bodyTextLeading']
bodyTextPxLeading = round(float(bodyTextLeading) * 72/72.27,3)
# top margin [px]
topMargin = self.layoutConfig['PageLayout']['topMargin']
topPxMargin = round(self.mmToPx * float(topMargin),1)
# outside margin [px]
outsideMargin = self.layoutConfig['PageLayout']['outsideMargin']
outsidePxMargin = round(self.mmToPx * float(outsideMargin),1)
#inside margin [px]