Convert from HTML to PDF in CSharp VB and ASP.NET with a Free 3rd Party Library

Converting from html to pdf is not an easy task. There are some tools that can do that, but most of them cost thousands of dollars. SelectPdf offers a Community Edition (FREE) of the powerful Html To Pdf Converter for .NET that can be found in the full featured pdf library.

 
 
 
 
 
3.6 Star
(59)
52,883 times
Add to favorites
5/10/2019
E-mail Twitter del.icio.us Digg Facebook

Solution explorer

C#
VB.NET
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web

Namespace SelectPdf.Samples
	Public Class Helper
		Public Shared Function SomeShortText() As String
			Return "This is some short text. This is some short text. This is some short text. This is some short text. This is some short text. This is some short text. This is some short text. This is some short text. This is some short text. This is some short text. This is some short text. This is some short text. This is some short text. This is some short text. This is some short text."
		End Function

		Public Shared Function SomeText() As String
			Return "This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. " & vbCr & vbLf & vbCr & vbLf & "New paragraph. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. " & vbCr & vbLf & vbCr & vbLf & "3rd paragraph. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. New paragraph. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. " & vbCr & vbLf & vbCr & vbLf & "4th paragraph. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text."
		End Function

		Public Shared Function SomeLongText() As String
			Return "This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. " & vbCr & vbLf & vbCr & vbLf & "New paragraph. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. " & vbCr & vbLf & vbCr & vbLf & "3rd paragraph. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. New paragraph. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. " & vbCr & vbLf & vbCr & vbLf & "4th paragraph. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. " & vbCr & vbLf & vbCr & vbLf & "5th paragraph. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. " & vbCr & vbLf & vbCr & vbLf & "6th paragraph. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. " & vbCr & vbLf & vbCr & vbLf & "7th paragraph. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. " & vbCr & vbLf & vbCr & vbLf & "8th paragraph. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. " & vbCr & vbLf & vbCr & vbLf & "9th paragraph. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. " & vbCr & vbLf & vbCr & vbLf & "10th paragraph. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text. This is some long text."
		End Function

        Public Shared Function SomeVeryLongText() As String
            Return SomeLongText() + SomeLongText() + SomeLongText() + SomeLongText() + SomeLongText()
        End Function

		Public Shared Function PageBreaksText() As String
			Return "<html>" & vbCr & vbLf & "    <body>" & vbCr & vbLf & "        <div style=""font-size: 28px; page-break-after: always"">" & vbCr & vbLf & "            This is a short paragraph of text. After it, a page break will be inserted. <br/>" & vbCr & vbLf & "            This is a short paragraph of text. After it, a page break will be inserted. <br/>" & vbCr & vbLf & "            This is a short paragraph of text. After it, a page break will be inserted. <br/>" & vbCr & vbLf & "            This is a short paragraph of text. After it, a page break will be inserted. <br/>" & vbCr & vbLf & "        </div>" & vbCr & vbLf & vbCr & vbLf & "        <div style=""font-size: 28px; "">" & vbCr & vbLf & "            This paragraph should appear in the second page (the first paragraph inserted a page break after it). <br/>" & vbCr & vbLf & "            This paragraph should appear in the second page (the first paragraph inserted a page break after it). <br/>" & vbCr & vbLf & "            This paragraph should appear in the second page (the first paragraph inserted a page break after it). <br/>" & vbCr & vbLf & "            This paragraph should appear in the second page (the first paragraph inserted a page break after it). <br/>" & vbCr & vbLf & "            This paragraph should appear in the second page (the first paragraph inserted a page break after it). <br/>" & vbCr & vbLf & "            This paragraph should appear in the second page (the first paragraph inserted a page break after it). <br/>" & vbCr & vbLf & "            This paragraph should appear in the second page (the first paragraph inserted a page break after it). <br/>" & vbCr & vbLf & "            This paragraph should appear in the second page (the first paragraph inserted a page break after it). <br/>" & vbCr & vbLf & "            This paragraph should appear in the second page (the first paragraph inserted a page break after it). <br/>" & vbCr & vbLf & "            This paragraph should appear in the second page (the first paragraph inserted a page break after it). <br/>" & vbCr & vbLf & "            This paragraph should appear in the second page (the first paragraph inserted a page break after it). <br/>" & vbCr & vbLf & "            This paragraph should appear in the second page (the first paragraph inserted a page break after it). <br/>" & vbCr & vbLf & "            This paragraph should appear in the second page (the first paragraph inserted a page break after it). <br/>" & vbCr & vbLf & "        </div>" & vbCr & vbLf & vbCr & vbLf & "        <div style=""font-size: 28px; page-break-inside: avoid; "">" & vbCr & vbLf & "            This paragraph should all be displayed in the same page (contains page-break-inside: avoid). Since it's too large to appear in the second page, it will all appear in the third page. <br/>" & vbCr & vbLf & "            This paragraph should all be displayed in the same page (contains page-break-inside: avoid). Since it's too large to appear in the second page, it will all appear in the third page. <br/>" & vbCr & vbLf & "            This paragraph should all be displayed in the same page (contains page-break-inside: avoid). Since it's too large to appear in the second page, it will all appear in the third page. <br/>" & vbCr & vbLf & "            This paragraph should all be displayed in the same page (contains page-break-inside: avoid). Since it's too large to appear in the second page, it will all appear in the third page. <br/>" & vbCr & vbLf & "            This paragraph should all be displayed in the same page (contains page-break-inside: avoid). Since it's too large to appear in the second page, it will all appear in the third page. <br/>" & vbCr & vbLf & "            This paragraph should all be displayed in the same page (contains page-break-inside: avoid). Since it's too large to appear in the second page, it will all appear in the third page. <br/>" & vbCr & vbLf & "            This paragraph should all be displayed in the same page (contains page-break-inside: avoid). Since it's too large to appear in the second page, it will all appear in the third page. <br/>" & vbCr & vbLf & "            This paragraph should all be displayed in the same page (contains page-break-inside: avoid). Since it's too large to appear in the second page, it will all appear in the third page. <br/>" & vbCr & vbLf & "            This paragraph should all be displayed in the same page (contains page-break-inside: avoid). Since it's too large to appear in the second page, it will all appear in the third page. <br/>" & vbCr & vbLf & "            This paragraph should all be displayed in the same page (contains page-break-inside: avoid). Since it's too large to appear in the second page, it will all appear in the third page. <br/>" & vbCr & vbLf & "        </div>" & vbCr & vbLf & "    </body>" & vbCr & vbLf & "</html>" & vbCr & vbLf
		End Function

		Public Shared Function PixelsToPoints(value As Single) As Single
			Return 96F * value / 72F
		End Function

		Public Shared Function PointsToPixels(value As Single) As Single
			Return 72F * value / 96F
		End Function
	End Class
End Namespace