From b9932dd4fd6de355f299c3661fb41f0d958e28d8 Mon Sep 17 00:00:00 2001 From: Julien R Date: Mon, 16 Oct 2023 16:12:35 +0200 Subject: [PATCH 1/2] do not replace existing XMP metadata if any we should not simply replace and lose existing XMP metadata if any already set --- src/foundation/src/PDFsharp/src/PdfSharp/Pdf/PdfDocument.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/foundation/src/PDFsharp/src/PdfSharp/Pdf/PdfDocument.cs b/src/foundation/src/PDFsharp/src/PdfSharp/Pdf/PdfDocument.cs index c5054814..7eb47e7e 100644 --- a/src/foundation/src/PDFsharp/src/PdfSharp/Pdf/PdfDocument.cs +++ b/src/foundation/src/PDFsharp/src/PdfSharp/Pdf/PdfDocument.cs @@ -436,7 +436,8 @@ internal override void PrepareForSave() // @PDF/UA // Create PdfMetadata now to include the final document information in XMP generation. - Catalog.Elements.SetReference(PdfCatalog.Keys.Metadata, new PdfMetadata(this)); + if (!Catalog.Elements.ContainsKey(PdfCatalog.Keys.Metadata) || Catalog.Elements.GetReference(PdfCatalog.Keys.Metadata) == null) + Catalog.Elements.SetReference(PdfCatalog.Keys.Metadata, new PdfMetadata(this)); } /// From a8dda526648f45eab6e5784b6aba1b727ae388e2 Mon Sep 17 00:00:00 2001 From: Julien R Date: Mon, 16 Oct 2023 17:18:22 +0200 Subject: [PATCH 2/2] XMP metadata automatic/manual is now a document option in order to have full control --- .../src/PDFsharp/src/PdfSharp/Pdf/PdfDocument.cs | 2 +- .../PDFsharp/src/PdfSharp/Pdf/PdfDocumentOptions.cs | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/foundation/src/PDFsharp/src/PdfSharp/Pdf/PdfDocument.cs b/src/foundation/src/PDFsharp/src/PdfSharp/Pdf/PdfDocument.cs index 7eb47e7e..72a5db6c 100644 --- a/src/foundation/src/PDFsharp/src/PdfSharp/Pdf/PdfDocument.cs +++ b/src/foundation/src/PDFsharp/src/PdfSharp/Pdf/PdfDocument.cs @@ -436,7 +436,7 @@ internal override void PrepareForSave() // @PDF/UA // Create PdfMetadata now to include the final document information in XMP generation. - if (!Catalog.Elements.ContainsKey(PdfCatalog.Keys.Metadata) || Catalog.Elements.GetReference(PdfCatalog.Keys.Metadata) == null) + if (Options.ManualXmpGeneration == false) Catalog.Elements.SetReference(PdfCatalog.Keys.Metadata, new PdfMetadata(this)); } diff --git a/src/foundation/src/PDFsharp/src/PdfSharp/Pdf/PdfDocumentOptions.cs b/src/foundation/src/PDFsharp/src/PdfSharp/Pdf/PdfDocumentOptions.cs index fcc8df71..5909f17b 100644 --- a/src/foundation/src/PDFsharp/src/PdfSharp/Pdf/PdfDocumentOptions.cs +++ b/src/foundation/src/PDFsharp/src/PdfSharp/Pdf/PdfDocumentOptions.cs @@ -81,5 +81,17 @@ public PdfUseFlateDecoderForJpegImages UseFlateDecoderForJpegImages set => _useFlateDecoderForJpegImages = value; } PdfUseFlateDecoderForJpegImages _useFlateDecoderForJpegImages = PdfUseFlateDecoderForJpegImages.Never; + + /// + /// Gets or sets a value indicating whether XMP metadata will be generated manually. + /// true (manual): XMP metadata has to be built and attached manually via class. + /// false (auto): XMP metadata will be built and attached automatically. + /// + public bool ManualXmpGeneration + { + get => _manualXmpGeneration; + set => _manualXmpGeneration = value; + } + bool _manualXmpGeneration = false; } }