I was asked about the new way to work with NFOP to generate the pdf without
the old Engine class. So here is what I am doing:

1 #region Using
2
3 using System.Net;
4 using System.Reflection;
5 using System.Xml;
6 using System.Xml.Xsl;
7 using java.io;
8 using log4net;
9 using org.apache.fop.apps;
10 using org.xml.sax;
11 using TechHeadBrothers.Portal.UI;
12 using StringWriter = System.IO.StringWriter;
13
14 #endregion
15
16 namespace TechHeadBrothers.TechHeadBrothers.Portal.UI
17 {
18 ///


19 /// Strategy to print PDF using FOP
20 ///

21 public class FOPPrintStrategy : PrintStrategy
22 {
23 #region Logging Definition
24
25 private static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
26
27 #endregion
28
29 protected override void Print(PrintArticle page, string xmlpath, string xslpah, XsltArgumentList xsltargs)
30 {
31 string fullFoDoc = XmlContentToFoContent(page, xmlpath, xslpah);
32
33 InputSource source = new InputSource(fullFoDoc);
34 ByteArrayOutputStream output = new ByteArrayOutputStream();
35
36 try
37 {
38 Driver driver = new Driver(source, output);
39 driver.setRenderer(Driver.RENDER_PDF);
40 driver.run();
41 output.close();
42
43 int sz = output.buf.Length;
44 byte[] pdf = new byte[sz];
45 for (int i = 0; i < sz; i++)
46 pdf[i] = (byte) output.buf[i];
47
48 page.Response.ClearHeaders();
49 page.Response.Clear();
50
51 page.Response.AddHeader(“Content-Disposition”, “attachment; filename=TechHeadBrothers.pdf”);
52 page.Response.ContentType = “application/octet-stream”;
53
54 page.Response.Flush();
55 page.Response.BinaryWrite(pdf);
56 page.Response.End();
57 }
58 catch (FOPException fope)
59 {
60 if (log.IsDebugEnabled)
61 log.Debug(fope.getMessage());
62 }
63 }
64 }