Platforms to show: All Mac Windows Linux Cross-Platform
/DynaPDF/Create PDF with Glyphs
Required plugins for this example: MBS DynaPDF Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /DynaPDF/Create PDF with Glyphs
This example is the version from Sun, 23th Sep 2017.
Project "Create PDF with Glyphs.xojo_binary_project"
FileTypes
Filetype text
End FileTypes
MenuBar MenuBar1
MenuItem UntitledMenu1 = ""
MenuItem FileMenu = "&File"
MenuItem FileQuit = "Quit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu0 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class App Inherits Application
EventHandler Sub Open()
dim pdf as new MyDynapdfMBS
dim line as integer = 120
dim col as integer = 60
dim page as integer = 1
dim font as string = "Arial" // font to test
dim t as string
dim f as FolderItem = SpecialFolder.Desktop.Child("Create PDF with Glyphs " + font + ".pdf")
pdf.SetLicenseKey "Starter" // For this example you can use a Starter, Lite, Pro or Enterprise License
call pdf.CreateNewPDF f
call pdf.SetDocInfo pdf.kdiSubject, "My first Xojo output"
call pdf.SetDocInfo pdf.kdiProducer, "Xojo test application"
call pdf.SetDocInfo pdf.kdiTitle, "My first Xojo output"
// We want to use top-down coordinates
call pdf.SetPageCoords pdf.kpcTopDown
call pdf.Append
dim hFont1 as integer = pdf.SetFont (font, pdf.kfsNone, 20.0, true, pdf.kcpUnicode)
dim hFont2 as integer = pdf.SetFont ( "Courier", pdf.kfsNone, 14.0, true, pdf.kcpUnicode)
dim fontInfo as DynaPDFFontInfoMBS = pdf.GetFontInfoEx(hFont1)
call pdf.changeFont(hFont2)
call pdf.ChangeFontSize(24.0)
'call pdf.SetFont "Courier New", pdf.kfsNone, 24.0, true, pdf.kcpUnicode
call pdf.WriteFText pdf.ktaCenter, "Glyphs for " + font
for i as integer = 32 to 65535
if i >= 56320 and i <= 57343 then continue // Skip the Unicode 'dead area'
t = encodings.UTF16.Chr(i)
if pdf.TestGlyphs( hFont1, t ) <> -1 then continue // Check font for populated codepoints
call pdf.changeFont(hFont2)
call pdf.ChangeFontSize(14.0)
'call pdf.SetFont "Courier New", pdf.kfsNone, 14.0, true, pdf.kcpUnicode
call pdf.WriteText col, line, getHex(i)
call pdf.changeFont(hFont1)
call pdf.ChangeFontSize(20.0)
'call pdf.SetFont font, pdf.kfsNone, 20.0, true, pdf.kcpUnicode
call pdf.WriteText col + 70, line + fontInfo.Descent/72.0, t
if line < 650 then
line = line + 30
else
line = 120
if col < 440 then
col = col + 130
else
col = 60
call pdf.changeFont(hFont2)
call pdf.ChangeFontSize(14.0)
'call pdf.SetFont "Courier New", pdf.kfsNone, 14.0, true, pdf.kcpUnicode
call pdf.WriteText 470, 750, "Page " + str( page )
call pdf.EndPage
call pdf.Append
call pdf.changeFont(hFont2)
call pdf.ChangeFontSize(24.0)
'call pdf.SetFont "Courier New", pdf.kfsNone, 24.0, true, pdf.kcpUnicode
call pdf.WriteFText pdf.ktaCenter, "Glyphs for " + font + " (contd.)"
page = page + 1
end if
end if
next
call pdf.changeFont(hFont2)
'call pdf.SetFont "Courier New", pdf.kfsNone, 14.0, true, pdf.kcpUnicode
call pdf.WriteText 470, 750, "Page " + str( page )
call pdf.EndPage
call pdf.CloseFile
f.Launch
quit
End EventHandler
Function getHex(int as integer) As string
dim s as string
select case len(hex(int))
case 2
s = "&h00" + hex(int)
case 3
s = "&h0" + hex(int)
case else
s = "&h" + hex(int)
end select
return s
End Function
End Class
Class MyDynaPDFMBS Inherits DynaPDFMBS
EventHandler Function Error(ErrorCode as integer, ErrorMessage as string, ErrorType as integer) As integer
// output all messages on the console:
System.DebugLog str(ErrorCode)+": "+ErrorMessage
// and display dialog:
Dim d as New MessageDialog //declare the MessageDialog object
Dim b as MessageDialogButton //for handling the result
d.icon=MessageDialog.GraphicCaution //display warning icon
d.ActionButton.Caption="Continue"
d.CancelButton.Visible=True //show the Cancel button
// a warning or an error?
if BitAnd(ErrorType, me.kE_WARNING) = me.kE_WARNING then
// if user decided to ignore, we'll ignore
if IgnoreWarnings then Return 0
d.Message="A warning occurred while processing your PDF code."
// we add a third button to display all warnings
d.AlternateActionButton.Caption = "Ignore warnings"
d.AlternateActionButton.Visible = true
else
d.Message="An error occurred while processing your PDF code."
end if
d.Explanation = str(ErrorCode)+": "+ErrorMessage
b=d.ShowModal //display the dialog
Select Case b //determine which button was pressed.
Case d.ActionButton
Return 0 // ignore
Case d.AlternateActionButton
IgnoreWarnings = true
Return 0 // ignore
Case d.CancelButton
Return -1 // stop
End select
End EventHandler
Property IgnoreWarnings As Boolean
End Class
End Project
See also:
- /DynaPDF/Create numbered pages
- /DynaPDF/Create PDF console
- /DynaPDF/Create PDF in memory
- /DynaPDF/Create PDF UA
- /DynaPDF/Create PDF with Line
- /DynaPDF/Create PDF with page wrap
- /DynaPDF/Create PDF with Picture
- /DynaPDF/Create PDF with Round Rectangles
- /DynaPDF/Create PDF with sum form field
- /DynaPDF/Create PDF with text block
The items on this page are in the following plugins: MBS DynaPDF Plugin.