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/Change PDF Metadata
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/Change PDF Metadata
This example is the version from Sun, 17th Mar 2012.
Project "Change PDF Metadata.rbp"
Filetype text
Filetype application/pdf
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 NewDocument() dim f as FolderItem = GetOpenFolderItem(FileTypes.Pdf) if f<>nil then OpenDocument f end if End EventHandler
EventHandler Sub OpenDocument(item As FolderItem) process item End EventHandler
Sub Process(InputFile as FolderItem) if InputFile = nil then Return dim OutputFile as FolderItem = GetSaveFolderItem(FileTypes.Pdf, InputFile.name) if OutputFile = nil then Return dim pdf as new MyDynapdfMBS pdf.SetLicenseKey "Lite" // For this example you can use a Lite, Pro or Enterprise License call pdf.CreateNewPDF OutputFile /// If the imported document should be edited then avoid // the conversion of pages to templates (see SetImportFlags() // for further information). call pdf.SetImportFlags(bitwiseOr(pdf.kifImportAll,pdf.kifImportAsPage)) // Import the PDF file so that it can be edited call pdf.OpenImportFile(InputFile,pdf.kptOpen,"") dim iAuthor as string if pdf.GetInDocInfo(pdf.kdiAuthor, iAuthor)>0 then MetadataWindow.iAuthor.text = iAuthor end if dim iCreator as string if pdf.GetInDocInfo(pdf.kdiCreator, iCreator)>0 then MetadataWindow.iCreator.text = iCreator end if dim iCompany as string if pdf.GetInDocInfo(pdf.kdiCompany, iCompany)>0 then MetadataWindow.iCompany.text = iCompany end if dim iKeywords as string if pdf.GetInDocInfo(pdf.kdiKeywords, iKeywords)>0 then MetadataWindow.iKeywords.text = iKeywords end if dim iProducer as string if pdf.GetInDocInfo(pdf.kdiProducer, iProducer)>0 then MetadataWindow.iProducer.text = iProducer end if dim iSubject as string if pdf.GetInDocInfo(pdf.kdiSubject, iSubject)>0 then MetadataWindow.iSubject.text = iSubject end if dim iTitle as string if pdf.GetInDocInfo(pdf.kdiTitle, iTitle)>0 then MetadataWindow.iTitle.text = iTitle end if MetadataWindow.ShowModal if MetadataWindow.ok = false then Return end if iAuthor = MetadataWindow.iAuthor.text if len(iAuthor)>0 then call pdf.SetDocInfo pdf.kdiAuthor, iAuthor end if iCreator = MetadataWindow.iCreator.text if len(iCreator)>0 then call pdf.SetDocInfo pdf.kdiCreator, iCreator end if iCompany = MetadataWindow.iCompany.text if len(iCompany)>0 then call pdf.SetDocInfo pdf.kdiCompany, iCompany end if iTitle = MetadataWindow.iTitle.text if len(iTitle)>0 then call pdf.SetDocInfo pdf.kdiTitle, iTitle end if iKeywords = MetadataWindow.iKeywords.text if len(iKeywords)>0 then call pdf.SetDocInfo pdf.kdiKeywords, iKeywords end if iProducer = MetadataWindow.iProducer.text if len(iProducer)>0 then call pdf.SetDocInfo pdf.kdiProducer, iProducer end if iTitle = MetadataWindow.iTitle.text if len(iTitle)>0 then call pdf.SetDocInfo pdf.kdiTitle, iTitle end if dim pageCount as integer = pdf.ImportPDFFile(1, 1.0, 1.0) // If DestPage is 1, the return value is the new number of pages call pdf.CloseImportFile call pdf.CloseFile MetadataWindow.Close End Sub
End Class
Class MetadataWindow Inherits Window
Control iAuthor Inherits TextField
ControlInstance iAuthor Inherits TextField
End Control
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control iCreator Inherits TextField
ControlInstance iCreator Inherits TextField
End Control
Control StaticText2 Inherits Label
ControlInstance StaticText2 Inherits Label
End Control
Control StaticText3 Inherits Label
ControlInstance StaticText3 Inherits Label
End Control
Control iKeywords Inherits TextField
ControlInstance iKeywords Inherits TextField
End Control
Control iProducer Inherits TextField
ControlInstance iProducer Inherits TextField
End Control
Control StaticText4 Inherits Label
ControlInstance StaticText4 Inherits Label
End Control
Control iSubject Inherits TextField
ControlInstance iSubject Inherits TextField
End Control
Control StaticText5 Inherits Label
ControlInstance StaticText5 Inherits Label
End Control
Control StaticText6 Inherits Label
ControlInstance StaticText6 Inherits Label
End Control
Control iTitle Inherits TextField
ControlInstance iTitle Inherits TextField
End Control
Control iCompany Inherits TextField
ControlInstance iCompany Inherits TextField
End Control
Control StaticText7 Inherits Label
ControlInstance StaticText7 Inherits Label
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() ok=true hide End EventHandler
End Control
Control PushButton2 Inherits PushButton
ControlInstance PushButton2 Inherits PushButton
EventHandler Sub Action() ok=false hide End EventHandler
End Control
Property ok As Boolean
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

Feedback, Comments & Corrections

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

MBS Xojo PDF Plugins