A way to automatically scale all images in pdf?

Here should go questions about transforming XML with XSLT and FOP.
justyna_i
Posts: 9
Joined: Mon Oct 08, 2018 12:16 pm

A way to automatically scale all images in pdf?

Post by justyna_i » Mon Jun 01, 2020 12:00 pm

Hello,

is there any automatic way to scale all images throughout the dita bookmap into the same size in PDF print?

I have inherited dita structures that include images added by different people, different time, different resolution, different sizes. The result is that images throughout the whole pdf have different sizes.

Preferably some setting in XSLT customization that overrides each image own attributes?

P.S. All images are conkeyref-ed.

Radu
Posts: 7019
Joined: Fri Jul 09, 2004 5:18 pm

Re: A way to automatically scale all images in pdf?

Post by Radu » Tue Jun 09, 2020 11:28 am

Hi,

Sorry for the delay. Are you publishing to PDF using the default XSL-FO based publishing or Oxygen's specific CSS-based PDF publishing? For the latter you can impose the width directly from the CSS:

https://www.oxygenxml.com/doc/versions/ ... mages.html

For the former you would indeed need to perform some XSLT customizations:

https://www.oxygenxml.com/doc/versions/ ... utput.html

The XSLT stylesheet:

DITA-OT-DIR/plugins/org.dita.pdf2/xsl/fo/topic.xsl

has a template which matches any DITA image element:

Code: Select all

<xsl:template match="*[contains(@class,' topic/image ')]" name="image">
so you would need to override it in your XSLT customization.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

justyna_i
Posts: 9
Joined: Mon Oct 08, 2018 12:16 pm

Re: A way to automatically scale all images in pdf?

Post by justyna_i » Tue Jun 09, 2020 11:32 am

Hi,

thank you for response,
I am using custom pdf plugin based on XSL-FO.

<xsl:template match="*[contains(@class,' topic/image ')]" name="image">

Do I need to create new attribute set for that?
Could you please help with code a bit more? - I am not that fluent in XSL-FO customizations yet.

Radu
Posts: 7019
Joined: Fri Jul 09, 2004 5:18 pm

Re: A way to automatically scale all images in pdf?

Post by Radu » Tue Jun 09, 2020 11:55 am

Hi,

There is another XSLT template in the same topic.xsl XSLT which looks more interesting:

Code: Select all

<xsl:template match="*" mode="placeImage">
If you copy that entire xsl template to your XSLT customization stylesheet, it has two places where it does something like:

Code: Select all

<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 $scale">
                <xsl:attribute name="content-width">
                    <xsl:value-of select="concat($scale,'%')"/>
                </xsl:attribute>
            </xsl:if>
In those places maybe instead of relying on the @scale, @width and @height attributes defined in the DITA content you can set your own XSl-FO content-width attribute value.
But I'm not sure how scalable this is, are you sure that you can find that magic width for which all images will look good in the PDF, no matter how small or large they were originally? For example we sometimes use very small images to represent button icons in the PDF, those images need to remain small in the PDF, so they should not be scaled up forcefully.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

justyna_i
Posts: 9
Joined: Mon Oct 08, 2018 12:16 pm

Re: A way to automatically scale all images in pdf?

Post by justyna_i » Tue Jun 30, 2020 1:56 pm

You are absolutely right, there are also smaller icons in the pdf and I dont want them scaled.

As a solution, we run a batch task on all images, that scaled them to the same size and resolution and it worked.

Thank you for your help!

Post Reply