xml-xsl-fo-pdf
Rozdíly
Zde můžete vidět rozdíly mezi vybranou verzí a aktuální verzí dané stránky.
Předchozí verze | |||
— | xml-xsl-fo-pdf [2023/12/26 19:13] (aktuální) – upraveno mimo DokuWiki 127.0.0.1 | ||
---|---|---|---|
Řádek 1: | Řádek 1: | ||
+ | ====== XML+XSL-FO+PDF ====== | ||
+ | ===== FOP ===== | ||
+ | |||
+ | http:// | ||
+ | |||
+ | |||
+ | |||
+ | ==== Čeština ==== | ||
+ | |||
+ | Zdroj: http:// | ||
+ | |||
+ | Do **fop-1.1/ | ||
+ | |||
+ | __Podopora dělení slov__ | ||
+ | |||
+ | http:// | ||
+ | |||
+ | **fop-hyph.jar** vložit do **fop-1.1/ | ||
+ | |||
+ | __České TTF fonty__ | ||
+ | |||
+ | http:// | ||
+ | |||
+ | ==== Instalace ==== | ||
+ | |||
+ | **Stažení a rozbalení FOP** | ||
+ | |||
+ | < | ||
+ | shell# mkdir fop; cd fop | ||
+ | shell# wget -c -t 0 ftp:// | ||
+ | shell# tar xvzf fop-1.1-bin.tar.gz | ||
+ | </ | ||
+ | |||
+ | **Dělení českých slov** | ||
+ | |||
+ | Stáhnout: http:// | ||
+ | |||
+ | < | ||
+ | shell# unzip offo-hyphenation-binary_v2.0.zip | ||
+ | shell# cp ./ | ||
+ | </ | ||
+ | |||
+ | **Stažení TTF fontů** | ||
+ | |||
+ | < | ||
+ | shell# mkdir fonts-cab | ||
+ | </ | ||
+ | |||
+ | Stáhnout: http:// | ||
+ | |||
+ | * andale32.exe | ||
+ | * arialb32.exe | ||
+ | * arial32.exe | ||
+ | * comic32.exe | ||
+ | * courie32.exe | ||
+ | * georgi32.exe | ||
+ | * impact32.exe | ||
+ | * times32.exe | ||
+ | * trebuc32.exe | ||
+ | * verdan32.exe | ||
+ | * webdin32.exe | ||
+ | |||
+ | **Extrahování TTF fontů z CAB** | ||
+ | |||
+ | < | ||
+ | shell# yum install cabextract.x86_64 | ||
+ | shell# cabextract ./ | ||
+ | shell# mkdir fonts | ||
+ | shell# cp ./ | ||
+ | </ | ||
+ | |||
+ | **Vytvoření metric pro TTF fonty** | ||
+ | |||
+ | http:// | ||
+ | |||
+ | <file bash create-ttf-metrics.sh> | ||
+ | #!/bin/bash | ||
+ | # | ||
+ | # Create TrueType Font Metrics | ||
+ | # | ||
+ | # Author: Jiří Blažek (blazek@isn.cz) | ||
+ | # | ||
+ | |||
+ | # FOP path | ||
+ | FOP_PATH=" | ||
+ | |||
+ | # True Type Fonts path | ||
+ | TTF_PATH=" | ||
+ | |||
+ | # extension from | ||
+ | EXT_FROM=" | ||
+ | |||
+ | # extension to | ||
+ | EXT_TO=" | ||
+ | |||
+ | # rename files from upper to lower | ||
+ | for TTF_FILE in $(ls $TTF_PATH/ | ||
+ | mv $TTF_FILE $(echo $TTF_FILE | tr ' | ||
+ | done | ||
+ | |||
+ | # Create TrueType Font Metrics | ||
+ | for TTF_FILE in $(ls $TTF_PATH/ | ||
+ | XML_FILE=$(echo $TTF_FILE | sed " | ||
+ | |||
+ | java -cp $FOP_PATH/ | ||
+ | done | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | shell# chmod 755 create-ttf-metrics.sh | ||
+ | shell# ./ | ||
+ | </ | ||
+ | |||
+ | **Přesun fontů do FOP** | ||
+ | |||
+ | < | ||
+ | shell# mv fonts fop-1.1 | ||
+ | </ | ||
+ | |||
+ | **Konfigurace fop.xconf** | ||
+ | |||
+ | http:// | ||
+ | |||
+ | <file xml ./ | ||
+ | < | ||
+ | ... | ||
+ | < | ||
+ | <font metrics-file=" | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | <font metrics-file=" | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | <font metrics-file=" | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | <font metrics-file=" | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | ==== Spuštění ==== | ||
+ | |||
+ | < | ||
+ | shell# ./ | ||
+ | </ | ||
+ | |||
+ | === JAVA FOP class === | ||
+ | |||
+ | <file java FopGen.java> | ||
+ | package test; | ||
+ | |||
+ | import org.apache.log4j.Logger; | ||
+ | import java.io.File; | ||
+ | import java.io.OutputStream; | ||
+ | import javax.xml.transform.Transformer; | ||
+ | import javax.xml.transform.TransformerFactory; | ||
+ | import javax.xml.transform.Source; | ||
+ | import javax.xml.transform.Result; | ||
+ | import javax.xml.transform.stream.StreamSource; | ||
+ | import javax.xml.transform.sax.SAXResult; | ||
+ | import org.apache.fop.apps.FOUserAgent; | ||
+ | import org.apache.fop.apps.Fop; | ||
+ | import org.apache.fop.apps.FopFactory; | ||
+ | import org.apache.fop.apps.MimeConstants; | ||
+ | |||
+ | /** | ||
+ | * | ||
+ | * @author blazek | ||
+ | */ | ||
+ | public class FopGen { | ||
+ | |||
+ | static Logger logger = Logger.getLogger(FopGen.class); | ||
+ | private String xconf; | ||
+ | private String fontBase; | ||
+ | private String xmlInput; | ||
+ | private String xsltInput; | ||
+ | private String pdfOutput; | ||
+ | |||
+ | public FopGen() { | ||
+ | } | ||
+ | |||
+ | public FopGen(String xconf, String fontBase, String xmlInput, String xsltInput, String pdfOutput) { | ||
+ | this.xconf = xconf; | ||
+ | this.fontBase = fontBase; | ||
+ | this.xmlInput = xmlInput; | ||
+ | this.xsltInput = xsltInput; | ||
+ | this.pdfOutput = pdfOutput; | ||
+ | } | ||
+ | |||
+ | public String getXconf() { | ||
+ | return xconf; | ||
+ | } | ||
+ | |||
+ | public void setXconf(String xconf) { | ||
+ | this.xconf = xconf; | ||
+ | } | ||
+ | |||
+ | public String getFontBase() { | ||
+ | return fontBase; | ||
+ | } | ||
+ | |||
+ | public void setFontBase(String fontBase) { | ||
+ | this.fontBase = fontBase; | ||
+ | } | ||
+ | |||
+ | public String getXmlInput() { | ||
+ | return xmlInput; | ||
+ | } | ||
+ | |||
+ | public void setXmlInput(String xmlInput) { | ||
+ | this.xmlInput = xmlInput; | ||
+ | } | ||
+ | |||
+ | public String getXsltInput() { | ||
+ | return xsltInput; | ||
+ | } | ||
+ | |||
+ | public void setXsltInput(String xsltInput) { | ||
+ | this.xsltInput = xsltInput; | ||
+ | } | ||
+ | |||
+ | public String getPdfOutput() { | ||
+ | return pdfOutput; | ||
+ | } | ||
+ | |||
+ | public void setPdfOutput(String pdfOutput) { | ||
+ | this.pdfOutput = pdfOutput; | ||
+ | } | ||
+ | |||
+ | public boolean createPDF() { | ||
+ | |||
+ | try { | ||
+ | // configure fopFactory as desired | ||
+ | FopFactory fopFactory = FopFactory.newInstance(); | ||
+ | |||
+ | // configure fonts | ||
+ | fopFactory.setUserConfig(this.xconf); | ||
+ | fopFactory.getFontManager().setFontBaseURL(" | ||
+ | FOUserAgent foUserAgent = fopFactory.newFOUserAgent(); | ||
+ | |||
+ | // Setup output | ||
+ | OutputStream out = new java.io.FileOutputStream(new File(this.pdfOutput)); | ||
+ | out = new java.io.BufferedOutputStream(out); | ||
+ | |||
+ | try { | ||
+ | // Construct fop with desired output format | ||
+ | Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, | ||
+ | |||
+ | // Setup XSLT | ||
+ | TransformerFactory factory = TransformerFactory.newInstance(); | ||
+ | Transformer transformer = factory.newTransformer(new StreamSource(new File(this.xsltInput))); | ||
+ | |||
+ | // Setup input for XSLT transformation | ||
+ | Source src = new StreamSource(new File(this.xmlInput)); | ||
+ | |||
+ | // Resulting SAX events (the generated FO) must be piped through to FOP | ||
+ | Result res = new SAXResult(fop.getDefaultHandler()); | ||
+ | |||
+ | // Start XSLT transformation and FOP processing | ||
+ | transformer.transform(src, | ||
+ | } finally { | ||
+ | out.close(); | ||
+ | } | ||
+ | } catch (Exception e) { | ||
+ | e.printStackTrace(System.err); | ||
+ | System.exit(-1); | ||
+ | } | ||
+ | |||
+ | return true; | ||
+ | } | ||
+ | } | ||
+ | </ |