【问题标题】:Generate PDF from a big image using Apache FOP使用 Apache FOP 从大图像生成 PDF
【发布时间】:2012-06-27 11:16:31
【问题描述】:

我想使用 Apache FOP 和 XSLT 从图像生成 PDF。但是,如果图像更大,然后是 PDF 文档页面,则它只会获得页面上可用的空间(包括右边距和下边距)。因此,部分图像超出了页面边界。

这是否可以设置 fop,以便如果图像无法放入页面中,它会自动拆分为多个页面?

这是我的 xslt 模板:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.1"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"
    xmlns:java="http://xml.apache.org/xslt/java"
    xmlns:dp="http://www.dpawson.co.uk"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:f="Functions"
    xmlns:xdt="http://www.w3.org/2005/02/xpath-datatypes"
    exclude-result-prefixes="java">

    <xsl:output method="xml" version="1.0" omit-xml-declaration="no" indent="yes" />

    <xsl:param name="image-print-path" />

    <xsl:template match="/">
        <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
            <fo:layout-master-set>
                <fo:simple-page-master master-name="simpleA4"
                    page-height="29.7cm" page-width="21cm" margin-top="2cm"
                    margin-bottom="2cm" margin-left="2cm" margin-right="2cm">
                    <fo:region-body margin-top="20pt" margin-bottom="35pt" />
                    <fo:region-before extent=".5in"/>
                    <fo:region-after extent=".5in"/>
                </fo:simple-page-master>
            </fo:layout-master-set>

            <fo:page-sequence master-reference="simpleA4">
                <fo:static-content flow-name="xsl-region-before" text-align="left">
                    <fo:block font-size="10pt">
                        Print
                    </fo:block>
                </fo:static-content>

                <fo:static-content flow-name="xsl-region-after">
                    <fo:block font-size="10pt" text-align="left">
                        something else
                    </fo:block>
                <!--    TODO: add current date, page number -->
                </fo:static-content>

                <fo:flow flow-name="xsl-region-body">
                    <fo:block font-size="10pt" page-break-after="always">
                        <fo:external-graphic src="{$image-print-path}"/>
                    </fo:block>
                </fo:flow>
            </fo:page-sequence>
        </fo:root>
    </xsl:template>

</xsl:stylesheet>

【问题讨论】:

    标签: java xslt xsl-fo apache-fop


    【解决方案1】:

    the spec 中似乎没有任何可以按照您需要的方式进行格式化的内容。这给您留下了几个选择:

    1. 在将图形注入 XSL 工作流程之前检查图形并将其切割成多个图像以在多个页面中使用
    2. 检查图形以确定其尺寸并创建足够大的页面大小以容纳它,然后将切片留给打印机进行
    3. content-width 设置为scale-down-to-fit 以在单个页面上显示整个图形

    【讨论】:

    • 您好,感谢您的回复。最后,我的解决方案是将图像分成几块以适合页面。
    猜你喜欢
    • 2018-07-01
    • 1970-01-01
    • 2022-11-25
    • 2012-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-16
    • 1970-01-01
    相关资源
    最近更新 更多