How to change image size in Pdf transform?

ann.jensen
Posts: 236
Joined: Wed Jun 17, 2015 10:19 am

How to change image size in Pdf transform?

Post by ann.jensen » Tue Oct 25, 2016 6:45 pm

Hi,
I am trying to do the following with images sizes:
- reduce the image size to 50% for PDF transform
- apply scalefit for webhelp transform

My DITA code is as follows;

Code: Select all

     <step>
<cmd>Select an Occupied Properties - <ph
conref="../../../../../t_content_refs.dita#t_content_refs/evic_init_task"/>
task from the property task summary that is in status <i>Open</i> .</cmd>
<info><image href="images/i_eviction_initated_open.png" scalefit="yes"/>
</info>
</step>
<step>
<cmd><ph
conref="../../../../../t_content_refs.dita#t_content_refs/select_cancel_action"
/></cmd>
<info><image href="images/i_eviction_cancelled.png" scalefit="yes"/></info>
</step>
and the related code in my custom PDF plugin file C:\Program Files (x86)\Oxygen XML Author 18\frameworks\dita\DITA-OT2.x\plugins\com.example.print-pdf\xsl\fo\commons.xsl looks as follows:

Code: Select all

  <fo:external-graphic src="url('{$href}')" xsl:use-attribute-sets="image">
<!--Setting image height if defined-->
<xsl:if test="$height">
<xsl:attribute name="content-height">
<!--The following test was commented out because most people found the behavior
surprising. It used to force images with a number specified for the dimensions
*but no units* to act as a measure of pixels, *if* you were printing at 72 DPI.
Uncomment if you really want it. -->
<xsl:choose>
<!--xsl:when test="not(string(number($height)) = 'NaN')">
<xsl:value-of select="concat($height div 72,'in')"/>
</xsl:when-->
<xsl:when test="not(string(number($height)) = 'NaN')">
<xsl:value-of select="concat($height, 'px')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$height"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</xsl:if>
<!--Setting image width if defined-->
<xsl:if test="$width">
<xsl:attribute name="content-width">
<xsl:choose>
<!--xsl:when test="not(string(number($width)) = 'NaN')">
<xsl:value-of select="concat($width div 72,'in')"/>
</xsl:when-->
<xsl:when test="not(string(number($width)) = 'NaN')">
<xsl:value-of select="concat($width, 'px')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$width"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</xsl:if>
<xsl:if test="not($width) and not($height) and not(@scale)">
<xsl:attribute name="content-width">
<xsl:value-of select="'50%'"/>
</xsl:attribute>
<xsl:attribute name="content-height">
<xsl:value-of select="'50%'"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="@scalefit = 'yes' and not($width) and not($height) and not(@scale)">
<xsl:attribute name="width"> <xsl:value-of select="'50%'"/></xsl:attribute>
<xsl:attribute name="height"> <xsl:value-of select="'50%'"/></xsl:attribute>
<xsl:attribute name="content-width"> <xsl:value-of select="'50%'"/></xsl:attribute>
<xsl:attribute name="content-height"> <xsl:value-of select="'50%'"/></xsl:attribute>
<xsl:attribute name="scaling">uniform</xsl:attribute>
</xsl:if>
<xsl:apply-templates select="node() except (text(),
*[contains(@class, ' topic/alt ') or
contains(@class, ' topic/longdescref ')])"/>
</fo:external-graphic>
None of the xsl tests seem to be applying for the PDF transform and my images are appearing full size.
Can anyone see what's wrong with this?
Thanks in advance,
Ann

radu_pisoi
Posts: 375
Joined: Thu Aug 21, 2003 11:36 am
Location: Craiova
Contact:

Re: How to change image size in Pdf transform?

Post by radu_pisoi » Wed Oct 26, 2016 3:25 pm

Hi,

I don't see any problem, your XSLT customization seems to impose the 'content-width' and 'content-height' traits to 50% when @scale, @width and @height attributes are not set. Maybe you should also handle the case when the @scale attribute is set.

For cases like this, I think you can try the next approach:
1. Try to add xsl:messages in your code, maybe your XSLT customization was not called;
2. Inspect the topic.fo file that represents the input for the XSL-FO processor. This file is generated in a temporary folder and it is deleted automatically by the transformation. You can avoid this by setting the clean.temp parameter to no and check the temp/topic.fo. The temp directory is usually generated near your DITA map file.
Radu Pisoi
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

Post Reply