Question
· May 25, 2016

Infusing SVG into a pdf document...

Hello there Intersystems Developer Community,

This year while at the Global Summit, I came to learn of a component that Stephen Morrison of Intersystems had written that was capable of infusing SVG content into a PDF document.  Apparently Stephen was approached about this and was amenable to sharing the code with us as we have recently encountered a similar need.  I'm hoping this post will lead to the sharing of this utility code, so that we can determine if it will indeed suit our need.

It is my impression that this code is maybe that being used to perform the print operation on a given widget from DeepSee?

Any detail that would be helpful in us adopting/trying it would also be welcome of course.

Thanks for your consideration,
  Jeff

Discussion (2)0
Log in or sign up to continue

Hi Jeff,

The component you are referring to is the %ZEN.ComponentEx.svgImageProvider. This is extended for printing in DeepSee by the %DeepSee.Component.deepseeSvgImageProvider. The latter adds some DeepSee-specific tools for converting certain HTML tables to SVG documents for printing the pivotTable component and ZEN chart legends.

The %ZEN version is the utility that handles the creation of an XSL-FO file containing the SVG gathered from the browser's DOM, and then invokes the FOP engine on the server to convert that XSL-FO to a PDF.

In it's most basic usage, you can print the SVG content of the chart from DeepSee's Basic Dashboard demo using this sample code in the Developer Tools console:

util = zenPage.getComponentById("svgUtil")
inFile = util.makeSVGFileName("infile.xsl")
parms = {}
parms.fileName = inFile
util.saveToXSLFile('$widget_2/svgFrame',parms)
outFile = util.makeSVGFileName("outfile.pdf")
util.ConvertXSLToPDF(inFile,outFile)

The parms object can be used to insert arbitrary svg content before and after the target content from the DOM using 

parms.svgIntro
parms.svgCoda

Simlarly, arbitrary fo can be inserted before and after the complete SVG content (svgIntro + userContent + svgCoda) using 

foIntro
foCoda

It is worth noting that this component does not allow for placement of temp files anywhere other than the install's <installDir>/mgr/Temp directory. The output pdf file is considered a temporary file that should be opened and saved by the user using any client capable of handling the file. For the DeepSee example, "printing" means performing an elaborate version of the above sample script and then openeing that temporary pdf to the user in the browser, where the user may save it to any location. The .xsl and .pdf files are deleted from <installDir>/mgr/Temp once the page successfully loads in the browser.

Regards,
Dan

Thanks for this detailed response Dan.

In the meantime we have decided for our current reporting needs that we will produce an HTML report, and allow the user to rely on the browser's built-in print capability, in the interest of delegating the printing responsibility to existing functionality.  But I know this response is here, and if we re-visit the idea of printing directly to PDF, to include SVG, I will know where to look for how to get started.

 

Thanks again for the quick and thorough response,

  Jeff