private string _bookname; private short _pagecount; private string[] _chaptername; private string _isbn; private string[][] _content; private string _summary; private string _publishingname; private string _writer; private DateTime _date; public string BooKName { get { return _bookname; } set { _bookname = value; } } public string Writer { get { return _writer; } set { _writer = value; } } public short PageCount { get { return _pagecount; } set { _pagecount = value; } }
public string[] ChapterName { get { return _chaptername; } set { _chaptername = value; } } public string ISBN { get { return _isbn; } set { _isbn = value; } } public string[][] Content { get { return _content; } set { _content = value; } } public string Summary { get { return _summary; } set { _summary = value; } } public string PublishingName { get { return _publishingname; } set { _publishingname = value; } } public DateTime Date { get { return _date; } set { _date = value; } }
public PDFBook() {
} }
public static void Main() { Document co = new Document(); PDFBook pdfbook = new PDFBook(); pdfbook.BooKName = "新的一天"; pdfbook.ChapterName = new string[5]; pdfbook.ChapterName[0] = "第一天"; pdfbook.ChapterName[1] = "第二天"; pdfbook.ChapterName[2] = "第三天"; pdfbook.ChapterName[3] = "第四天"; pdfbook.ChapterName[4] = "第五天"; pdfbook.PageCount = 554; pdfbook.Writer = "ZTX"; pdfbook.PageCount = 5; pdfbook.Content = new string[5][]; pdfbook.Content[0] = new string[2]; pdfbook.Content[1] = new string[2]; pdfbook.Content[2] = new string[3]; pdfbook.Content[3] = new string[4]; pdfbook.Content[4] = new string[5]; pdfbook.Summary = "我也写了一本书"; pdfbook.ISBN = "000000001"; pdfbook.Date = DateTime.Now; //如何把这个对象传送给另外一个方法,另外一个方法就是接受对象生成pdf文件!! 怎么弄? }
pdfbook.PageCount = 554;应该是16
public static void CreatePDFFile(PDFBook book, string strPass) {
//************************************** // 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(); } } }
using org.apache.fop; using org.apache.fop.apps; using org.apache.fop.tools; using org.xml.sax; using java.io;........................ ..........................java.io都来了..............
写好的pdf流
还是只是数据的?
如果是只是数据的话你看看rdl这个东西
网上有源代码
如果是合并的话
我到是有代码
我到是有代码代码我看看!
[email protected]
public class PDFBook
{
private string _bookname;
private short _pagecount;
private string[] _chaptername;
private string _isbn;
private string[][] _content;
private string _summary;
private string _publishingname;
private string _writer;
private DateTime _date;
public string BooKName
{
get { return _bookname; }
set { _bookname = value; }
}
public string Writer
{
get { return _writer; }
set { _writer = value; }
} public short PageCount
{
get { return _pagecount; }
set { _pagecount = value; }
}
public string[] ChapterName
{
get { return _chaptername; }
set { _chaptername = value; }
}
public string ISBN
{
get { return _isbn; }
set { _isbn = value; }
}
public string[][] Content
{
get { return _content; }
set { _content = value; }
} public string Summary
{
get { return _summary; }
set { _summary = value; }
}
public string PublishingName
{
get { return _publishingname; }
set { _publishingname = value; }
} public DateTime Date
{
get { return _date; }
set { _date = value; } }
public PDFBook()
{
}
}
{
Document co = new Document();
PDFBook pdfbook = new PDFBook();
pdfbook.BooKName = "新的一天";
pdfbook.ChapterName = new string[5];
pdfbook.ChapterName[0] = "第一天";
pdfbook.ChapterName[1] = "第二天";
pdfbook.ChapterName[2] = "第三天";
pdfbook.ChapterName[3] = "第四天";
pdfbook.ChapterName[4] = "第五天";
pdfbook.PageCount = 554;
pdfbook.Writer = "ZTX";
pdfbook.PageCount = 5;
pdfbook.Content = new string[5][];
pdfbook.Content[0] = new string[2];
pdfbook.Content[1] = new string[2];
pdfbook.Content[2] = new string[3];
pdfbook.Content[3] = new string[4];
pdfbook.Content[4] = new string[5];
pdfbook.Summary = "我也写了一本书";
pdfbook.ISBN = "000000001";
pdfbook.Date = DateTime.Now;
//如何把这个对象传送给另外一个方法,另外一个方法就是接受对象生成pdf文件!!
怎么弄? }
{
}
// 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();
}
}
}
using org.apache.fop.apps;
using org.apache.fop.tools;
using org.xml.sax;
using java.io;........................
..........................java.io都来了..............
??
J# ?