- 27.08.2008
- 8 002
- 610
и пагинация там есть и чего только нет, даже баркоды
чтобы далеко не ходить, примерчик из их библиотеки (он в архиве идет), вот два хмл отрывка, тестил в Эклипсе :
- кусок основного:
-параметром <import source="test/print/barcode-module.xml"/> он ссылается на шаблон:
и небольшой java код:
<pre><code class="]
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.ujac.print.DocumentHandlerException;
import org.ujac.print.DocumentPrinter;
import org.ujac.util.io.FileResourceLoader;
import lotus.domino.*;
public class UJACTest {
public static void main(String["> argv){
// defining the document properties, this map is used for dynamical content evaluation.
Map documentProperties = new HashMap();
String testName="barcode-test";
// instantiating the document printer
FileInputStream templateStream = null;
try {
templateStream = new FileInputStream("./xml/"+testName+".xml");
} catch (FileNotFoundException e) {
// TODO Автоматически созданный блок catch
e.printStackTrace();
}
DocumentPrinter documentPrinter = new DocumentPrinter(templateStream, documentProperties);
// in case you'd like to use a XML parser different from the default implementation
// you can specify it here (apache xerces in this case).
documentPrinter.setXmlReaderClass("com.sun.org.apache.xerces.internal.parsers.SAXParser");//"org.apache.xerces.parsers.SAXParser");
// defining the ResourceLoader: This is necessary if you like to
// dynamically load resources like images during template processing.
try {
documentPrinter.setResourceLoader(new FileResourceLoader("./"));
} catch (IOException e) {
// TODO Автоматически созданный блок catch
e.printStackTrace();
}
// generating the document output
FileOutputStream pdfStream = null;
try {
pdfStream = new FileOutputStream("./pdf/"+testName+".pdf");
} catch (FileNotFoundException e) {
// TODO Автоматически созданный блок catch
e.printStackTrace();
}
try {
documentPrinter.printDocument(pdfStream);
} catch (DocumentHandlerException e) {
// TODO Автоматически созданный блок catch
e.printStackTrace();
} catch (IOException e) {
// TODO Автоматически созданный блок catch
e.printStackTrace();
}
}
}</code></pre>
код отрезал движок :blink:
чтобы далеко не ходить, примерчик из их библиотеки (он в архиве идет), вот два хмл отрывка, тестил в Эклипсе :
- кусок основного:
Код:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE document
PUBLIC "-//UJAC.org//Print Document//EN"
"http://ujac.sourceforge.net/ujac-print-document.dtd">
<document size="A4" margin-left="25" margin-right="25" margin-top="25" margin-bottom="25">
<font-def name="title" family="Helvetica" style="bold" size="14"/>
<font-def name="section" family="Helvetica" style="bold" size="12"/>
<font-def name="normal" family="Helvetica" style="normal" size="10"/>
<font-def name="small" family="Helvetica" style="normal" size="9"/>
<header font="small">
<header-part halign="left"><image source="test/print/ujac-logo.jpg" height="8"/> barcode label test</header-part>
</header>
<footer font="small">
<footer-part padding-top="10" halign="center">Page ${pageNumber} of ${pageCount}</footer-part>
</footer>
<import source="test/print/barcode-module.xml"/>
<table columns="5" width="100" line-spacing="1.0">
<foreach loop-variable="row" sequence="1-13">
<foreach loop-variable="col" sequence="1-5">
<macro name="sticker">
<parameter name="text">Test ${row},${col}</parameter>
<parameter name="codetype">CODE39</parameter>
<parameter name="code">978020</parameter>
</macro>
</foreach>
</foreach>
</table>
</document>
-параметром <import source="test/print/barcode-module.xml"/> он ссылается на шаблон:
Код:
<?xml version="1.0" encoding="ISO-8859-1"?>
<module>
<macro-def name="sticker">
<parameter-def name="text"/>
<parameter-def name="codetype"/>
<parameter-def name="code"/>
<cell padding-top="5" padding-bottom="5" border-width="0.5" border-style="box">
<table columns="1" width="100">
<cell halign="center" border-style="none">
<barcode type="${codetype}" bar-height="10" generate-checksum="true">${code}</barcode>
</cell>
<cell halign="center" border-style="none">
${text}
</cell>
</table>
</cell>
</macro-def>
</module>
и небольшой java код:
<pre><code class="]
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.ujac.print.DocumentHandlerException;
import org.ujac.print.DocumentPrinter;
import org.ujac.util.io.FileResourceLoader;
import lotus.domino.*;
public class UJACTest {
public static void main(String["> argv){
// defining the document properties, this map is used for dynamical content evaluation.
Map documentProperties = new HashMap();
String testName="barcode-test";
// instantiating the document printer
FileInputStream templateStream = null;
try {
templateStream = new FileInputStream("./xml/"+testName+".xml");
} catch (FileNotFoundException e) {
// TODO Автоматически созданный блок catch
e.printStackTrace();
}
DocumentPrinter documentPrinter = new DocumentPrinter(templateStream, documentProperties);
// in case you'd like to use a XML parser different from the default implementation
// you can specify it here (apache xerces in this case).
documentPrinter.setXmlReaderClass("com.sun.org.apache.xerces.internal.parsers.SAXParser");//"org.apache.xerces.parsers.SAXParser");
// defining the ResourceLoader: This is necessary if you like to
// dynamically load resources like images during template processing.
try {
documentPrinter.setResourceLoader(new FileResourceLoader("./"));
} catch (IOException e) {
// TODO Автоматически созданный блок catch
e.printStackTrace();
}
// generating the document output
FileOutputStream pdfStream = null;
try {
pdfStream = new FileOutputStream("./pdf/"+testName+".pdf");
} catch (FileNotFoundException e) {
// TODO Автоматически созданный блок catch
e.printStackTrace();
}
try {
documentPrinter.printDocument(pdfStream);
} catch (DocumentHandlerException e) {
// TODO Автоматически созданный блок catch
e.printStackTrace();
} catch (IOException e) {
// TODO Автоматически созданный блок catch
e.printStackTrace();
}
}
}</code></pre>
код отрезал движок :blink:
Код:
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.ujac.print.DocumentHandlerException;
import org.ujac.print.DocumentPrinter;
import org.ujac.util.io.FileResourceLoader;
import lotus.domino.*;
public class UJACTest {
public static void main(String[] argv){