Page 1 of 1

Image scaling depending on output

Posted: Tue May 15, 2012 1:04 pm
by H_Too_Oh
If I put screenshots and other graphics in what seem like normal sizes, e.g. 500px wide, they come out as far too large in my PDF output.

If I use "scale=50" attribute, that solves that and they come out well for the PDF, but then are far too small in my Eclipse Infocenter HTML output.

If I remove the scale attribute and set "scalefit" to "yes", the image vanishes completely in the PDF output.

Does anyone have any advice about general image scaling strategies? My first thought is that I could include each image twice, scaled two different ways, and use conditional profiling to exclude one from PDF output and the other from HTML, but it seems like there's probably a better way.

Mac OS 10.6
XEP RenderX
Oxygen Editor 13.2
Dita Bookmaps

Re: Image scaling depending on output

Posted: Tue May 15, 2012 2:36 pm
by Radu
Hi,

I think there have been discussions in the past on the DITA Users List about this.
Indeed conditional profiling is one option.
My suggested solution would be to leave the images in the DITA content without a @scale attribute set to them and then customize the XSLT stylesheets which generate PDF output to add this scale to all images when the XSL-FO output is generated.

If you look in this XSLT stylesheet:

OXYGEN_INSTALL_DIR/frameworks/dita/DITA-OT/demo/fo/xsl/fo/commons.xsl

it's got some code like:

Code: Select all

 <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>
which looks at the @scale attribute set on the image.
You could replace it with something like:

Code: Select all

<xsl:attribute name="content-width">
<xsl:value-of select="'50%')"/>
</xsl:attribute>
If you want various opinions from our users I would suggest you to join the Oxygen Users mailing List and ask the question there:

http://www.oxygenxml.com/mailman/listinfo/oxygen-user/

Regards,
Radu

Re: Image scaling depending on output

Posted: Tue May 15, 2012 4:09 pm
by H_Too_Oh
That would be a great solution.

It doesn't seem to like that code- just to be clear, you're talking about replacing the top one entirely with the bottom code, right? Eliminating the "if test" code and just telling it the scale to use?

Could you take a quick look at the code again? It doesn't like the single ) it seems, but if I remove it then the build works, but the image isn't scaled, plus then I see this message:

transform.fo2pdf.xep:
[java] ERROR: no space for an element, trying to recover
[java] ERROR: no space for an element, trying to recover

I don't really know enough about XSL syntax to know what's wrong myself.

I did look at various DITA forums but I saw nothing that addressed this directly, as far as I could find anyway.

Thanks a million.

Re: Image scaling depending on output

Posted: Wed May 16, 2012 11:34 am
by Radu
Hi,

I should have tried what I suggested to you first.

You were right in removing the extra ) from the replacement code.

There is another stylesheet:

OXYGEN_INSTALL_DIR/frameworks/dita/DITA-OT/demo/fo/xsl/fo/flagging.xsl

in which there is the same code which needs to be replaced.
Somehow the template in this XSL overwrites the one in the XSL I told you to modify in the first post. I will discuss this with the DITA OT developers.

In my sample DITA Map I'm not getting the extra warnings you are mentioning when running XEP, the warnings may not be generated by this modification.

Regards,
Radu

Re: Image scaling depending on output

Posted: Wed May 16, 2012 2:05 pm
by H_Too_Oh
Great. That seems to work perfectly now.

With the other error message, I think I see what happened. When I took off the scale attribute to try the modification above, then one of the images was too large for the system and it didn't appear at all, thus that error. Now that the modification works, and that one is automatically scaled at 50% like the rest, it appears again and that error is gone.

Thanks again. Much easier than inserting the images twice. Plus explaining to whoever will be maintaining these documents why there are two images side by side would be a long story, much more elegant solution this way.

Re: Image scaling depending on output

Posted: Thu May 18, 2017 8:33 pm
by dgallo
I am experiencing the same issue when transforming PDF and HTML output with a svg image. I would like to assign a max-width for both outputs, but I am not sure how to do this with the PDF. I have tried as you suggested above and have not had success. I am using Oxygen 18.1.

Re: Image scaling depending on output

Posted: Mon May 22, 2017 5:10 pm
by radu_pisoi
Hi,

A possible implementation is to set the max-width property for the XSL-FO external-graphic element generated for the corresponding DITA image.
https://www.w3.org/TR/xsl/#fo_external-graphic

Code: Select all

<fo:external-graphic max-width="2in" src="url('images/batik3D.svg')"/>
To implement this, you need to override the following XSLT template from your PDF customization:

Code: Select all

<xsl:apply-templates select="." mode="placeImage">
The XSLT stylesheet that defines this template is:

Code: Select all

DITA-OT-DIR/plugins/org.dita.pdf2/xsl/fo/commons.xsl
To specify the max-width information in the DITA image element, you can use the outputclass attribute.

Code: Select all

<image href="../images/batik3D.svg" id="image_xqs_dvd_zz" outputclass="max-width=100;"/>