Platforms to show: All Mac Windows Linux Cross-Platform

/DynaPDF/Create PDF UA

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

This example is the version from Sat, 16th Jun 2023.

Project "Create PDF UA.xojo_binary_project"
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 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 // Required! The document title must be displayed Call pdf.SetViewerPreferences(pdf.kvpDisplayDocTitle, pdf.kavNone) // Required! The language must be set too Call pdf.SetLanguage "en-EN" // PDF/UA files are Tagged PDF files. So, a structure tree is required. Call pdf.CreateStructureTree // set version to PDF/UA-1 Call pdf.SetPDFVersion(pdf.kpvPDFUA1) If pdf.Append Then // Setup the output text rectangle // this are properties in our subclass. pdf.Orientation = 0 pdf.ColCount = 2 pdf.Column = 0 pdf.Distance = 5.0 pdf.PosX = 50.0 pdf.PosY = 50.0 pdf.Height = pdf.GetPageHeight - 2.0 * pdf.PosX pdf.Width = ((pdf.GetPageWidth - 2.0 * pdf.PosX) - (pdf.ColCount -1) * pdf.Distance) / pdf.ColCount // Set the default output rectangle Call pdf.SetTextRect(pdf.PosX, pdf.PosY, pdf.Width, pdf.Height) Call pdf.SetFont("Arial", pdf.kfsRegular, 10.0, True, pdf.kcpUnicode) // The root node btDocument was already created by CreateStructureTree(). Call pdf.OpenTag(pdf.kbtP, "", "", "") Call pdf.WriteFText(pdf.ktaLeft, SampleText+SampleText+SampleText) Call pdf.CloseTag // The tag btFigure requires the bounding box of the object. Dim bbox As New DynaPDFRectMBS(50.0, 450.0, 200.0, 500.0) Call pdf.OpenTag(pdf.kbtFigure, "", "Rectangle", "", bbox) Call pdf.Rectangle(bbox.Left, bbox.Right, bbox.Width,, pdf.kfmStroke) Call pdf.CloseTag Call pdf.EndPage End If #if DebugBuild then // for debugging, don't compress this pdf Call pdf.SetCompressionLevel(0) #endif 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
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...