Platforms to show: All Mac Windows Linux Cross-Platform

/DynaPDF/text formatting/text formatting parallel


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 parallel

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

Project "text formatting parallel.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 parallel.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.CreateNewPDF(nil) // The output file is created later r.ColCount = 3 // Set the number of columns r.Distance = 10.0 // Distance between two columns 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 // first column call pdf.Append r.Column = 0 // Current column r.page = 1 r.PosX = 50.0 // Set the output rectangle first call pdf.SetTextRect(r.PosX, r.PosY+r.Height, 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 // second column call pdf.EditPage(1) r.page = 1 r.Column = 1 // Current column r.PosX = 50.0 + r.Column * (r.Width + r.Distance) pdf.current=r // Set the output rectangle first call pdf.SetTextRect(r.PosX, r.PosY+r.Height, r.Width, r.Height) Call pdf.SetFont("Helvetica", pdf.kfsNone, 12.0, True, pdf.kcpUnicode) call pdf.WriteFText(pdf.ktaJustify, fText) // Now we can print the text call pdf.EndPage // Close the last page // third column call pdf.EditPage(1) r.page = 1 r.Column = 2 // Current column r.PosX = 50.0 + r.Column * (r.Width + r.Distance) pdf.current=r // Set the output rectangle first call pdf.SetTextRect(r.PosX, r.PosY+r.Height, r.Width, r.Height) call pdf.SetFont("Helvetica", pdf.kfsNone, 9.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). // the page is full, close the current one and append a new page call EndPage r.page = r.page + 1 if r.page>GetPageCount then call Append else call EditPage(r.page) end if call SetTextRect(r.PosX, r.PosY, r.Width, r.Height) r.Column = 0 return 0 End EventHandler
Property IgnoreWarnings As Boolean
Property current As toutRect
End Class
Class TOutRect
Property ColCount As Integer
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
Property page As Integer
End Class
End Project

See also:

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


The biggest plugin in space...