CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 23
  1. #1
    Join Date
    May 2002
    Location
    Hyderabad
    Posts
    76

    How to convert HTML to PDF format

    Hi all,
    I want to create a program that converts HTML to PDF?
    How to do that using .NET?
    Please help immediately..
    thanks
    Ashish
    Ashish Sheth

  2. #2
    Join Date
    Apr 2003
    Location
    Concordia sulla Secchia (MO) Italy
    Posts
    202
    I think that PDF isn't a free file format.
    You should buy and use some Adobe Api to do that if they exist.
    Rudy Barbieri

  3. #3
    Join Date
    Jul 2002
    Location
    Seattle Area, WA
    Posts
    241
    If it is something that just "has to happen" and does not have to happen programtically, then you can get a PDF printer relatively cheap.

    I had to do this very thing for work recently, but we found it more cost effective to by a program called pdfFactory from http://www.fineprint.com which worked well for us. It cost about $50 or so if I remember right.

  4. #4
    Join Date
    May 2002
    Location
    Hyderabad
    Posts
    76
    Thanks,
    I have downloaded some tools which can convert HTML or any file format to PDF but I need some component or API using which I can programmatically convert HTML to PDF.
    I came to know that some PDFWritter and HTML2PDF api is there which can do this but I coudn't find any downloads on the net.
    Can some body tell me is there any component is available or from where can I download this api?

    Thanks,
    Ashish Sheth

  5. #5
    Join Date
    Jun 2003
    Location
    South Africa
    Posts
    11

    Post Script

    What you can do is try and read it in to a postscript and then use the Acrobat Distiller to create it
    Kind Regards
    Neil de Weerdt

  6. #6
    Join Date
    May 2002
    Location
    Hyderabad
    Posts
    76
    I don't know anything about PostScript and Acrobat Distiller.
    Main thing is that I want to develop it in .NET or use a component written in dotnet. I don't know what is postscript and whether it can be written in .net and whether Acrobat Distiller can be used in .net.

    Thanks
    Ashish Sheth

  7. #7
    Join Date
    Jun 2003
    Location
    South Africa
    Posts
    11

    Crystal

    I Generated the PostScript in my app.
    With a String Builder.
    And then I saved it to the disk.
    But then we had problems with user access.
    So what we the did is used crystal reports.
    It’s got a nice Exporting tool
    But the again you need to re do the page in crystal.
    Don’t think you want to do that.
    Kind Regards
    Neil de Weerdt

  8. #8
    Join Date
    May 2002
    Location
    Hyderabad
    Posts
    76
    Thaks,
    Can you tell me how to generate postscript using stringbuilder?
    An example will be nice.
    If I use crystal reports then i think it functionality will be restricted. I want to make a component like application which can be used in any application.

    thanks again
    Ashish Sheth

  9. #9
    Join Date
    Jun 2003
    Location
    South Africa
    Posts
    11

    Use of Post Script.

    Use of Post Script.
    You will have to have a look at the Script it self to see how to do it.
    What I did was to create the header in my app.
    And then the detail will be generated by a string builder.
    I deleted an example how to do this. so i cant help you with that.
    But here is an example of a post script file.
    In a post script file you will have a look at the code before %%EndSetup (That will be the header cant post that It’s about 20 page’s in word)
    Below that is your Detail this is what you need to generate on the fly.
    Don’t know the language that well.
    That you will find on adobe’s web site. Developers sdk
    //////////////////////////////////////////////////////////////////////////////
    %%EndSetup
    PDFVars begin PDF begin PDFVars/InitAll get exec
    0 0 612 792 re W n
    /N9 DefaultRGB /ColorSpace defineRes pop
    /N11 16 dict dup begin
    /SA false def
    /TR {}def
    /SM 0.02 def
    end /ExtGState defineRes pop
    BT
    /N8 1 Tf
    12 0 0 12 90.0406 709.2 Tm
    /N9 /ColorSpace findRes cs
    0 0 0 sc
    /N11 /ExtGState findRes gs
    -0.0002 Tc
    0.0002 Tw
    /N8 1 Tf (Use of Post Script. )Tj
    0 -1.14999 TD
    -0.00031 Tc
    0.00031 Tw
    /N8 1 Tf (You will have to have a look at the Script it self to see how to do it. \
    )Tj
    T*
    -0.0009 Tc
    0.0009 Tw
    /N8 1 Tf [(W)-7.10001 ]TJ /N8 1 Tf [(h)-0.89999 ]TJ /N8 1 Tf [(at I)22.10001 ]TJ /N8 1 Tf [( did was to create the header in my)29.10001 ]TJ /N8 1 Tf [( app. )]TJ
    T*
    0.0007 Tc
    -0.0007 Tw
    /N8 1 Tf [(And the)4.5 ]TJ /N8 1 Tf [(n)0.7 ]TJ /N8 1 Tf [( the)4.5 ]TJ /N8 1 Tf [( de)4.5 ]TJ /N8 1 Tf [(ta)4.5 ]TJ /N8 1 Tf [(il will be)4.5 ]TJ /N8 1 Tf [( g)10.7 ]TJ /N8 1 Tf [(e)4.5 ]TJ /N8 1 Tf [(ne)4.5 ]TJ /N8 1 Tf [(r)3.7 ]TJ /N8 1 Tf [(a)4.5 ]TJ /N8 1 Tf [(te)4.5 ]TJ /N8 1 Tf [(d by)30.7 ]TJ /N8 1 Tf [( a)4.5 ]TJ /N8 1 Tf [( str)3.7 ]TJ /N8 1 Tf [(i)-1.5 ]TJ /N8 1 Tf [(ng)10.7 ]TJ /N8 1 Tf [( builde)4.5 ]TJ /N8 1 Tf [(r)3.7 ]TJ /N8 1 Tf [(. )]TJ
    T*
    -0.0006 Tc
    0.0006 Tw
    /N8 1 Tf [(I)22.39999 ]TJ /N8 1 Tf [( deleted an ex)-10.60001 ]TJ /N8 1 Tf [(ample how to do this. )]TJ
    T*
    /N8 1 Tf [(B)6.3 ]TJ /N8 1 Tf [(u)-0.7 ]TJ /N8 1 Tf [(t here is an ex)-10.7 ]TJ /N8 1 Tf [(ample of a post script file. )]TJ
    T*
    0 Tc
    0 Tw
    /N8 1 Tf ( )Tj
    T*
    /N8 1 Tf ( )Tj
    T*
    /N8 1 Tf ( )Tj
    T*
    /N8 1 Tf ( )Tj
    ET
    PDFVars/TermAll get exec end end
    %%PageTrailer
    %%EndPage
    %%Trailer
    %%DocumentNeededResources:
    %%+ font TimesNewRomanPSMT
    %%EOF
    //////////////////////////////////////////////////////////////////////////////
    Kind Regards
    Neil de Weerdt

  10. #10
    Join Date
    May 2002
    Location
    Hyderabad
    Posts
    76
    thanks neildw,
    But I couldn't understand any of the postscript code.
    I am surfing on the net and I have found some tools that converts HTML to PostScript and some tools are there which converts PostScript to PDF.
    But the problem is all this tools are windows application or Printer drivers. and also this is a two step process.
    Also I came to know there are APIs(HTML2PDF and PDFWriter API) but I couldn't found any download for that.

    what i need is this:
    Either this APIs so I can write my own component
    Or A tool which I can call programatically in any .NET Application so that it converts HTML to PDF format.

    The PostScript idea seems good but I need to take time to learn PostScript that I don't have.

    Thanks again
    Ashish Sheth

  11. #11
    Join Date
    May 2002
    Location
    Hyderabad
    Posts
    76
    Ok, Now I have conceived one Idea. I think you people will understand and help me out here.

    what I was trying to do is I got some PDF printer driver using which I can convert HTML docs to PDF. As far as I give the print command from the Internet explorer selecting the PDF printer , it converts the HTML to PDF properly. but when I tried to print programatically I couldn't succeed. it just printed the HTML code not the actual matter which is displayed in the browser.


    Because HTML needs to be Printed as it is displayed in Browser, I have to programmatically open the internet explorer in invisible mode and open the required HTML file in it and give the internet explorer's print command selecting the PDF Printer.

    I think u people will understand the problem. How can I do this?

    Thanks and regards,
    Ashish Sheth

  12. #12
    Join Date
    Jun 2003
    Location
    South Africa
    Posts
    11

    Response.ContentType

    try the following.

    private void Page_Load(object sender, System.EventArgs e)
    {
    Response.ClearContent();
    Response.ClearHeaders();
    Response.ContentType = "application/pdf";
    }
    Kind Regards
    Neil de Weerdt

  13. #13
    Join Date
    May 2002
    Location
    Hyderabad
    Posts
    76
    Thanks Neildw,
    I have tried your code but it didn't work.
    I have on my page just to labels with some text. I put your code in my page_load event, but it shows the text of the label as such not the PDF file.
    Second thing is this will display a PDF file to the client but what if I want it to server. and what if I want it to convert to PDF in a windows based application?

    Thanks and regards,
    Ashish
    Ashish Sheth

  14. #14
    Join Date
    Jun 2003
    Location
    South Africa
    Posts
    11

    Sorry theres more

    Sorry on your Page (pdffile.aspx) there should be no HTML Code.
    Only
    <%@ Page language="c#" Codebehind=" pdffile.aspx.cs" AutoEventWireup="false"%>
    Kind Regards
    Neil de Weerdt

  15. #15
    Join Date
    May 2002
    Location
    Hyderabad
    Posts
    76
    Sorry Neildw,
    I couldn't get you.
    If on my aspx page no HTML will be there then what it will convert ?
    I need to convert HTML to PDF file not to display existing PDF file?
    I think your solution will work if I want to dispaly PDF file.
    Thanks,
    Ashish
    Ashish Sheth

Page 1 of 2 12 LastLast

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

Featured