Platforms to show: All Mac Windows Linux Cross-Platform

/DynaPDF/text formatting/text formatting Unicode


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/text formatting/text formatting Unicode

This example is the version from Wed, 14th Sep 2021.

Project "text formatting Unicode.xojo_binary_project"
FileTypes
Filetype text
Filetype icc
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
EventHandler Sub Open() dim pdf as new MyDynapdfMBS pdf.SetLicenseKey "Starter" // For this example you can use a Starter, Lite, Pro or Enterprise License // The structure TOutRect holds all required variables to calculate // the output rectangle. We use it to avoid the usage of global // variables. dim r as new TOutRect dim outfile as FolderItem=SpecialFolder.Desktop.Child("text formatting Unicode.pdf") // The text is stored in a file dim filepath as FolderItem=FindFile("sample.txt") dim fText as string = GetFileBuffer(filePath) if lenb(fText)=0 then MsgBox "Cannot open input file: "+filepath.Name quit end if // fText=ReplaceLineEndings(fText,EndOfLine.UNIX) call pdf.SetDocInfo(pdf.kdiCreator, "C++ test app") call pdf.SetDocInfo(pdf.kdiSubject, "Multi-column text") call pdf.SetDocInfo(pdf.kdiTitle, "Multi-column text") call pdf.SetPageCoords(pdf.kpcTopDown) call pdf.CreateNewPDF(nil) // The output file is created later call pdf.Append r.ColCount = 3 // Set the number of columns r.Column = 0 // Current column r.Distance = 10.0 // Distance between two columns r.PosX = 50.0 r.PosY = 50.0 r.Height = pdf.GetPageHeight - 100.0 r.Width = (pdf.GetPageWidth - 100.0 - (r.ColCount -1) * r.Distance) / r.ColCount pdf.current=r // Set the output rectangle first call pdf.SetTextRect(r.PosX, r.PosY, r.Width, r.Height) call pdf.SetFont("Helvetica", pdf.kfsNone, 10.0, true, pdf.kcpUnicode) call pdf.WriteFText(pdf.ktaJustify, fText) // Now we can print the text call pdf.EndPage // Close the last page // No fatal error occurred? if pdf.HaveOpenDoc then // OK, now we can open the output file. if ( not pdf.OpenOutputFile(outFile)) then MsgBox "Make sure that you have write access to the project folder." end if if pdf.CloseFile then outfile.Launch end if end if quit End EventHandler
Function FindFile(name as string) As FolderItem // Look for file in parent folders from executable on dim parent as FolderItem = app.ExecutableFile.Parent while parent<>Nil dim file as FolderItem = parent.Child(name) if file<>Nil and file.Exists then Return file end if parent = parent.Parent wend End Function
Function GetFileBuffer(file as folderitem) As string dim b as BinaryStream b=file.OpenAsBinaryFile(False) if b<>Nil then return b.Read(b.Length, encodings.WindowsANSI) end if 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
EventHandler Function PageBreak(LastPosX as double, LastPosY as double, PageBreak as boolean) As integer dim r as TOutRect = current call SetPageCoords(kpcTopDown) // we use top down coordinates r.Column=r.Column+1 // PageBreak is true if the string contains a page break tag (see help file for further information). if (not PageBreak and r.Column < r.ColCount) then // Calulate the x-coordinate of the column dim posX as double = r.PosX + r.Column * (r.Width + r.Distance) // change the output rectangle, do not close the page! call SetTextRect(posX, r.PosY, r.Width, r.Height) return 0 // we do not change the alignment else // the page is full, close the current one and append a new page call EndPage call Append call SetTextRect(r.PosX, r.PosY, r.Width, r.Height) r.Column = 0 return 0 end if End EventHandler
Property IgnoreWarnings As Boolean
Property current As toutRect
End Class
Class TOutRect
Sub Constructor() ColCount=1 End Sub
Property ColCount As Integer
Number of colummns
Property Column As Integer
Current column
Property Distance As double
Space between columns
Property Height As double
Original height of first output rectangle
Property PosX As double
Original x-coordinate of first output rectangle
Property PosY As double
Original y-coordinate of first output rectangle
Property Width As double
Original width of first output rectangle
End Class
End Project

See also:

The items on this page are in the following plugins: MBS DynaPDF Plugin.


The biggest plugin in space...