1

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.

Marcello B.
  • 4,177
  • 11
  • 45
  • 65
  • I posted this as a Q&A style question as I got stuck on this for a few hours, and was unable to find anything on how to do this. Once I realized that the return value of `pdf.Content()` was a byte array I was able to figure this out. – Marcello B. Jan 11 '19 at 21:06

1 Answers1

7

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);
         }
    }
}
Marcello B.
  • 4,177
  • 11
  • 45
  • 65