简体   繁体   中英

Save OpenHTMLtoPDF Content to PDF file

I have this PDF file that I have generated with OpenHTMLtoPDF .

string html = "<html><body><h1>TEST</h1></body></html>";
var pdf = Pdf.From(html).OfSize(size);
byte[] content = pdf.Content();

However, I cannot figure out how to save it to the disk. There appears to not be a method to save to the hard drive.

It is very easy since pdf.content() is passing you an array of bytes you can simply call File.WriteAllBytes() to save the file to the hard drive.

using OpenHtmlToPdf;
using System.IO;
namespace Test{
    class TestOpenHTMLtoPDF{
         private void Main(){
             string html = "<html><body><h1>TEST</h1></body></html>";
             var pdf = Pdf.From(html).OfSize(size);
             byte[] content = pdf.Content();
             File.WriteAllBytes(@"C:\Test.pdf", content);
         }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM