The API mentioned in my first tutorial got taken down and so I had to do some updates. First, choose another 3rd party API. I currently am trying out HTML 2 PDF Rocket and modified my code a bit:
public async Task<FileStreamResult> PrintAsync(int id)
InvoiceVM invoiceVM = new InvoiceVM();
invoiceVM = invoiceRepository.Get(id);
var engine = new RazorLightEngineBuilder()
.UseFilesystemProject(_hostingEnvironment.WebRootPath + "\\pdf\\")
var view = await engine.CompileRenderAsync("PDF.cshtml", invoiceVM);
string apiKey = "xxxxxxxxxxxxxxxxxxxx";
using (var client = new WebClient())
// Build the conversion options
NameValueCollection options = new NameValueCollection();
MemoryStream ms = new MemoryStream(client.UploadValues("http://api.html2pdfrocket.com/pdf", options));
return new FileStreamResult(ms, "application/pdf");
This is based directly off the HTML 2 Rocket documentation. For the rest of the code see the first tutorial.
I recently had an issue with printing a report to PDF using Microsoft Reporting Service and a RDLC file, etc. Something similar to this. Unfortunately, it worked great in development, but refused to work once deployed into Azure. No matter what I did, I could not duck the GDI errors I kept getting, and apparently this continues through a line of various PDF exporting extensions, all of which rely on GDI for export. Turns out, I’m not alone in facing this problem and so, I decided to find a solution.
My general idea was to use something to render my PDF view, send that view as one long html string to a free PDF microservice and get the PDF in return.
Today’s problem dealt with how we view our invoices online. We use an app on the iSeries that creates a PDF and delivers it to a set destination. That destination, in our case is a regular windows server, the files landing in a small site: pdf.mycompany.com.
My initial approach was simple, use the PHP API I have sitting on the iSeries to make a call to the program – passing it the parameters for that specific invoice, await response (which gave me the new created filename) and then redirect to that URL. The method looks something like this:
public async Task<ActionResult> GetInvoiceAsync(int invoice)
GetInvoice getInvoice = new GetInvoice();
var client = new HttpClient();
string fileName = await getInvoice.LoadPDF(invoice);
string url = "http://pdf.mycompany.com/";
url += fileName + ".pdf";
This worked great… 90% of the time, but the other 10% of the time, I clicked too quickly on an invoice and got forwarded to a 404.