RenderPage1.vb
''
'' This code is part of GrapeCity Documents for PDF samples.
'' Copyright (c) GrapeCity, 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 how to render a web page specified by a URL
'' to a PDF. Here we render the C# source of the WordIndex sample.
'' Similar to HtmlRenderPage0, this sample directly uses GcHtmlRenderer,
'' but shows how to specify options such as page orientation, margins,
'' headers and footers.
''
'' For reference, the following markup extensions can be used in the
'' header and title templates (all except title are used in this sample):
'' - <span class="date">       - Formatted date
'' - <span class="title">      - Document title
'' - <span class="url">        - Document location
'' - <span class="pageNumber"> - Current page number
'' - <span class="totalPages"> - Total number of pages
''
'' Please see notes in comments at the top of HelloWorldHtml
'' sample code for details on adding GcHtml to your projects.
Public Class RenderPage1
    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("https://www.grapecity.com/documents-api-pdf/demos/view-source-cs/WordIndex/")
        '' Create a GcHtmlRenderer with the source Uri
        '' (note that GcHtmlRenderer ctor and other HTML rendering methods accept either a Uri
        '' specifying the HTML page to render, or a string which represents the actual HTML):
        Using re = New GcHtmlRenderer(uri)
            '' PdfSettings allow to provide options for HTML to PDF conversion:
            Dim pdfSettings = New PdfSettings() With
            {
                .PageRanges = "2-100", '' skip the first page which is empty in this case
                .PageWidth = 8.5F, '' this is the default, here for demo only
                .PageHeight = 11.0F, '' this is the default, here for demo only
                .Margins = New Margins(0.2F, 1, 0.2F, 1), '' page margins (default is no margins)
                .IgnoreCSSPageSize = True, '' try to ensure that we print the pages as we want
                .Landscape = True, '' use landscape to make sure long code lines fit
                .DisplayHeaderFooter = True, '' turn headers/footers on
                .HeaderTemplate = "<div style='font-size:12em;width:1000px;margin-left:0.2in;margin-right:0.2in'>" +
                    "<span style='float:left'>Page <span class='pageNumber'></span> of <span class='totalPages'></span></span>" +
                    "<span style='float:right'>Document created on <span class='date'></span>" +
                    "</div>",
                .FooterTemplate = "<div style='font-size:12em;width:1000px;margin-left:0.2in;margin-right:0.2in'>" +
                    "<span>Document location: <span class='url'></span></div>"
            }
            '' Render the source Web page to the temporary file:
            re.RenderToPdf(tmp, pdfSettings)
        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