Skip to main content
Skip table of contents

How to use Better PDF Exporter to export progress bars to PDF?

Setup

  • Create a PDF template “epic-sum-up-tool.groovy”

    GROOVY
    import com.atlassian.jira.issue.Issue;
    import com.atlassian.jira.issue.fields.CustomField;
    import com.atlassian.jira.user.ApplicationUser;
    import com.atlassian.jira.component.ComponentAccessor
    import org.apache.commons.io.IOUtils
    import org.apache.log4j.Logger
     
     
    epicSumUp = new EpicSumUpTool()
     
    /**
     * Velocity tool to get and render Epic Sum Up progress.
     *
     * @see https://aptis.atlassian.net/wiki/spaces/ESUHC/pages/1379106862/Better+PDF+Export+Midori
     */
    class EpicSumUpTool {
        def log = Logger.getLogger(this.getClass())
     
        /**
         * Returns the Progress Object that can be used to output the text directly or render it as image
         */
       
        def getProgress(Issue issue, CustomField customField, ApplicationUser currentUser) {
            def progressProviderClass = ComponentAccessor.pluginAccessor.classLoader.loadClass("aptis.plugins.epicSumUp.api.ProgressProvider")
            def progressProvider = ComponentAccessor.getOSGiComponentInstanceOfType(progressProviderClass)
           
           
            return progressProvider.getGenericProgress(
                issue,
                customField,
                currentUser
            );
        } 
       
        /**
         * Render the given progress bar as image
         */
        def renderProgressBar(def progress) {
            if (!progress) {
                return null;
            }
            def progressBarRendererClass = ComponentAccessor.pluginAccessor.classLoader.loadClass("aptis.plugins.epicSumUp.api.ProgressBarRenderer")
            def progressBarRenderer = ComponentAccessor.getOSGiComponentInstanceOfType(progressBarRendererClass)
       
             
            def base64Image = progressBarRenderer.renderAsSvg(progress, 200, 12).bytes.encodeBase64().toString()
            return base64Image
             
        }
     
    }

  • Add the following code into your PDF template (issue-fo.vm)

    GROOVY
    ...
    ...
    ## renders custom field values
    #macro(cfValue $customField)
    	...
    	...
    	#if($customFieldValue != '') ## skips NULL, but not empty string or empty collection
    		...
    		...
    		#elseif($customFieldTypeKey == 'aptis.plugins.epicSumUp:epic-sum-up-custom-field-progress' ||
    			$customFieldTypeKey == 'aptis.plugins.epicSumUp:epic-sum-up-custom-field-time-progress' ||
    			$customFieldTypeKey == 'aptis.plugins.epicSumUp:epic-sum-up-custom-field-issue-count-progress' ||
    			$customFieldTypeKey == 'aptis.plugins.epicSumUp:epic-sum-up-custom-field-status-category-progress' ||
    			$customFieldTypeKey == 'aptis.plugins.epicSumUp:epic-sum-up-custom-field-story-points-progress')
    			$scripting.executeOnce('epic-sum-up-tool.groovy')
    			#set($progress = $epicSumUp.getProgress($issue, $customField, $user))
    			#set($progressImage = $epicSumUp.renderProgressBar($progress))
    			#if($progressImage)
    				<fo:block>
    					<fo:external-graphic content-height="0.3cm" src="data:image/svg+xml;base64,$progressImage" />
    					<fo:block>$xmlutils.escape($progress.getText())</fo:block>
    				</fo:block>
    			#end

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.