CREATE A MULTIPLE PAGE PDF FROM SCANNED PAGES

Using  XSL:FO


You want to scan in multiple pages and end up with a PDF not a TIFF but your scanner won't let you!
Here is what you do, use your scanner to create jpg's and build your own PDF.

fop command
fop.sh -xml /u/tmp/scan.xml -xsl scan2pdf.xsl new.pdf

The  XML

<?xml  version='1.0'?>
<scan2pdf  xmlns="http://www.ci-inc.com/namespace"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <Scan>
                <Scan_Item>/pages/scan-001.jpg</Scan_Item>
        </Scan>
        <Scan>
                <Scan_Item>/pages/scan-002.jpg</Scan_Item>
        </Scan>
        <Scan>
                <Scan_Item>/pages/scan-003.jpg</Scan_Item>
        </Scan>
</scan2pdf>

The  XSL:FO

<?xml  version="1.0"  encoding="UTF-8"?>
<xsl:stylesheet  version="2.0"  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  xmlns:fo="http://www.w3.org/1999/XSL/Format"  xmlns:tbe="http://www.ci-inc.com/namespace"  xmlns:xs="http://www.w3.org/2001/XMLSchema"  xmlns:fn="http://www.w3.org/2005/02/xpath-functions"  xmlns:xdt="http://www.w3.org/2005/02/xpath-datatypes">
<!--  PAGE  DIMENSIONS  -  BEGIN  -->
<xsl:variable  name="fo:layout-master-set">
  <fo:layout-master-set>
    <fo:simple-page-master  master-name="default-page"  page-height="11in"  page-width="8.5in"  margin-left="0.0in"  margin-right="0.0in">
      <fo:region-body  margin-top="0.0in"  margin-bottom="0.0in"  />
      <fo:region-after  extent="0.0in"  />
    </fo:simple-page-master>
  </fo:layout-master-set>
</xsl:variable>
<!--  PAGE  DIMENSIONS  -  END      -->
<xsl:output  version="1.0"  encoding="UTF-8"  indent="no"  omit-xml-declaration="no"  media-type="text/html"  />
<xsl:template  match="/">
<fo:root>
<xsl:copy-of  select="$fo:layout-master-set"  />
<fo:page-sequence  master-reference="default-page"  initial-page-number="1"  format="1">
<!--  FOOTER  -  BEGIN  -->
<fo:static-content  flow-name="xsl-region-after"  display-align="after">
</fo:static-content>
<!--  FOOTER  -  END      -->
<!--  BODY  -  BEGIN  -->
<fo:flow  flow-name="xsl-region-body">
<fo:block>
<!--  PAGE  HEADER  :  BEGIN  -->
  <xsl:for-each  select="tbe:scan2pdf">
    <fo:table  table-layout="fixed"  width="100%"  space-before.optimum="1pt"  space-after.optimum="2pt">
      <!--  initializes  detail  column  headings  :  BEGIN  -->
      <fo:table-column  />
      <!--  initializes  detail  column  headings  :  END      -->
        <fo:table-header>
          <fo:table-row>
            <fo:table-cell  border-style="solid"  border-width="0pt"  border-color="#FF0000"  padding-start="0pt"  padding-end="0pt"  padding-before="0pt"  padding-after="0pt"  number-columns-spanned="1"  display-align="center"  text-align="start">
            </fo:table-cell>
          </fo:table-row>
        </fo:table-header>
<!--  PAGE  HEADER  :  END      -->
        <!--  Detail  Loop  :  BEGIN  -->
        <fo:table-body>
          <xsl:for-each  select="tbe:Scan">
            <fo:table-row>
                <fo:table-cell  border-bottom-color="#000000"  border-left-color="#000000"  border-right-color="#000000"  border-top-color="#FFFFFF"  border-style="solid"  border-width="0pt"  padding-start="0pt"  padding-end="0pt"  padding-before="0pt"  padding-after="0pt"  display-align="center"  text-align="start">
                  <!--  image  start  -->
                  <fo:block>
                    <xsl:for-each  select="tbe:Scan_Item">
                      <fo:external-graphic  space-before.optimum="0pt"  space-after.optimum="0pt">
                        <xsl:attribute  name="src">url('<xsl:value-of  select="."  />')</xsl:attribute>
                      </fo:external-graphic>
                    </xsl:for-each>
                  </fo:block>
                  <!--  image  end  -->
                </fo:table-cell>
              </fo:table-row>
            </xsl:for-each>
          </fo:table-body>
        </fo:table>
      </xsl:for-each>
    </fo:block>
    <!--  Detail  Loop  -  END      -->
<!--  BODY  -  END      -->
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
</xsl:stylesheet>