Esempio n. 1
0
        /// <summary>
        /// Convert provided file content to PDF.
        /// Specify extension of the file.
        /// </summary>
        /// <param name="content">file content</param>
        /// <param name="ext">file extension</param>
        /// <returns>PDF converted file</returns>
        public static byte[] Convert(byte[] content, string ext)
        {
            var from = TemporaryResources.CreateFile(ext);
            var to   = from + ".pdf";

            File.WriteAllBytes(from, content);
            RunConverter(from);
            var result = File.ReadAllBytes(to);

            File.Delete(from);
            File.Delete(to);
            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Convert provided stream content to PDF.
        /// Specify extension of the file
        /// </summary>
        /// <param name="content">file content</param>
        /// <param name="ext">file extension</param>
        /// <param name="disposeStream">dispose provided stream after conversion</param>
        /// <returns>PDF converted stream</returns>
        public static Stream Convert(Stream content, string ext, bool disposeStream)
        {
            var from = TemporaryResources.CreateFile(ext);
            var to   = from + ".pdf";
            var fs   = new FileStream(from, FileMode.Create, FileAccess.Write);

            content.CopyTo(fs);
            fs.Close();
            if (disposeStream)
            {
                content.Dispose();
            }
            RunConverter(from);
            var cms = ChunkedMemoryStream.Create();

            using (var f = new FileStream(to, FileMode.Open, FileAccess.Read))
            {
                f.CopyTo(cms);
            }
            File.Delete(from);
            File.Delete(to);
            cms.Position = 0;
            return(cms);
        }