Create a PDF Using a Web API and Mashape

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.
figure1

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….

    '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()

Looking for quality web hosting? Look no further than Arvixe Web Hosting!

Tags: , , , , , , , , , , , | Posted under Programming/Coding | RSS 2.0

Author Spotlight

David Bauernschmidt

David Bauernschmidt

I live in the historical triangle of Virginia where I am married with two daughters. I have spent over 13 years working for a Fortune 500 company in the computer area. I started in VB 6.0 and by the time I ended my employment I was supervising a development team where we built many web applications. When my first daughter was born I wanted to spend more time with her so I left and became a programmer analyst for local government as well as launch my own company. Since then I have grown James River Webs into a profitable web design and application company helping small businesses create a big presence on the internet. As an employee I have created web application used by citizens and other companies. I enjoy fly fishing, and spending time with my family. I also enjoy learning new approaches and development tools when it comes to developing applications.

Leave a Reply

Your email address will not be published. Required fields are marked *


2 × = 2

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>