Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi All,

YES, I have checked the samples of pdfsharp and searched for many hours for finding the solution for this very basic issue.

I have created reference and able to run hello world program successfully BUT am NOT able to know how to convert my existing aspx page into pdf.

Its urgent pls give the code lines if you have some as all links through google have already been tried by me.

Thanks in advance..


Below is the current code:

VB
' VB.NET version of 'Hello World'
Private Sub subCreatePDF()
    ' Create a new PDF document
    Dim document As PdfDocument = New PdfDocument
    document.Info.Title = "Created with PDFsharp"

    ' Create an empty page
    Dim page As PdfPage = document.AddPage

    ' Get an XGraphics object for drawing
    Dim gfx As XGraphics = XGraphics.FromPdfPage(page)

    ' Draw crossing lines
    Dim pen As XPen = New XPen(XColor.FromArgb(255, 0, 0))
    gfx.DrawLine(pen, New XPoint(0, 0), New XPoint(page.Width.Point, page.Height.Point))
    gfx.DrawLine(pen, New XPoint(page.Width.Point, 0), New XPoint(0, page.Height.Point))

    ' Draw an ellipse
    gfx.DrawEllipse(pen, 3 * page.Width.Point / 10, 3 * page.Height.Point / 10, 2 * page.Width.Point / 5, 2 * page.Height.Point / 5)

    ' Create a font
    Dim font As XFont = New XFont("Verdana", 20, XFontStyle.Bold)

    ' Draw the text
    gfx.DrawString("Hello, World!", font, XBrushes.Black, _
    New XRect(0, 0, page.Width.Point, page.Height.Point), XStringFormats.Center)


    ' Save the document...
    Dim filename As String = Server.MapPath("~\Documents\Intimation\Hello.pdf") '"H:\HelloWorld.pdf"
    document.Save(filename)

    ' ...and start a viewer.
    Process.Start(filename)

End Sub
Posted
Updated 22-Mar-17 0:01am
Comments
ZurdoDev 29-Jun-15 16:02pm    
So, what isn't working? What does happen? What is the error? Give us some details.
atul sharma 5126 30-Jun-15 5:43am    
I could not find any code to export/save the aspx page in pdf. The code given above just writes plain string in pdf when what I require is to export my already created page.
Hope I am able to clearly mention my situation.
Thanks

1 solution

There are many examples online but here is one that should work, http://www.aspsnippets.com/Articles/Export-ASPNet-Web-Page-with-images-to-PDF-using-ITextsharp.aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900