使用Apache NFOP创建pdf
来源:互联网 发布:淘宝买手机需要加微信 编辑:程序博客网 时间:2024/06/08 19:46
//**************************************
// Name: Create in memory PDF documents in ASP.NET using Apache NFOP
// Description:The sample demonstrates how to create PDF documents in memory using the open source Apache NFOP(http://sourceforge.net/projects/nfop/) and stream the same to browser instead of saving the PDF documents to harddrive.
// By: Azeet Chebrolu
//
//
// Inputs:Path to your XML Data File and Path to the XSLT Transformation file.
//
// Returns:None
//
//Assumes:Add reference to ApacheFop.Net.dll and vJsLib.dll which comes with Visual J#.net
//
//Side Effects:None
//**************************************
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Xml;
using System.Xml.Xsl;
using System.Xml.XPath;
using org.apache.fop;
using org.apache.fop.apps;
using org.apache.fop.tools;
using org.xml.sax;
using java.io;
using System.Text;
public partial class output : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e){}
protected void Button1_Click(object sender, EventArgs e)
{
StreamPDF(Server.MapPath("CP0000001.xml"), Server.MapPath("pdf.xslt"));
}
private static void StreamPDF(string XMLFile,string XSLTFile)
{
// Load the style sheet.
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load(XMLFile);
XmlDocument objSourceData = new XmlDocument();
//Load the Source XML Document
objSourceData.Load(XSLTFile);
// Execute the transform and output the results to a file.
MemoryStream ms = new MemoryStream();
xslt.Transform(objSourceData, null, ms);
//Convert the Byte Array from MemoryStream to SByte Array
sbyte[] inputFOBytes = ToSByteArray(ms.ToArray());
InputSource inputFoFile = new org.xml.sax.InputSource(new ByteArrayInputStream(inputFOBytes));
ByteArrayOutputStream bos = new java.io.ByteArrayOutputStream();
org.apache.fop.apps.Driver dr = new org.apache.fop.apps.Driver(inputFoFile, bos);
dr.setRenderer(org.apache.fop.apps.Driver.RENDER_PDF);
dr.run();
//Convert the SByte Array to Byte Array to stream to the Browser
byte[] getBytes = ToByteArray(bos.toByteArray());
MemoryStream msPdf = new MemoryStream(getBytes);
Response.ContentType = "application/pdf";
Response.AddHeader("Content-disposition", "filename=output.pdf");
Response.OutputStream.Write(getBytes, 0, getBytes.Length);
Response.OutputStream.Flush();
Response.OutputStream.Close();
}
private static SByte[] ToSByteArray(Byte[] source)
{
sbyte[] sbytes = new sbyte[source.Length];
System.Buffer.BlockCopy(source, 0, sbytes, 0, source.Length);
return sbytes;
}
private static Byte[] ToByteArray(SByte[] source)
{
byte[] bytes = new byte[source.Length];
System.Buffer.BlockCopy(source, 0, bytes, 0, source.Length);
return bytes;
}
public static string GetStringFromStream(Stream stream)
{
// Create a stream reader.
stream.Seek(0, SeekOrigin.Begin);
using (StreamReader reader = new StreamReader(stream))
{
// Just read to the end.
return reader.ReadToEnd();
}
}
}
- 使用Apache NFOP创建pdf
- 使用C#创建PDF文档
- 使用iText创建PDF文件
- 2015.3.23 使用python创建pdf文件
- 使用iText库创建PDF文件
- 使用Apache XML项目FOP生成PDF文件(上)
- 使用Apache XML项目FOP生成PDF文件(下)
- 使用Apache FOP将XML导出成PDF
- 使用Apache PDFBox转换PDF文件为Text文件
- 使用Apache FOP将XML导出成PDF
- 使用Apache CXF创建Web Service
- 使用Apache CXF创建简单Web Service
- Apache数组创建、使用的过程分析
- 使用wamp中的Apache创建虚拟主机
- 使用xetex直接由围棋棋谱文件创建pdf书籍
- 独家:使用iText JAR在Java中创建PDF
- 使用iText创建PDF文档,代码整理自iText官网
- Itext 使用入门 之 创建pdf 文档 附中文解决方案
- 位置服务的发展趋势(整理)
- java.lang.Exception: Exception in sending Request :: null (oracle 10g)
- 为什么IX主机访问不了?
- sqlldr 导数的一点总结
- 利用Windows外壳扩展保护文件夹
- 使用Apache NFOP创建pdf
- 强大的百度啊,这都可以,真是佩服啊。
- Linux守护进程的编程规则
- web.config中authorization下的location中的path的设置
- 水ME811发彩信
- Delphi Window 消息大全使用详解
- Oraclee 事务处理以及在c#中使用oracle的事务处理
- 关于yii 数据库添加新字段之后model类的修改
- 学习4(优化)