''
'' This code is part of Document Solutions for PDF demos.
'' Copyright (c) MESCIUS inc. All rights reserved.
''
Imports System.IO
Imports System.Drawing
Imports GrapeCity.Documents.Pdf
Imports GrapeCity.Documents.Text
Imports GrapeCity.Documents.Html
'' This sample shows the simplest way to render a web page
'' specified by a URL to a PDF (here we render the Google home page).
''
'' In this sample we directly use the GcHtmlRenderer class
'' to render the page to a temporary PDF file, which Is then
'' returned in the output stream.
'' A more flexible way that allows you to easily add HTML content
'' to a PDF file along with other content Is via the extension
'' methods GcPdfGraphics.MeasureHtml()/GcPdfGraphics.DrawHtml()
'' as demonstrated by HelloWorldHtml And other samples.
''
'' Please see notes in comments at the top of HelloWorldHtml
'' sample code for details on adding DsHtml to your projects.
Public Class RenderPage0
Sub CreatePDF(ByVal stream As Stream)
'' Get a temporary file where the web page will be rendered:
Dim tmp = Path.GetTempFileName()
'' The Uri of the web page to render:
Dim uri = New Uri("http://www.google.com")
'' Create an instance of GcHtmlBrowser that is used to render HTML:
Using browser = Util.NewHtmlBrowser()
'' Render the source Web page to the temporary file:
Using htmlPage = browser.NewPage(uri)
htmlPage.SaveAsPdf(tmp)
End Using
End Using
'' Copy the created PDF from the temp file to target stream
Using ts = File.OpenRead(tmp)
ts.CopyTo(stream)
End Using
'' Clean up:
File.Delete(tmp)
'' Done.
End Sub
End Class