Web Hosting Forum | Lunarpages

Author Topic: convert html to pdf  (Read 24744 times)

Offline podznet

  • Pong! (the videogame) Master
  • *****
  • Posts: 23
convert html to pdf
« on: February 26, 2015, 07:46:18 PM »
I want to create a webpage dynamically with ASP or PHP and then have it automatically be converted into a PDF which is automatically emailed to someone. How would I go about doing this?

Thanks

Offline MrPhil

  • Senior Moderator
  • Berserker Poster
  • *****
  • Posts: 6207
Re: convert html to pdf
« Reply #1 on: February 27, 2015, 07:22:39 AM »
As far as I know, there is no good general purpose HTML-to-PDF converter, although it wouldn't hurt to look at products such as Adobe Acrobat (expensive!). You would probably be better off getting a PHP or ASP library that lets you directly generate PDF documents from your source data, rather than going through an HTML intermediate stage. It would also allow you finer control over the appearance and behavior of the resulting document.
Visit My Site

E-mail Me
  
-= From the ashes shall rise a sooty tern =-

Offline podznet

  • Pong! (the videogame) Master
  • *****
  • Posts: 23
Re: convert html to pdf
« Reply #2 on: February 27, 2015, 07:54:50 PM »
Thanks for you response. I think you're right. Do you know if I need to install anything to dynamically generate the PDF or is it just a php/asp script that I include?


Offline MrPhil

  • Senior Moderator
  • Berserker Poster
  • *****
  • Posts: 6207
Re: convert html to pdf
« Reply #3 on: February 27, 2015, 08:45:13 PM »
I don't know what's available for PHP or ASP. I know that there are some PDF-generation libraries for Perl (e.g., PDF::API2) that could be useful. For other languages, maybe there's some library code you could install on your server. Note that Acrobat will run on a PC, but I doubt it could be installed on a website server anyway.

I vaguely seem to recall that there is an osCommerce add-on to generate PDF invoices. That (forums.oscommerce.com) might give you a clue of where to start for a PHP-based site. Look in the Website > Add-Ons catalog.
Visit My Site

E-mail Me
  
-= From the ashes shall rise a sooty tern =-

Offline podznet

  • Pong! (the videogame) Master
  • *****
  • Posts: 23
Re: convert html to pdf
« Reply #4 on: February 28, 2015, 08:05:03 PM »
Thanks very much. I'll have a look.

Offline doncht

  • Intergalactic Cowboy
  • *****
  • Posts: 63
Re: convert html to pdf
« Reply #5 on: March 08, 2015, 04:13:45 AM »
Hi podznet, please update this thread if you find out anything.

Offline davidssmith01

  • Newbie
  • *
  • Posts: 4
Re: convert html to pdf
« Reply #6 on: July 07, 2016, 02:29:14 AM »
1:You can try this:
EVO HTML to Converter for .NET Core allows you develop applications for various platforms using C# as development language. The .NET Core platform from Microsoft can be used to create applications for Windows, Linux, OS X and FreeBSD for various CPUs.

2:Code:
using System;
using System.IO;

public class PdfcrowdTest
{
  static void Main() {
    try
    {
      FileStream fileStream; 

      // create an API client instance
      pdfcrowd.Client client = new pdfcrowd.Client("username", "apikey");

      // convert a web page and save the PDF to a file
      fileStream = new FileStream("google_com.pdf", FileMode.CreateNew);
      client.convertURI("http://www.google.com", fileStream);
      fileStream.Close();

      // convert an HTML string and store the PDF into a memory stream
      MemoryStream memStream = new MemoryStream();
      string html = "<head></head><body>My HTML Layout</body>";
      client.convertHtml(html, memStream);

      // convert an HTML file
      fileStream = new FileStream("file.pdf", FileMode.CreateNew);
      client.convertFile("c:/local/file.html", fileStream);
      fileStream.Close();

      // retrieve the number of tokens in your account
      int ntokens = client.numTokens();
    }
    catch(pdfcrowd.Error why) {
      System.Console.WriteLine(why.ToString());
    }
  }
}


<spam link removed>
« Last Edit: July 07, 2016, 04:24:18 AM by MrPhil »

 

Share |