Convert current html page into PDF

Last post 09-28-2009 8:02 AM by DuoDimension. 5 replies.

Sort Posts:

  • Convert current html page into PDF

    07-11-2007, 5:54 AM
    • Member
      20 point Member
    • pragasht
    • Member since 11-17-2006, 7:33 AM
    • India
    • Posts 25

     

               When a user clicks a button in a page 

                                     that page has to be rendered as PDF file, where as any freeware or free component available to do that

    Regards
    Pragash T
    Chennai

    Filed under:
  • Re: Convert current html page into PDF

    07-15-2007, 11:07 PM

    Hi Pragash,

    Seems there is no free component for this feature. However, Most of them have the Trial Version for download. Please check the link below:

    http://search.msn.co.uk/results.aspx?q=html+pdf+convert+free&form=QBRE

    Anyway, please refer to the following links. From their shared solutions, I hope you can decide which one is acceptable to you.

    Pdfizer, a dumb HTML to PDF converter, in C#
    http://www.codeproject.com/csharp/pdfizer.asp

    PDF Library for creating PDF with tables and text, in C#
    http://www.codeproject.com/dotnet/PdfLibrary.asp

    Generate PDF documents from a HTML page using ASP.NET
    http://www.codeproject.com/aspnet/HTML2PDF.asp

     

    Sincerely,
    Benson Yu
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help. This can be beneficial to other community members reading the thread.
  • Re: Convert current html page into PDF

    07-16-2007, 3:46 AM
    Answer
    • Member
      20 point Member
    • pragasht
    • Member since 11-17-2006, 7:33 AM
    • India
    • Posts 25

    Thanks For Your reply Benson Yu

                  I found a free tool to make a pdf , though the task is to convert a html page into PDF, I got a free tool to make a new pdf in asp.net  using

    iTextSharp (http://channel9.msdn.com/ShowPost.aspx?PostID=120461_  and its working now, where the pdf page is deigned in server side code.

     

    Dim m As New MemoryStream()

    Dim document As New Document(PageSize.A4.Rotate(), 10, 10, 10, 10)

    Try

    Response.ContentType = "application/pdf"

    PdfWriter.GetInstance(document, m)

    document.Open()

    PdfWriter.GetInstance(document,
    New FileStream("Chap0501.pdf", FileMode.Create))

    ' step 3: we open the document

    document.Open()

    Dim strBuilder As New StringBuilder

    strBuilder.Append("GLASGOW - De Britse politie zoekt maandageen zesde verdachte in verband met de drieaanslagpogingen")

    strBuilder.Append("in Londen en Glasgow van hetvoorbije weekend. Het terreuralarm in Groot-")

    strBuilder.Append("Brittannië blijft intussen hoog. De Britse autoriteiten")

    strBuilder.Append("zouden moeite hebben met het vaststellen van de identiteit van verdachten. Sky")

    strBuilder.Append("News en verscheidene Britse kranten meldden")

    strBuilder.Append("dat er bij de verdachten artsen zijn die in Britse")

    strBuilder.Append("ziekenhuizen werken.")

    Dim helvetica As BaseFont = BaseFont.CreateFont("Helvetica", BaseFont.CP1252, BaseFont.NOT_EMBEDDED)

    Dim font As New Font(helvetica, 12, font.NORMAL)

    Dim chunk As New Chunk(" this is an example dto dfgsdfg sdfg sdfg sdfg sd fg sdfg sdfg sdfg sd fg asdnkfklsdfg sdfg dfg sdfg fgjjhklcvbnxcvbnfg dfghfdgh", font)

    document.Add(chunk)

     

    document.Add(
    New Paragraph(strBuilder.ToString))Dim jpeg As Image = Image.GetInstance(New Uri("http://localhost:4548/TPGTest/j1.bmp"))

    jpeg.Alignment = jpeg.Right

    document.Add(jpeg)

    Dim jpeg2 As Image = Image.GetInstance(New Uri("http://localhost:4548/TPGTest/j2.bmp"))

    jpeg2.Alignment = jpeg2.Left

    document.Add(jpeg2)

    Dim strBuilder2 As New StringBuilder

    strBuilder2.Append("De Britse politie zou de verdachten van de aanslag op de luchthaven")

    strBuilder2.Append("van Glasgow al op het spoor geweest zijn vlak voordat zij")

    strBuilder2.Append("zaterdag hun mislukte aanslag pleegden. Dit heeft de woordvoerder")

    strBuilder2.Append("van een particulier woningverhuurbedrijf, Let-In, in Glasgow")

    strBuilder2.Append("maandag gezegd. Een of meerdere verdachten verbleven in een woning van Let-In.")

    document.Add(New Paragraph(strBuilder2.ToString))document.Add(New Paragraph("Yet another test"))

     

    'Dim helvetica As BaseFont = BaseFont.CreateFont("Helvetica", BaseFont.CP1252, BaseFont.NOT_EMBEDDED)

    'Dim font As New Font(helvetica, 22, font.NORMAL)

    'Dim chunk As New Chunk(" this is an example dto dfgsdfg sdfg sdfg sdfg sd fg sdfg sdfg sdfg sd fg asdnkfklsdfg sdfg dfg sdfg fgjjhklcvbnxcvbnfg dfghfdgh", font)

    'document.Add(chunk)

     

    Catch ex As DocumentException

    Console.[Error].WriteLine(ex.StackTrace)

    Console.[Error].WriteLine(ex.Message)

    End Try

    ' step 5: Close document

    document.Close()

    ' step 6: Write pdf bytes to outputstream

    Response.OutputStream.Write(m.GetBuffer(), 0, m.GetBuffer().Length)

    Response.OutputStream.Flush()

    Response.OutputStream.Close()

    Regards
    Pragash T
    Chennai

  • Re: Convert current html page into PDF

    07-16-2007, 3:51 AM

    Hi Pragash,

    Thanks for sharing the solution. I believe many people will benefit from it.

     

    Sincerely,
    Benson Yu
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help. This can be beneficial to other community members reading the thread.
  • Re: Convert current html page into PDF

    07-01-2009, 6:02 AM
    • Member
      13 point Member
    • Balajie100
    • Member since 01-06-2009, 9:03 AM
    • India
    • Posts 16

    Hi..Pragasht


    Iam having a very urgent requirement of converting a web page to pdf format... you have

    mentioned that you are having a tool for converting and integrating with .net and gave a  vb

    code for that....Can you please give C# version of the code and the tool...Requirement is very

    urgent and expecting your reply at the earliest..


    Thanks & Regards

    Balaji.S

  • Re: Convert current html page into PDF

    09-28-2009, 8:02 AM
    • Member
      24 point Member
    • DuoDimension
    • Member since 05-28-2009, 7:25 AM
    • Posts 15

    I advise PDF Duo .NET converting component (but it is not free).

    It converts a html to a pdf.

    But the component can be used as a creator. For that just pass a html string:

    public partial class _Default : System.Web.UI.Page    
    {   
        protected void Page_Load(object sender, EventArgs e)   
        {   
            DuoDimension.HtmlToPdf conv = new DuoDimension.HtmlToPdf();   
            conv.BasePath = MapPath("~/");   
            conv.PageFormat = DuoDimension.ePageFormat.A4;   
            conv.PageOrientation = DuoDimension.ePageOrientation.Portrait;   
            conv.OpenHTML(@"   
                    <table width='100%'>   
                      <tr>   
                        <td width='19%'><strong>Last update:</strong></td>   
                        <td width='81%'> 23 Jun 2009 - 01:22</td>   
                      </tr>   
                      ...   
                    </table>   
            ");   
            conv.SavePDF(MapPath("~/pdf/") + "report.pdf");   
            preport.InnerText = "The report has been created.";   
        }   
    }   

    How dinamicly convert/create pdf in ASP.NET web applications, see info on the component page.

    We are open for any ideas regarding cooperation.

Page 1 of 1 (6 items)