0

I built a web application using ITextSharp to convert HTML into a PDF that is saved by the user. This works fine. Now though I am being tasked with creating a process to save the PDF to a share on a schedule. Since the entire PDF creation however is based on HTML I'm struggling on a way to do this with the removal of the front end.

Its hard to show code for this, so I hope I am getting the concept across well enough.

I tried creating a web service that I could trigger that would render the HTML and create the PDF and drop it, however I can't seem to find a way to make a webservice actually render a page. I'm not sure if thats even possible.

I basically want to see if anyone has any ideas before I go through the painful route of redoing the PDF design generation without using HTML.

Finuve
  • 73
  • 7

3 Answers3

1

There are many ways you can don this, here are a couple of suggestions of would I approach this problem:

-Recycle the code to a console app and run the code using a scheduled task. -Run a scheduled task that will execute a web service within your web app.

MAlvarez
  • 86
  • 5
  • 2
    Normally I'd say it would be nicer if you posted some code but since the OP didn't either I think it is okay! I completely agree with this! The way I've done this in the past is to make a single page on my site (page, not web service, no need for unnecessary complications), then download `wget` or `curl`, wrote a very simple batch file to hit that page and finally wrap that up in a scheduled task. These days you could probably PowerShell it, too, and skip `wget`. – Chris Haas May 19 '15 at 19:01
0

Just to elaborate on what MAlvarez and Chris Haas said, this might work for you:

  1. On the server use curl or wget to obtain your HTML:

    wget -O - http://localhost:80/my/page.html > result.html

  2. Post the result to your web service to render into PDF:

    curl -F file=@result.html -F outputName=result.pdf -F > result.pdf

  3. Store the result.pdf where you need it (unless your web service can do it in step #2)

    curl -F file=@result.pdf -F storeTo=my/storage/resultpdf

The commands above are only indicative because only you know the parameters of your web service etc.

Paul Jowett
  • 6,513
  • 2
  • 24
  • 19
0

So, still hard to post code but I was able to use HTMLGenericControls and Literals to build the entire page in the web service code and then use itextsharp to render that to a PDF.

Things like the table that the user facing version used a grid view I built into a Literal. The entire Page that I built in code then was handled by itextsharp and the PDF was generated into a filestream

Finuve
  • 73
  • 7