私は、グラフと表を PDF にエクスポートするプロジェクトに取り組んでいます。PDF の生成には Apache FOP を使用しています。グラフは SVG であり、1 つしかない場合は問題なく表示されます。ただし、最大 4 つある場合があり、これらの場合、生成された PDF に適合するのは 4 つのうち 3 つだけです。数に関係なく、すべての画像が収まるようにする必要があります。残念ながら、単にページを横向きにすることは、さらに多くのページを収める必要がある場合の一時的な解決策になるでしょう. 各グラフのサイズは、Highcharts ライブラリによってクライアントで生成された svg からピクセル単位で設定されます。ここに見られる例に従って instream-foreign-object の属性を設定しても、画像がスケーリングなしで pdf に挿入されているように見えます: scale-to-fit を使用した画像のスケーリング
したがって、各チャートを「縮小して合わせる」必要があります。インストリーム外部オブジェクトを含む各要素を囲む要素の長さと幅を設定しようとしました (xsl も含めています)。instream-foreign -object 内で、実際のチャート svg の値に svg の幅と高さを割り当てています。おそらくこれが問題だと思いましたが、これらの寸法を含めないと、グラフが pdf に表示されません。ここの質問に従って、スケーリング属性を「不均一」に設定しようとしました:固定高さで画像をスケーリングしても、結果は良くありませんでした。実際にはページ全体にグラフが引き伸ばされ、4 つのうちの 1 つだけが表示されます。これが私のxslです:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<fo:root>
<fo:layout-master-set>
<fo:simple-page-master master-name="exportPage">
<fo:region-body />
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="exportPage">
<fo:flow flow-name="xsl-region-body">
<fo:block id="mainTitleBlock" font-family="arial, helvetica, sans-serif" color="#5c068c" font-weight="bold">
<xsl:value-of select="exports/export/charts/@mainTitle"/>
</fo:block>
<fo:block id="timestampBlock" font-family="arial, helvetica, sans-serif" font-size="small" color="#6D869F">
<xsl:value-of select="exports/export/charts/@timeStamp"/>
</fo:block>
<!-- This is where the charts go -->
<!-- Within this block will be an inline element for each chart-->
<fo:block id="chartBlock" width="8.25in" height="6in">
<xsl:apply-templates select="exports/export/charts/chart"/>
</fo:block>
<fo:block id="tableBlock" >
<xsl:apply-templates select="exports/export/table"/>
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
<!-- Creates the table -->
<xsl:template match="table">
<fo:table table-layout="fixed" width="100%" >
<fo:table-header>
<fo:table-row>
<xsl:apply-templates select="tblRow[position() = 1]"/>
</fo:table-row>
</fo:table-header>
<fo:table-body>
<xsl:apply-templates select="tblRow[position() > 1]"/>
</fo:table-body>
</fo:table>
</xsl:template>
<xsl:template match="hdrCell">
<fo:table-cell background-color="#666" border-right-style="solid" border-right-width="1px" border-right-color="white" empty-cells="show">
<fo:block color="white" font-family="arial, helvetica, sans-serif" font-size="x-small"><xsl:value-of select="."/></fo:block>
</fo:table-cell>
</xsl:template>
<xsl:template match="tblCell">
<fo:table-cell border-bottom-style="solid" border-bottom-width="1px" border-bottom-color="#E3E3E3" >
<fo:block color="#7E7E7E" font-family="arial, helvetica, sans-serif" font-size="x-small"><xsl:value-of select="."/></fo:block>
</fo:table-cell>
</xsl:template >
<xsl:template match="tblRow[position() > 1]">
<fo:table-row>
<xsl:apply-templates />
</fo:table-row>
</xsl:template>
<xsl:template match="chart">
<fo:inline>
<fo:instream-foreign-object xmlns:svg="http://www.w3.org/2000/svg" content-width="scale-to-fit" content-height="100%" width="100%" scaling="uniform">
<svg:svg width="{svg:svg/@width}" height="{svg:svg/@height}">
<xsl:copy-of select="svg:svg"/>
</svg:svg>
</fo:instream-foreign-object>
</fo:inline>
</xsl:template>
</xsl:stylesheet>
私は何が欠けていますか?グラフを表のセルに表示することは役に立ちますか (したがって、レイアウトに表を使用しないという慣習を破ります - 恐ろしい!)? これらを拡大縮小してページに収めるにはどうすればよいですか?
ありがとう、ブラント