/// <summary> /// Implements IComponent.Execute method. /// </summary> /// <param name="pc">Pipeline context</param> /// <param name="inmsg">Input message.</param> /// <returns>Processed input message with appended or prepended data.</returns> /// <remarks> /// Converts xsl-fo transformed messages to pdf /// </remarks> public IBaseMessage Execute(IPipelineContext pc, IBaseMessage inmsg) { IBaseMessagePart bodyPart = inmsg.BodyPart; if (bodyPart.Data != null) { VirtualStream vtstm = new VirtualStream(VirtualStream.MemoryFlag.AutoOverFlowToDisk); FonetDriver driver = FonetDriver.Make(); driver.CloseOnExit = false;//important for biztalk to work ... set position = 0 PdfRendererOptions options = new PdfRendererOptions(); options.Title = Title; options.Subject = Subject; options.UserPassword = Password; driver.Options = options; Stream stm = bodyPart.GetOriginalDataStream(); stm.Seek(0, SeekOrigin.Begin); driver.Render(stm, vtstm); vtstm.Seek(0, SeekOrigin.Begin); bodyPart.Data = vtstm; } return(inmsg); }
private void convertXmlToPDF(string xmlFilename, bool preview = true) { string filename = Path.ChangeExtension(xmlFilename, ".pdf"); var options = new PdfRendererOptions(); options.Author = Application.ProductName + " " + Application.ProductVersion; options.EnableModify = false; options.EnableAdd = false; options.EnableCopy = false; options.EnablePrinting = true; FonetDriver driver = FonetDriver.Make(); driver.Options = options; try { string s = doOpenDocument(xmlFilename, true); using (StringReader sr = new StringReader(s)) { using (FileStream fs = File.Create(filename)) { driver.Render(sr, fs); } } if (preview) { Process.Start(filename); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Errore", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Returns the PDF renderer options configured according to command line options. /// </summary> /// <returns>PDF render options configured according to command line options.</returns> private PdfRendererOptions GetPdfRendererOptions() { PdfRendererOptions options = new PdfRendererOptions(); // Enable/disable evil kerning options.Kerning = this.kerningOption.IsProvided; // Enum.Parse() will throw an exception if the fontTypeOption argument // does not represent one of the pre-defined FontType members if (this.fontTypeOption.IsProvided) { try { options.FontType = (FontType)Enum.Parse( typeof(FontType), this.fontTypeOption.Argument, true); } catch (Exception) { Console.WriteLine( "[WARN] Unrecognised -fonttype argument: '{0}' - defaulting to 'Link'", this.fontTypeOption.Argument); } } return(options); }
public void Dispose() { this.imageHandler = null; this.credentials = null; this.baseDirectory = null; this.renderOptions = null; this.OnError = null; this.OnInfo = null; this.OnWarning = null; }
public void SetOptions(PdfRendererOptions options) { // Configure the /Info dictionary. info = new PdfInfo(doc.NextObjectId()); if (options.Title != null) { info.Title = new PdfString(options.Title); } if (options.Author != null) { info.Author = new PdfString(options.Author); } if (options.Subject != null) { info.Subject = new PdfString(options.Subject); } if (options.Keywords != String.Empty) { info.Keywords = new PdfString(options.Keywords); } if (options.Creator != null) { info.Creator = new PdfString(options.Creator); } if (options.Producer != null) { info.Producer = new PdfString(options.Producer); } info.CreationDate = new PdfString(PdfDate.Format(DateTime.Now)); this.objects.Add(info); // Configure the security options. if (options.UserPassword != null || options.OwnerPassword != null || options.HasPermissions) { SecurityOptions securityOptions = new SecurityOptions(); securityOptions.UserPassword = options.UserPassword; securityOptions.OwnerPassword = options.OwnerPassword; securityOptions.EnableAdding(options.EnableAdd); securityOptions.EnableChanging(options.EnableModify); securityOptions.EnableCopying(options.EnableCopy); securityOptions.EnablePrinting(options.EnablePrinting); doc.SecurityOptions = securityOptions; encrypt = doc.Writer.SecurityManager.GetEncrypt(doc.NextObjectId()); this.objects.Add(encrypt); } }
private static byte[] RenderFo2Pdf(string xmlFo) { var foReader = new XmlTextReader(new StringReader(xmlFo)); var options = new PdfRendererOptions(); FonetDriver driver = FonetDriver.Make(); driver.OnError += HandleError; using (var stream = new MemoryStream()) { driver.Options = options; driver.Render(foReader, stream); return(stream.ToArray()); } }
public void generar_pdf(XmlDocument fo, string rutaPDF) { FonetDriver driver = FonetDriver.Make(); var options = new PdfRendererOptions(); var font = new System.IO.FileInfo(@"c:/xml/arial.ttf"); options.AddPrivateFont(font); options.FontType = FontType.Subset; driver.Options = options; ///poner ruta pdf 417 que el nombre tiene que ser igual al tiempo de firma ej 2016-12-13T192207 FileStream pdf_stream = null; pdf_stream = new FileStream(rutaPDF, FileMode.Create); driver.Render(fo, pdf_stream); //System.Diagnostics.Process.Start("c:/xml/hello.pdf"); }
public void MakePdf(string rutaPDF) { FonetDriver driver = FonetDriver.Make(); var options = new PdfRendererOptions(); var font = new System.IO.FileInfo(@"C:\Windows\Fonts\arial.ttf"); options.AddPrivateFont(font); options.FontType = FontType.Subset; driver.Options = options; FileStream PdfStream = null; PdfStream = new FileStream(rutaPDF, FileMode.Create); driver.Render(DTE, PdfStream); }
/// <summary> /// Creates a PDF from an XSLFO representation of a report /// </summary> /// <param name="reportXslFo">String containing the XSLFO representation of the report</param> /// <param name="pdfFilePath">The full path to the output PDF file (existing file will be overwritten)</param> /// <returns>True if the PDF document was created successfully, otherwise false</returns> private static bool CreatePdfFromXslFo(string reportXslFo, string pdfFilePath) { // Validate the arguments if (string.IsNullOrWhiteSpace(reportXslFo)) { throw new ArgumentException($"{nameof(reportXslFo)} must not be null or empty."); } if (string.IsNullOrWhiteSpace(pdfFilePath)) { throw new ArgumentException($"{nameof(pdfFilePath)} must not be null or empty."); } // Load the report XSLFO document into an XML document XmlDocument xslfoDocument = new XmlDocument(); xslfoDocument.LoadXml(reportXslFo); // Create a stream to write the PDF file into using (Stream pdfStream = new FileStream(pdfFilePath, FileMode.Create, FileAccess.Write)) { // Set up the Fonet driver FonetDriver driver = FonetDriver.Make(); // Configure the font options PdfRendererOptions options = new PdfRendererOptions(); options.FontType = FontType.Link; // TODO or FontType.Embed or FontType.Subset // options.AddPrivateFont(new FileInfo(@"\\server\fonts\rmgfont.otf")); driver.Options = options; // Create the PDF from the XSL-FO document driver.Render(xslfoDocument, pdfStream); } // Determine whether the PDF creation was successful bool success = File.Exists(pdfFilePath); return(success); }
static void xslfoTest() { string root = @"C:\Users\Fernando.pires\Documents\Visual Studio 2015\Projects\PdfWriter\Files\Out\"; if (File.Exists(root + "hello.pdf")) { File.Delete(root + "hello.pdf"); } FileStream inStm = new FileStream(root + "{6F233C6B-3174-47FC-8A01-80A18DEBAD94}.xml", FileMode.Open); FileStream stm = new FileStream(root + "hello.pdf", FileMode.Create); FonetDriver driver = FonetDriver.Make(); //driver.CloseOnExit = false;//important for biztalk to work ... set position = 0 PdfRendererOptions options = new PdfRendererOptions(); driver.Render(inStm, stm); Console.ReadKey(); }