This is the last article for a while on using web.api from maShape. This one actually allows you to build a pdf. I have taken the sample and expanded it to send back the .pdf and prompt to view it or save it. I even give it a default name to save. As I stated in the last article you can download a blank base project from here.
I chose to show this example because it shows how to use vb.net and .asBinary from unirest. After seeing many examples in C# and not finding ONE example in vb.net I decided to create an example so that other can follow the idea.
Enjoy….
[code language=”vb”]
‘https://www.mashape.com/yogthos/instant-pdf#!documentation
Dim response2 As HttpResponse(Of Stream) = Unirest.post("https://yogthos.p.mashape.com/") _
.header("X-Mashape-Authorization", "EnterYourAPIKeyHere") _
.field("json-input", "[{}, [""paragraph"", ""some text""]]") _
.asBinary()
Dim Buffer(response2.Body.Length) As Byte
response2.Raw.Read(Buffer, 0, CInt(response2.Raw.Length))
Response.Clear()
Response.AddHeader("Content-Type", "pdf")
Response.AddHeader("Content-Disposition", "attachment; filename=MySampleReport.pdf; size=" & Buffer.Length.ToString())
Response.Flush()
Response.BinaryWrite(Buffer)
Context.Response.OutputStream.Write(Buffer, 0, Buffer.Length)
Response.Flush()
Response.End()
[/code]
Looking for quality web hosting? Look no further than Arvixe Web Hosting!