Xojo Conferences
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/DynaPDF/Create PDF with Layers Languages
Function:
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 Layers Languages
This example is the version from Sat, 19th Jan 2018.
Project "Create PDF with Layers Languages.rbp"
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 d as new date dim f as FolderItem = SpecialFolder.Desktop.Child("Create PDF with Layers Languages.pdf") pdf.SetLicenseKey "Lite" // For this example you can use a 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 // Pass warnings and errors to this error callback function dim oc1 as integer = pdf.CreateOCG("Deutsch", true, false, pdf.koiAll) dim oc2 as integer = pdf.CreateOCG("English", true, true, pdf.koiAll) dim bmkDE as integer = pdf.AddBookmark("Deutsch", -1, 1, false) dim bmkEN as integer = pdf.AddBookmark("English", -1, 1, false) dim toggle(-1), on(-1), off(-1) as Uint32 toggle.Append oc1 toggle.Append oc2 // Simply toggle the state from On to Off or vice versa dim act as integer = pdf.CreateSetOCGStateAction(on, off, toggle, true) // Add the action to the bookmarks call pdf.AddActionToObj(pdf.kotBookmark, pdf.koeOnMouseUp, act, bmkDE) call pdf.AddActionToObj(pdf.kotBookmark, pdf.koeOnMouseUp, act, bmkEN) call pdf.SetPageCoords(pdf.kpcTopDown) call pdf.Append call pdf.SetFont("Arial", pdf.kfsRegular + pdf.kfsItalic, 12.0, true, pdf.kcp1252) dim text1 as string = "Dieses Beispiel zeigt wie ein mehrsprachiges Dokument "+_ "erzeugt werden kann."+_ EndOfLine.UNIX+_ EndOfLine.UNIX+_ "Zunächst wird beim Öffnen des Dokuments die Sprache mit "+_ "einer JavaScript Aktion eingestellt."+_ EndOfLine.UNIX+_ EndOfLine.UNIX+_ "Zusätzlich kann die Sprache auch über zwei Lesezeichen "+_ "ausgewählt werden. Hierbei wird lediglich ein Layer ein- "+_ "bzw. ausgeblendet."+_ EndOfLine.UNIX+_ EndOfLine.UNIX+_ "Der Seiteninhalt muss natürlich zweimal erzeugt werden, einmal "+_ "in Deutsch und einmal in Englisch in diesem Beispiel, jeweils "+_ "in unterschiedlichen Layern." dim text2 as string = "This example shows how a multi-language document can be "+_ "created."+_ EndOfLine.UNIX+_ EndOfLine.UNIX+_ "The language is initially selected with a JavaScript "+_ "Action when opening the file."+_ EndOfLine.UNIX+_ EndOfLine.UNIX+_ "Additionally, the wished language can be selected with two "+_ "bookmarks. The bookmarks simply hide or unhide a layer."+_ EndOfLine.UNIX+_ EndOfLine.UNIX+_ "The page contents must of course be created twice, one time "+_ "in English and one time in German in this example, but in "+_ "different layers." // Text for the German layer call pdf.BeginLayer(oc1) call pdf.WriteFTextEx(50.0, 50.0, pdf.GetPageWidth - 100.0, pdf.GetPageHeight - 100.0, pdf.ktaLeft, text1) call pdf.EndLayer // Text for the English layer call pdf.BeginLayer(oc2) call pdf.WriteFTextEx(50.0, 50.0, pdf.GetPageWidth - 100.0, pdf.GetPageHeight - 100.0, pdf.ktaLeft, text2) call pdf.EndLayer call pdf.EndPage // This script displays the correct layer depending on the viewer // language. SI32 actLang = pdfCreateJSAction(pdf, dim lines(-1) as string lines.Append "if (app.viewerVersion >= 6.0)" lines.Append "{" lines.Append " var ocgArray = this.getOCGs();" lines.Append " var de = (app.language == ""DEU"");" lines.Append " for (var i = 0; i < ocgArray.length; i++)" lines.Append " {" lines.Append " if (ocgArray[i].name==""English"")" lines.Append " {" lines.Append " ocgArray[i].state = !de;" lines.Append " }" lines.Append " else" lines.Append " {" lines.Append " ocgArray[i].state = de;" lines.Append " }" lines.Append " }" lines.Append "}" dim javascript as string = Join(lines,EndOfLine.UNIX) dim actLang as integer = pdf.CreateJSAction(javascript) call pdf.AddActionToObj(pdf.kotCatalog, pdf.koeOnOpen, actLang, -1) call pdf.CloseFile f.Launch quit End EventHandler
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:

Feedback, Comments & Corrections

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




Links
MBS FileMaker Plugins