#1 2023-12-28 12:26:02

padule
Member
Registered: 2023-07-19
Posts: 24

PDF Info (title etc) not saved in PDF version >1.3

If I put a custom title in the PDF Info, it works as long as the PDF version is 1.3.
Whenever I use a function that bumps the PDF version to >1.3 (eg. pdf.UseOptionalContent := true;) then the PDF Info is not saved anymore, and the title is lost.

Is this normal?

Offline

#2 2023-12-28 16:08:11

rvk
Member
Registered: 2022-04-14
Posts: 115

Re: PDF Info (title etc) not saved in PDF version >1.3

padule wrote:

Is this normal?

Works fine for me (with latest mORMot 2 sources).

What version of code are you using?
(otherwise a small sample would be helpful)

This works for me (generates a 1.5 PDF):

procedure MakePdfSynPdf;
var
  FileTemp: string;
  pdf: TPdfDocumentGDI;
begin
  FileTemp := 'C:\Temp\Test1.pdf';
  pdf := TPdfDocumentGDI.Create;
  try
    pdf.UseOptionalContent := true;
    pdf.Info.Title := 'Title name';
    pdf.Info.Author := 'User name';
    pdf.Info.Creator := 'Software name';
    pdf.Info.subject := 'Auto generated document';

    // page 1
    { page := } pdf.AddPage;
    pdf.VCLCanvas.Font.Name := 'Times New Roman';
    pdf.VCLCanvas.Font.size := 24;
    pdf.VCLCanvas.TextOut(100, 100, 'some text on page 1');

    // page 2
    { page := } pdf.AddPage;
    pdf.VCLCanvas.Font.Name := 'Times New Roman';
    pdf.VCLCanvas.Font.size := 24;
    pdf.VCLCanvas.TextOut(100, 100, 'some text on page 2');

    // back to page 1
    pdf.Canvas.SetPage(pdf.RawPages[0]);
    pdf.VCLCanvas.Font.Name := 'Times New Roman';
    pdf.VCLCanvas.Font.size := 24;
    pdf.VCLCanvas.TextOut(200, 200, 'some extra text on page 1');

    pdf.SaveToFile(FileTemp);

    ExecAssociatedApp(FileTemp);

  finally
      pdf.Free;
  end;

end;

Offline

#3 2023-12-29 11:18:59

padule
Member
Registered: 2023-07-19
Posts: 24

Re: PDF Info (title etc) not saved in PDF version >1.3

Thank you very much for your attempt, and thanks to this I found out the problem.
I was using pdf.UseOptionalContent := true; after setting the Info data, and this will not work.
So the correct way to use it is setting the UseOptionalContent to true as first thing, then setting the Info data.

This is indeed documented in the code, so it was an overlook on my part, my mistake.
Thank you again.

Offline

Board footer

Powered by FluxBB