TextToOutlines.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.Pdf.AcroForms
  9. Imports GrapeCity.Documents.Pdf.Graphics
  10. Imports GrapeCity.Documents.Drawing
  11. Imports GrapeCity.Documents.Text
  12.  
  13. '' This sample shows how to convert all text in an existing PDF to glyph outlines.
  14. '' The resulting PDF will look exactly Like the original, but all glyphs in it
  15. '' will be rendered as graphics paths. This can be used to manipulate the paths,
  16. '' Or to make sure it will be impossible to copy Or search the text.
  17. '' Note that the resulting documents will have no fonts (see for example
  18. '' the Document Properties | Fonts tab in DsPdfViewer).
  19. '' The original PDF used by this sample was generated by Wetlands.
  20. Public Class TextToOutlines
  21. Function CreatePDF(ByVal stream As Stream) As Integer
  22. Dim doc = New GcPdfDocument()
  23. Using fs = File.OpenRead(Path.Combine("Resources", "PDFs", "Wetlands.pdf"))
  24. '' Load the source PDF into a temp document:
  25. Dim srcDoc = New GcPdfDocument()
  26. srcDoc.Load(fs)
  27. '' Draw all pages of the source document on pages of the New PDF:
  28. For Each srcPage In srcDoc.Pages
  29. Dim page = doc.Pages.Add(srcPage.Size)
  30. '' Setting Graphics.DrawTextAsPath to true makes all glyphs draw as graphics paths
  31. '' instead of rendering text using fonts:
  32. page.Graphics.DrawTextAsPath = True
  33. '' Draw the source page on the target:
  34. srcPage.Draw(page.Graphics, srcPage.Bounds)
  35. Next
  36. '' Done:
  37. doc.Save(stream)
  38. Return doc.Pages.Count
  39. End Using
  40. End Function
  41. End Class
  42.