Platforms to show: All Mac Windows Linux Cross-Platform
/DynaPDF/Create PDF with text block2
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /DynaPDF/Create PDF with text block2
This example is the version from Mon, 10th Sep 2023.
Project "Create PDF with text block2.xojo_binary_project"
FileTypes
Filetype Text
End FileTypes
MenuBar MenuBar1
MenuItem UntitledMenu1 = ""
MenuItem FileMenu = "&File"
MenuItem FileQuit = "Quit"
MenuItem UntitledMenu5 = ""
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu0 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "Clear"
MenuItem UntitledMenu4 = ""
MenuItem UntitledMenu3 = ""
MenuItem UntitledMenu2 = ""
End MenuBar
Class App Inherits Application
Const kText = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. \n\nDuis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. \n\nUt wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. \n\nNam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. \n\nDuis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis. \n\nAt vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, At accusam aliquyam diam diam dolore dolores duo eirmod eos erat, et nonumy sed tempor et et invidunt justo labore Stet clita ea et gubergren, kasd magna no rebum. sanctus sea sed takimata ut vero voluptua. est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat. \n\nConsetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus. "
EventHandler Sub Open()
test False, "Create PDF with text block1.pdf"
test True, "Create PDF With Text block2.pdf"
Quit
End EventHandler
Sub test(fix as Boolean, FileName as string)
Dim pdf As New MyDynapdfMBS
Dim d As New date
Dim height As Double
pdf.SetLicenseKey "Starter" // For this example you can use a Starter, Lite, Pro or Enterprise License
Dim f As FolderItem = SpecialFolder.Desktop.Child(FileName)
Call pdf.CreateNewPDF f
// We want to use top-down coordinates
Call pdf.SetPageCoords pdf.kpcTopDown
Call pdf.Append
// set font
Call pdf.SetFont "Helvetica", 0, 12.0, True, pdf.kcpUnicode
Dim y As Double = 50
// change font size and raise for foot note references
Dim TextToDraw As String = ktext
pdf.CurrentText = TextToDraw
pdf.fix = fix
Call pdf.Rectangle(50, 50, 440, 700, pdf.kfmStroke)
Call pdf.WriteFTextEx(50, 50, 440, 700, pdf.ktaJustify, TextToDraw)
Call pdf.EndPage
Call pdf.CloseFile
f.Launch
End Sub
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
EventHandler Function PageBreak(LastPosX as double, LastPosY as double, PageBreak as boolean) As integer
If fix Then
// where did text finish?
Dim LastTextPosY As Double = Me.GetLastTextPosY
// query the text rectangle
Dim RectX As Double
Dim RectY As Double
Dim RectW As Double
Dim RectH As Double
Call Me.GetTextRect(RectX, RectY, RectW, RectH)
// now check how much text is left
Dim pos As Integer = Me.GetLastTextOffset
Dim textLeft As String = CurrentText.Mid(pos+1)
// measure height
Dim Heigth As Double = Me.GetTextHeightEx(RectW, Me.ktaJustify, textLeft)
// if small, then add below existing block
If Heigth < 20 Then
Call Me.SetTextRect(RectX, LastTextPosY, RectW, 30)
Return Me.kNEW_ALIGN_JUSTIFY
End If
End If
// make a new page and continue
Call Me.EndPage
Call Me.Append
// continue
Return Me.kNEW_ALIGN_JUSTIFY
End EventHandler
Property ColumnWidth As Integer
Property CurrentText As String
Property IgnoreWarnings As Boolean
Property fix As Boolean
End Class
End Project
See also:
- /DynaPDF/Create Fields with JavaScript Actions
- /DynaPDF/Create PDF with bezier curve
- /DynaPDF/Create PDF with Circle
- /DynaPDF/Create PDF with Czech
- /DynaPDF/Create PDF with DeviceN Colorspace
- /DynaPDF/Create PDF with Highlight
- /DynaPDF/Create PDF with LAB color
- /DynaPDF/Create PDF with over 2 GB size
- /DynaPDF/Create PDF with PictureMBS
- /DynaPDF/Create PDF with restrictions
The items on this page are in the following plugins: MBS DynaPDF Plugin.