public static XslFORenderFileOutput RenderXslFOToPdfFile(this XDocument xXslFODoc, FileInfo pdfOutputFileInfo, XslFORenderOptions options) { try { //NOTE: MUST pass the FileStream with READ & WRITE access so that it can be validated after Rendering! using (FileStream fileStream = pdfOutputFileInfo.Open(FileMode.Create, FileAccess.ReadWrite, FileShare.None)) { //var xmlNotifyReader = XmlNotificationReader.Create(xXslFODoc.CreateReader()); //xmlNotifyReader.AddNotification(XName.Get("ReportProgress", XsltSystemCustomExtensionObject.XmlnsUrn), (xEl) => //{ // var text = xEl.GetInnerText(); // Debug.WriteLine(text); // return xEl; //}); XslFOFonetHelper.Render(xXslFODoc, fileStream, options); } //NOTE: The stream will be managed because the XslFORenderStreamOutput wraps it and correctly supports IDisposable interface. return(new XslFORenderFileOutput(xXslFODoc, pdfOutputFileInfo)); } catch (Exception exc) { throw new XslFORenderException("Error occurred while rendering the XslFO into Pdf File output.", exc, xXslFODoc.ToString()); } }
public static XslFORenderStreamOutput RenderXslFOToPdf(this XDocument xXslFODoc, XslFORenderOptions options) { try { //NOTE: We do NOT wrap the memory stream in a using{} block or dispose of it because it must // be returned to the caller who will manage its life/scope MemoryStream memoryStream = new MemoryStream(); XslFOFonetHelper.Render(xXslFODoc, memoryStream, options); //NOTE: The stream will be managed because the XslFORenderStreamOutput wraps it and correctly supports IDisposable interface. return(new XslFORenderStreamOutput(xXslFODoc, memoryStream)); } catch (Exception exc) { throw new XslFORenderException("Error occurred while rendering the XslFO into Pdf File output.", exc, xXslFODoc.ToString()); } }