« xDev Magazine 21.4 | Home | MBS Xojo Plugins, ver… »

Create PDF/UA with DynaPDF Starter

Now you got our MBS Xojo DynaPDF Plugin (e.g. with OmegaBundle) and you like to make a PDF with PDF/UA standard. That means your PDF includes tags for accessibility. So instead of just having text pieces on the page, they each haves tags to classify whether they are heading, paragraph, quote, label or similar thing.

You build your PDF and do a few extra steps for the PDF:

  • You need to define the viewer preferences to show the display title.
  • The language needs to be set, e.g. to en-EN.
  • The structure tree needs to be created, so we have a root.
  • The PDF version is set use to kpvPDFUA1.
  • When adding content, you call OpenTag/CloseTag to annotate your content.

For debugging, it can be helpful to set the compression level to zero for a PDF and thus be able to just drop the PDF on a text editor and see what is inside.

Here is a little sample code for you:

Dim pdf As New DynaPDFMBS Dim f As FolderItem = SpecialFolder.Desktop.Child("Create PDF.pdf") Call pdf.CreateNewPDF f // 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 // Set to write text block Call pdf.SetTextRect(50, 50, pdf.GetPageWidth - 2.0 * 50.0, pdf.GetPageHeight - 2.0 * 50.0) // set a font Call pdf.SetFont("Arial", pdf.kfsRegular) // The root node btDocument was already created by CreateStructureTree(). // create a paragraph tag Call pdf.OpenTag(pdf.kbtP, "", "", "") // put in content Call pdf.WriteFText(pdf.ktaLeft, "Hello World"+EndOfLine+"Second line") // and close the tag 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

Please try and let us know if you have questions.

The biggest plugin in space...
05 07 23 - 08:09