forked from Coded/SIPRP
git-svn-id: https://svn.coded.pt/svn/SIPRP@834 bb69d46d-e84e-40c8-a05a-06db0d633741
parent
9a083d11bc
commit
6def0acfc5
@ -0,0 +1,55 @@
|
||||
package siprp.planoactuacao.print;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
import com.evolute.utils.fop.PDFCreator;
|
||||
import com.evolute.utils.xml.XSLTransformer;
|
||||
|
||||
public class TestPrint
|
||||
{
|
||||
public static void main( String args[] )
|
||||
throws Exception
|
||||
{
|
||||
new TestPrint().test();
|
||||
}
|
||||
|
||||
public void test()
|
||||
throws Exception
|
||||
{
|
||||
byte fo[] = applyTemplate(
|
||||
"siprp/planoactuacao/print/plano_actuacao.xsl",
|
||||
// getClass().getClassLoader().getResourceAsStream( "siprp/planoactuacao/plano_actuacao.xsl" ),
|
||||
"siprp/planoactuacao/print/teste_input.xml" );
|
||||
// new ByteArrayInputStream( "<?xml version=\"1.0\" encoding=\"UTF-8\"?><plano></plano>".getBytes() ) );
|
||||
createPDFFile( fo, "/home/fpalma/Desktop/out.pdf" );
|
||||
// createPDFFile( fo, "c:/Documents and Settings/Frederico/Ambiente de Trabalho/out.pdf" );
|
||||
}
|
||||
|
||||
public void createPDFFile( byte fo[], String path )
|
||||
throws Exception
|
||||
{
|
||||
byte pdf[] = PDFCreator.getPDFCreator().createPdfFromFo( fo );
|
||||
FileOutputStream fos = new FileOutputStream( path );
|
||||
fos.write( pdf );
|
||||
fos.close();
|
||||
}
|
||||
|
||||
public byte[] applyTemplate( String template, String data )
|
||||
throws Exception
|
||||
{
|
||||
InputStream xsl = getClass().getClassLoader().getResourceAsStream( template );
|
||||
InputStream xml = getClass().getClassLoader().getResourceAsStream( data );
|
||||
return( applyTemplate( xsl, xml ) );
|
||||
}
|
||||
|
||||
public byte[] applyTemplate( InputStream xsl, InputStream dataStream )
|
||||
throws Exception
|
||||
{
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
XSLTransformer.getXSLTransformer().transform( dataStream, xsl, baos );
|
||||
return baos.toByteArray();
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue