Platforms to show: All Mac Windows Linux Cross-Platform
/DynaPDF/DynaPDF Graphics/Create numbered pages
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /DynaPDF/DynaPDF Graphics/Create numbered pages
This example is the version from Thu, 27th Dec 2023.
Project "Create numbered pages.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
EventHandler Sub Open()
// we have two ways
DrawNumbersOnTopOfPages
'TemplateOnTopOfNumbers
quit
End EventHandler
Sub DrawNumbersOnTopOfPages()
Dim pdf As New MyDynapdfMBS
Dim x As integer
// 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 "Lite" // For this example you can use a Pro or Enterprise License
Dim f As FolderItem=SpecialFolder.Desktop.Child("Create numbered pages1.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.ImportPDFFile(1)
// no compression to read pdf file in text editor
call pdf.SetCompressionLevel(0)
dim PageCount as integer = pdf.GetPageCount
for x=1 to PageCount
Call pdf.EditPage(x)
call pdf.SetPageCoords(pdf.kpcBottomUp)
'call pdf.SetFontOrigin(pdf.korDownLeft)
Call pdf.SetUseVisibleCoords(True) // to avoid trouble with special cropbox settings
Dim g As Graphics = pdf.PageGraphics
g.FontName = "Times"
g.TextSize = 46
g.ForeColor = &cFF0000
g.DrawString "Page "+Str(x), 72, g.Height - 72
Call pdf.EndPage
next
call pdf.CloseImportFile
call pdf.CloseFile
f.Launch (true)
End Sub
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
Sub TemplateOnTopOfNumbers()
Dim pdf As New MyDynapdfMBS
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 pages2.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)
Dim g As Graphics = pdf.PageGraphics
g.FontName = "Times"
g.TextSize = 46
g.ForeColor = &cFF0000
g.DrawString "Page "+Str(x), 72, g.Height - 72
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)
End Sub
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
FileTypes1
Filetype Pdf
End FileTypes1
Sign
End Sign
End Project
See also:
- /DynaPDF/DynaPDF Graphics/DynaPDF Graphics iOS
- /DynaPDF/DynaPDF Graphics/DynaPDF GraphicsPath
- /DynaPDF/DynaPDF Graphics/Reporting/List Of Orders with Background
- /DynaPDF/DynaPDF Graphics/Reporting/List Of Products
- /DynaPDF/DynaPDF Graphics/Reporting/List Of Products Preview
- /DynaPDF/DynaPDF Graphics/Reporting/ListBoxReport
- /DynaPDF/DynaPDF Makros
- /DynaPDF/DynaPDF Merge 2 to 1
- /DynaPDF/DynaPDF Transparency Color Test
- /DynaPDF/DynaPDF transparent images/DynaPDF transparent images console
The items on this page are in the following plugins: MBS DynaPDF Plugin.