Xojo Developer Conference
25/27th April 2018 in Denver.
MBS Xojo Conference
6/7th September 2018 in Munich, Germany.

Platforms to show: All Mac Windows Linux Cross-Platform

/DynaPDF/Create numbered pages
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 numbered pages
This example is the version from Sun, 17th Mar 2012.
Project "Create numbered pages.rbp"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
EventHandler Sub Open() dim pdf as new MyDynapdfMBS dim box as new DynaPDFRectMBS Dim x,template As integer dim mediabox, cropbox as DynaPDFRectMBS // takes existing PDF and draws a new one with page numbers and draws old PDF on top of that dim source as FolderItem = getopenfolderitem(FileTypes1.Pdf) if source=nil then return end if pdf.SetLicenseKey "Pro" // For this example you can use a Pro or Enterprise License dim f as FolderItem=SpecialFolder.Desktop.Child("Create numbered pages.pdf") call pdf.CreateNewPDF f call pdf.SetDocInfo pdf.kdiSubject, " " call pdf.SetDocInfo pdf.kdiProducer, "Quality Press Software" call pdf.SetDocInfo pdf.kdiAuthor, "Auto-Number" call pdf.SetDocInfo pdf.kdiTitle, "Numbered Output" call pdf.OpenImportFile source, pdf.kptOpen, "" call pdf.AddFontSearchPath SpecialFolder.Desktop.Child("fonts"),true for x=1 to pdf.getinPageCount call pdf.append call pdf.SetFontOrigin(pdf.korDownLeft) call pdf.SetFont "Times",pdf.kfsNone,46,True,pdf.kcp1252 call pdf.SetFillColor(-2550000) call pdf.WriteText 1*72,1*72, "Page "+str(x) template=pdf.ImportPage(x) mediabox=pdf.getinbbox(x,pdf.kpbmediaBox) cropbox=pdf.getinbbox(x,pdf.kpbcropBox) call placecentered(pdf, template, mediaBox, cropBox, 0, 0, pdf.getpageWidth, pdf.getpageheight) call pdf.EndPage next call pdf.CloseImportFile call pdf.CloseFile f.Launch (true) quit End EventHandler
Protected Function PlaceCentered(pdf as dynapdfmbs, template as integer, mediabox as DynaPDFRectMBS, cropbox as DynaPDFRectMBS, destx as double, desty as double, destwidth as double, destheight as double) As boolean dim x,y,w,h,sx as double if CropBox = nil then // If no crop box is set use the media box. CropBox = MediaBox end if w = CropBox.Right - CropBox.Left h = CropBox.Top - CropBox.Bottom sx = DestWidth / w // The origin of the template must be scaled if (h * sx <= DestHeight) then h = h* sx w = (MediaBox.Right - MediaBox.Left) * sx x = DestX - CropBox.Left * sx y = DestY - CropBox.Bottom * sx + (DestHeight - h) / 2.0 return pdf.PlaceTemplate( template, x, y, w, 0.0) else sx = DestHeight / h w = w*sx h = (MediaBox.Top - MediaBox.Bottom) * sx x = DestX - CropBox.Left * sx + (DestWidth - w) / 2.0 y = DestY - CropBox.Bottom * sx return pdf.PlaceTemplate(template, x, y, 0.0, h) end if End Function
Property dynapdfFontMBSXHeight As Single
End Class
Class Window1 Inherits Window
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
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
Filetype application/pdf
End FileTypes1
End Project

See also:

Feedback, Comments & Corrections

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

MBS Xojo PDF Plugins