RenderPage0.vb
  1. ''
  2. '' This code is part of Document Solutions for PDF demos.
  3. '' Copyright (c) MESCIUS inc. All rights reserved.
  4. ''
  5. Imports System.IO
  6. Imports System.Drawing
  7. Imports GrapeCity.Documents.Pdf
  8. Imports GrapeCity.Documents.Text
  9. Imports GrapeCity.Documents.Html
  10.  
  11. '' This sample shows the simplest way to render a web page
  12. '' specified by a URL to a PDF (here we render the Google home page).
  13. ''
  14. '' In this sample we directly use the GcHtmlRenderer class
  15. '' to render the page to a temporary PDF file, which Is then
  16. '' returned in the output stream.
  17. '' A more flexible way that allows you to easily add HTML content
  18. '' to a PDF file along with other content Is via the extension
  19. '' methods GcPdfGraphics.MeasureHtml()/GcPdfGraphics.DrawHtml()
  20. '' as demonstrated by HelloWorldHtml And other samples.
  21. ''
  22. '' Please see notes in comments at the top of HelloWorldHtml
  23. '' sample code for details on adding DsHtml to your projects.
  24. Public Class RenderPage0
  25. Sub CreatePDF(ByVal stream As Stream)
  26. '' Get a temporary file where the web page will be rendered:
  27. Dim tmp = Path.GetTempFileName()
  28. '' The Uri of the web page to render:
  29. Dim uri = New Uri("http://www.google.com")
  30. '' Create an instance of GcHtmlBrowser that is used to render HTML:
  31. Using browser = Util.NewHtmlBrowser()
  32. '' Render the source Web page to the temporary file:
  33. Using htmlPage = browser.NewPage(uri)
  34. htmlPage.SaveAsPdf(tmp)
  35. End Using
  36. End Using
  37. '' Copy the created PDF from the temp file to target stream
  38. Using ts = File.OpenRead(tmp)
  39. ts.CopyTo(stream)
  40. End Using
  41. '' Clean up:
  42. File.Delete(tmp)
  43. '' Done.
  44. End Sub
  45. End Class
  46.