Jag försöker skriva ut en sida i pdf till klienten. Jag använder nFop och har installerat J# Redistributable Package samt kopierat in filen ApacheFop.net.dll jag har också lagt till en referens till filen vjslib.dll. Problemet är att när jag testar min applikation så får jag följande felmeddelande. De vill att jag ska lösa det med nfop tyvärr. jag postar koden om det är någon som ser nåt fel i den.PDF problem
<b>
Exception Details: java.util.MissingResourceException: Resource Bundle not Found
Source Error:
Line 152: driver.setRenderer(Driver.RENDER_PDF);
Line 153:
Line 154: driver.run();
</b>
Skickar inte med all kod om någon vet vad som är fel utan, det är mycket kod. Det verkar ju som om någonting fattas på nåt sätt. Jag har även importerat följande namnområde:
using org.apache.fop;
using org.apache.fop.apps;
using org.apache.fop.tools;
using org.xml.sax;
using java.io;
Sv:PDF problem
<code>
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.Xsl;
// Have to import theses namespaces...
using org.apache.fop;
using org.apache.fop.apps;
using org.apache.fop.tools;
using org.xml.sax;
using java.io;
public partial class showPdf : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// If you have choosed one person...
if (Request.QueryString["id"] != null)
{
// We will load "onePdf.xsl" in this case...
string xslPath = Server.MapPath("~/xml/onePdf.xsl");
string xmlPath = Server.MapPath("~/xml/person.xml"); // The xml file...
// Gets the id from the querystring...
int myId = int.Parse(Request.QueryString["id"]);
// Create an object of the class...
XslCompiledTransform xslt = new XslCompiledTransform();
// Loads the xsl file...
xslt.Load(xslPath);
// Creates a object of the class...
XsltArgumentList xslArg = new XsltArgumentList();
// Sends the argument list...
xslArg.AddParam("id", "", myId);
// Create a memory stream...
MemoryStream ms = new MemoryStream();
// Send it to the processor...
xslt.Transform(xmlPath, xslArg, ms);
// Stores the length of the memory stream in a variable...
long size = ms.Length;
// Creates a new byte with the same size...
byte[] bytes = new byte[size];
// Creates a new sbyte with the same size as the size...
sbyte[] sbytes = new sbyte[size];
// Stores the value of the memory stream in bytes...
bytes = ms.ToArray();
// A loop that casts and stores all values in the array...
for (int i = 0; i < size; i++)
{
sbytes[i] = (sbyte)bytes[i];
}
// Creates a byte array input stream...
ByteArrayInputStream source = new ByteArrayInputStream(sbytes);
// Sends it as input source...
InputSource input = new InputSource(source);
// Creates an output...
ByteArrayOutputStream output = new ByteArrayOutputStream();
try
{
// Sends input and output to the nfop driver...
Driver driver = new Driver(input, output);
// Tells the driver that we will have it as PDF...
driver.setRenderer(Driver.RENDER_PDF);
// Execute the driver...
driver.run();
// Close the output stream...
output.close();
// Stores the output in byte and rend it as PDF...
int sz = output.buf.Length;
byte[] pdf = new byte[sz];
for (int i = 0; i < sz; i++)
pdf[i] = (byte)output.buf[i];
// Clean up...
Response.ClearHeaders();
Response.Clear();
// Mime-typ...
Response.ContentType = "application/pdf";
// Writes the PFD file to the client...
Response.Flush();
Response.BinaryWrite(pdf);
Response.End();
}
catch (FOPException fope) // Errors ends up here...
{
Response.Write("Det uppstod ett fel: <br />" + fope.Message.ToString());
}
}
else
{
// This is the same as we did above, but without the id parameter...
string xslPath = Server.MapPath("~/xml/allPdf.xsl");
string xmlPath = Server.MapPath("~/xml/person.xml");
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load(xslPath);
MemoryStream ms = new MemoryStream();
xslt.Transform(xmlPath, null, ms);
long size = ms.Length;
byte[] bytes = new byte[size];
sbyte[] sbytes = new sbyte[size];
bytes = ms.ToArray();
for (int i = 0; i < size; i++)
{
sbytes[i] = (sbyte)bytes[i];
}
ByteArrayInputStream input = new ByteArrayInputStream(sbytes);
InputSource source = new InputSource(input);
ByteArrayOutputStream output = new ByteArrayOutputStream();
try
{
Driver driver = new Driver(source, output);
driver.setRenderer(Driver.RENDER_PDF);
driver.run();
output.close();
int sz = output.buf.Length;
byte[] pdf = new byte[sz];
for (int i = 0; i < sz; i++)
pdf[i] = (byte)output.buf[i];
Response.ClearHeaders();
Response.Clear();
Response.ContentType = "application/pdf";
Response.Flush();
Response.BinaryWrite(pdf);
Response.End();
}
catch (FOPException fope)
{
Response.Write("Det uppstod ett fel:<br />" + fope.Message.ToString());
}
}
}
}
</code>