Platforms to show: All Mac Windows Linux Cross-Platform

/DynaPDF/Create PDF with DPart Metadata


You find this example project in your Plugins Download as a Xojo project file within the examples folder: /DynaPDF/Create PDF with DPart Metadata

This example is the version from Tue, 17th Jul 2023.

Project "Create PDF with DPart Metadata.xojo_binary_project"
FileTypes
Filetype Text
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
Const SampleText = "PDF/A and PDF/X Compatibility\n\nPDF files can be created for different purposes such as printing, publishing, or archiving which have all their own requirements. Due to these different requirements two separate PDF standards were defined by the ISO Committee, PDF/X and PDF/A.\n\nPDF/X\n\nThe PDF/X-1a standard addresses blind exchanges where all files should be delivered in CMYK (and/or spot colors), with no RGB or device independent (color-managed) data. This is a common requirement in many areas around the world and in many print sectors usually tied to an environment where the file supplier wants to retain maximum control of the print job.\nPDF/X 3 is like PDF/X 1a an ISO standard for graphic content exchange. The main difference is that PDF/X 3 allows the use of color management and device-independent color in addition to CMYK and spot colors.\nThe PDF/X standard requires all fonts to be embedded, the appropriate PDF bounding boxes to be specified, and color to appear as CMYK, spot colors, or both. In addition, PDF/X compliant PDF files must contain information describing the printing condition for which they are prepared (see AddRenderingIntent()).\nWhen creating PDF/X compliant files with DynaPDF you need to know that DynaPDF does not check whether certain features are allowed to use in the selected PDF/X standard. DynaPDF simply writes the required PDF/X key to the file which tells the viewer application that this file is compliant to a specific PDF/X version. Whether this is true or not depends on whether you used allowed features only and whether all required information were added to the file, e.g. the rendering intent (see AddRenderingIntent()), the document title (see SetDocInfo()) and the trim box for each page (see SetBBox()). It is usually best to check the resulting PDF file with a preflight tool before using certain features in a production environment.\nHowever, it is not very difficult to create PDF/X compliant PDF files. The main recommendation is that all fonts are embedded, that at the least the trim box for all pages are set, and that colors are defined in the color space DeviceCMYK (see SetColorSpace()). In addition, an ICC profile must be embedded in the file (see AddRenderingIntent()) and images must not be compressed with JPEG2000 compression.\nThe wished output PDF version must be set with SetPDFVersion().\n\nPDF/A\n\nPDF/A is an ISO standard for long-term preservation. These files are primarily used for archiving. PDF/A compliant files can contain text, raster images, vector graphics, as well as annotations, hyperlinks, or bookmarks.\nHowever, PDF/A compliant files must not contain JavaScripts or an Interactive Form. In addition, all fonts must be embedded and PDF/A compliant files must contain information describing the printing condition for which they are prepared (see AddRenderingIntent()). The output intent can be either CMYK or RGB based. However, only one device color space can be used in a document with the exception that DeviceGray can be combined with RGB or CMYK color spaces.\nWhen creating PDF/A compatible files with DynaPDF it is important to know that DynaPDF does not automatically check whether certain features are allowed to use. DynaPDF writes simply the required PDF/A key to the file which tells the viewer application that the file is compatible to a specific PDF/A standard. Whether this is true or not depends on whether prohibited features were used and whether all required information were added to the file, e.g. the rendering intent.\nHowever, DynaPDF contains the function CheckConformance() to check and convert non- conformant PDF files to PDF/A 1b. The function was originally developed a very powerful PDF to PDF/A converter called myPDFConvert by the DETEC GmbH in Germany.\nAll DynaPDF versions provide a restricted version of CheckConformance() that does not convert imported PDF files to PDF/A. The conversion of imported PDF files is possible if DynaPDF was licensed with the PDF/A Extension.\nCheckConformance() is a very good helper function to get your PDF file fully PDF/A 1b compatible. CheckConformance() is not a preflight function, it automatically adjusts anything that is possible to get the file PDF/A 1b compatible. The function supports a large set of flags to specify what should be done if prohibited features were found in the file. Take a look into the function description for further information.\n\n"
EventHandler Sub Open() Dim pdf As New MyDynapdfMBS dim d as new date dim f as FolderItem = SpecialFolder.Desktop.Child("Create PDF.pdf") pdf.SetLicenseKey "Starter" // For this example you can use a Starter, Lite, Pro or Enterprise License call pdf.CreateNewPDF f // make a few dummy pages If pdf.Append Then Call pdf.EndPage End If If pdf.Append Then Call pdf.EndPage End If If pdf.Append Then Call pdf.EndPage End If // Create the required root node Dim nameList() As String = Array("Root", "Pages") Call pdf.CreateDPartRoot(nameList, 3) // This node holds some DPM for two child DPart nodes. Dim node As Integer = pdf.AddDPartNode( -1, -1, -1, dpmbase) // We create two ranges for test purposes. Dim last As Integer = pdf.GetPageCount / 2 Dim json2 As String = """CIP4_Production"":{""CIP4_CopyCount"" : 1""CIP4_User"":""Stefan""}" Dim json3 As String = """CIP4_Production"":{""CIP4_CopyCount"" : 1""CIP4_User"":""Jens""}" Call pdf.AddDPartNode( node, 1, last, json2) Call pdf.AddDPartNode( node, last + 1, pdf.GetPageCount(), json3) // If you want to have a look into the resulting PDF file then deactivate object compression. If DebugBuild Then // don't compress Call pdf.SetGStateFlags( pdf.kgfNoObjCompression Or pdf.kgfDoNotComprMetadata, False) Else Call pdf.SetGStateFlags( pdf.kgfDoNotComprMetadata, False) End If Call pdf.CloseFile f.Launch 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
Property dpmBase As string = "{ ""ACME CustStatus"": ""Prospective"" ""CIP4 Root"": { ""CIP4 Summary"" : { ""CIP4 PageCount"" : 6 ""CIP4 Checked"" true } ""CIPA Production"": { ""CIPA CopyCount"" : 1 ""CIP4 Part"": { ""CIP4 ProductType"" : ""Brochure"" } } ""CIPA Recipient"" : { ""CIP4 Contact"" : { ""CIP4 Address"" : { ""CIPA City"": ""Phoenix"" ""CIPA CivicNumber"": ""96"" ""CIP4 Country"" : ""USA"" ""CIP4 PostalCode"" :""81215"" ""CIP4 Region"" : ""AZ"" ""CIP4 StreetName"" :""South Ave"" ""CIPA TestArrayl"" [1 2 3 4 true, false] ""CIPA TestArray?"" { ""Array"" [5 6 7 8 ""Testl""/Test2] } ""CIP4 Person"" : { ""CIP4 FirstName"" : ""Mary"" ""CIP4 LastName"": ""Smith"" } } ""CIPA UniqueID"" : ""ID I"" } } }"
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 // we use top down coordinates Call Self.SetPageCoords(kpcTopDown) Column = Column + 1 If Column < ColCount And Not PageBreak Then // Calulate the x-coordinate of the column Dim x As Double = Self.PosX + Self.Column * (Self.Width + Self.Distance) Call Self.SetTextRect(x, PosY, Width, Height) Return 0 else // The page is full or a page break event occurred. Close the current tag and append a new page. Call Self.CloseTag // P Call Self.EndPage Call Self.Append Call Self.SetOrientationEx(Orientation) Call Self.SetTextRect(PosX, PosY, Width, Height) Call Self.OpenTag(kbtP, "", "", "") Column = 0 Return 0 End If End EventHandler
Property ColCount As Integer
Number of colummns
Property Column As Integer
Current column
Property Distance As Double
Space between columns
Property Height As double
Property IgnoreWarnings As Boolean
Property Orientation As Integer
Wished page orientation
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
End Class
End Project

See also:

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


The biggest plugin in space...