Results 1 to 4 of 4

Thread: Anyone recommend a pdf generator?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    589

    Anyone recommend a pdf generator?

    Hi

    I have a page on which I generate a load of html which is used in a html email.

    Here is a bit of the code ...

    Code:
    MessageHeader = "<html>";
                MessageHeader += "<head>";
                MessageHeader += "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />";
                MessageHeader += "<title>Email from Customer Support</title>";
                MessageHeader += "<style type=\"text/css\">";
                MessageHeader += "html, body { margin:20px; border:0; padding:0; text-align:center; }";
                MessageHeader += "body {";
                MessageHeader += "font-family: arial, san-serif, Verdana;";
                MessageHeader += "font-size: 12px;";
                MessageHeader += "text-align: left;";
                MessageHeader += "}";
                MessageHeader += "</style>";
                MessageHeader += "</head>";
                MessageHeader += "<body>";
                MessageHeader += "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"width:800px;background-color:white\">";
    Because of the problems getting the email to look the same in various email clients, I need to convert that chunk of html to a pdf - so I can create the pdf on the fly, save it and attach it to the email.

    Can anyone suggest a simple pdf generator that will just take a chunk of html and create a pdf from it? The ones I have looked at so far have what looks like a steep learning curve with hundreds of features I don't need.

    Thanks for any suggestions.

  2. #2
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Anyone recommend a pdf generator?

    Hey,

    Have a look at iTextSharp:

    http://sourceforge.net/projects/itextsharp/

    It should do what you want.

    On a side note, due to the fact that the string class is immutable, you really shouldn't concatenate the string as you are. For what you are doing, I would highly recommend that you use the StringBuilder class.

    Gary

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    589

    Re: Anyone recommend a pdf generator?

    Hi Gary - thanks for the pdf suggestion - I'll give it a go.

    When you say ...

    "On a side note, due to the fact that the string class is immutable, you really shouldn't concatenate the string as you are. For what you are doing, I would highly recommend that you use the StringBuilder class."

    ... would you mind explaining a bit more please. I don't understand what I'm doing wrong concatenating the string as I have.

    Cheers

  4. #4
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Anyone recommend a pdf generator?

    Basically, the string class, once created, can't be changed. As a result, when you concatenate a string, it actually has to dispose of the first string, recreating a new one to store the concatenated version. This is fine when you are just doing this once, but when you are doing it several times, over and over again, with the string getting bigger and bigger each time, you are "hurting" your application by making it do lots of extra work.

    The StringBuilder class was created for specifically this purpose, and once created you can call the .Append or .AppendLine methods to add extra content to the string, and from there, you can call the .ToString method to get the entire string back when you have finished creating it.

    Hope that makes sense.

    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width