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.
The first package management system I learned to use was Bower. It was great for the short love affair we had together, but it stopped being supported and I was weary of learning to use one of its replacements. Fortunately, I haven’t had to with Libman. Libman’s (Library Manager) simple JSON approach to bringing front end dependencies has been the easiest for me quickly implement and it has been a great addition to Visual Studio. I implemented it possibly too quickly, however, and overlooked one powerful configuration setting: provider.…
I had a recent bug that took me much too long to solve and the root of the cause was me. I got a bit too delete happy and deleted a crucial file that allows me to use Razor Tag Helpers to bring a List into a View as a Drop Down (Select).
Here’s how the error presented itself:
- SelectList won’t populate
- Select or DropDown is empty
- value = Microsoft.AspNetCore.Mvc.Rendering.SelectList or
- System.Linq.OrderedEnumerable2 [Microsoft.AspNetCore.Mvc.Rendering.SelectListItem, System.String]
I am a full stack developer. I develop in Visual Studio, code in C# with .NET Core, deploy to Azure and I must admit, I’m a front-end cheater.
Comeon, the .NET Core Web App demo itself loads with Bootstrap and JQuery preinstalled. We’re all cheaters at some point, but I’m trying to diversify my cheating and eliminate my dependencies.
Here’s my latest strategy.…
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.…
TLDR: post IS successful. PayTrace, by design, returns a 400 error, which sets off exceptions in httpresponse. Solution: catch the exception and then continue deserializing your response.
I coded a few weeks ago a .NET post to the PayTrace API which helps me demo and test payment by credit card using client side encryption. The process more or less went like this:
- Create demo account as a merchant on Paytrace
- Download PEM key
- On submit of form with credit card information, an imported PayTraceJS library encrypts the card number and csc code
- Use the demo account’s username and password to submit a request for a token
- Submit transaction (which includes encrypted info as well as other required fields) using token and await response
A successful http response returns a status code of 200. I read it via stream, deserialize it using json into my CardResponse object (both successful and failure responses have the same design). Everything went great until I began testing rejected cards.…