[SOLVED] How to create a PDF file with Metadata? lazarus / 21-General ---------------------------------------------------------------------- kirchfritz · 2025-01-29 10:34 To produce a PDF-File with Metadata, I use the following sourcecode, but it doesnt create the Metadata. Who can help? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program PDFA_erstellen; {$mode objfpc}{$H+} uses  Classes, SysUtils, fpPDF, fpTTF; procedure CreatePDFA(const AFileName: string);var  PDF: TPDFDocument;  Page: TPDFPage;  Section: TPDFSection;  Font: Integer;begin  // PDF-Dokument erstellen  PDF := TPDFDocument.Create(nil);  try    PDF.StartDocument;    PDF.Options := [poPageOriginAtTop]; // Optionen festlegen     // add Metadata    PDF.Infos.Title := 'Mein PDF/A-Dokument';    PDF.Infos.Author := 'Max Mustermann';    PDF.Infos.Producer := 'Lazaurus and fpPDF';//    PDF.Infos. Subject := 'Beispiel für PDF/A mit Metadaten';    PDF.Infos.Keywords := 'PDF/A, Lazarus, Metadaten';    PDF.Infos.CreationDate := Now;     // Add a section, at least one section is needed.    Section:=PDF.Sections.AddSection;     // Eine Seite hinzufügen    Page := PDF.Pages.AddPage;    Page.PaperType := ptA4;    Page.UnitOfMeasure := uomMillimeters;     Section.AddPage(Page);     // Eine Schriftart laden (z. B. Arial)    Font := PDF.AddFont('C:\10_Fonts\WinnerBold.ttf','WinnerBold');     // Text auf der Seite hinzufügen    Page.SetFont(Font, 12);    Page.WriteText(20, 20, 'Hallo, dies ist vielleicht eine PDF/A Datei!');     // PDF-Datei speichern    PDF.SaveToFile(AFileName);  finally    PDF.Free;  end;end; begin  CreatePDFA('meine_datei2.pdf');end. ---------------------------------------------------------------------- rvk · 2025-01-29 10:53 You need to add poMetadataEntry to the PDF.Options. BUT... also... you need to move the line with PDF.Options := above PDF.StartDocument because the StartDocument needs that metadata option set. ---------------------------------------------------------------------- kirchfritz · 2025-01-29 11:06 Thanks rvk! With your modifications my program runs like a charm. PROBLEM SOLVED! ---------------------------------------------------------------------- madref · 2025-01-29 12:34 I have an additional question: Is this also possible if you export the pdf like this? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i       if frReport_Evaluatie.PrepareReport then        frReport_Evaluatie.ExportTo(TlrPdfExportFilter, UserDir + 'Declaration_Empty' + '.pdf'); ---------------------------------------------------------------------- rvk · 2025-01-29 12:46 Quote from: madref on January 29, 2025, 01:34:04 pmIs this also possible if you export the pdf like this? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i       if frReport_Evaluatie.PrepareReport then        frReport_Evaluatie.ExportTo(TlrPdfExportFilter, UserDir + 'Declaration_Empty' + '.pdf'); Yes, if you include the LazReportPDFExport package. Search for PDF on this page: https://wiki.freepascal.org/LazReport_Documentation ---------------------------------------------------------------------- madref · 2025-01-29 22:45 maybe I am blind but I can't find it ---------------------------------------------------------------------- rvk · 2025-01-30 11:08 Quote from: madref on January 29, 2025, 11:45:29 pmmaybe I am blind but I can't find it Package > Install/Uninstall Packages type pdf in "Available for installation" and choose lazreportpdfexport and "Install Selection" Press Rebuild IDE ---------------------------------------------------------------------- madref · 2025-02-01 05:13 ooooh that I have already installed... but the actual code I can't find anywhere a.k.a. how to set the metadata? ---------------------------------------------------------------------- paweld · 2025-02-01 06:09 @madref: To set the author and title in a PDF file, you don't need to enable poMetadataEntry. Here I have posted a fix that sets the author and title in the pdf file from the report options: https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/41392