//// This code is part of Document Solutions for PDF .NET demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem;usingSystem.IO; namespaceDsPdfWeb.Demos{// 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 use GcHtmlBrowser to create an instance of HtmlPage// that loads the specified URI, and then call the HtmlPage.SaveAsPdf()// method to render the page to PDF.//// A different approach 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.// Note that those methods require an instance of GcHtmlBrowser// to be passed as parameter.// // Please see notes in comments at the top of HelloWorldHtml// sample code for details on adding DsHtml to your projects.publicclassRenderPage0 {publicvoidCreatePDF(Stream stream) {// Get a temporary file where the web page will be rendered:var tmp = Path.GetTempFileName();// The Uri of the web page to render:var uri = newUri("http://www.google.com");// Create an instance of GcHtmlBrowser that is used to render HTML:usingvar browser = Common.Util.NewHtmlBrowser();// Create an HtmlPage instance rendering the source Uri:usingvar htmlPage = browser.NewPage(uri);// Render the source Web page to the temporary file: htmlPage.SaveAsPdf(tmp);// Copy the created PDF from the temp file to target stream:using (var ts = File.OpenRead(tmp)) ts.CopyTo(stream);// Clean up:File.Delete(tmp);// Done. } }}