From cc4cce818937dc13b11e0837acbbce010e0190ad Mon Sep 17 00:00:00 2001 From: icnocop Date: Wed, 10 Apr 2019 17:46:49 -0700 Subject: [PATCH] Allow setting the PdfDocument.Info.Producer property From https://github.com/2Toad/PDFsharp/commit/f53f15a95f5cb5d7aa0c99329764eb5c5ea3afe1 --- .gitignore | 6 +++--- src/PdfSharp/Pdf/PdfDocument.cs | 14 +++----------- src/PdfSharp/Pdf/PdfDocumentInformation.cs | 3 ++- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index ef5f1b7f..9047075d 100644 --- a/.gitignore +++ b/.gitignore @@ -22,7 +22,7 @@ bld/ [Bb]in/ [Oo]bj/ -# Visual Studo 2015 cache/options directory +# Visual Studio 2015 cache/options directory .vs/ # MSTest test Results @@ -90,7 +90,7 @@ _ReSharper*/ *.[Rr]e[Ss]harper *.DotSettings.user -# JustCode is a .NET coding addin-in +# JustCode is a .NET coding add-in .JustCode # TeamCity is a build add-in @@ -129,7 +129,7 @@ publish/ # Publish Web Output *.[Pp]ublish.xml *.azurePubxml -# TODO: Comment the next line if you want to checkin your web deploy settings +# TODO: Comment the next line if you want to checkin your web deploy settings # but database connection strings (with potential passwords) will be unencrypted *.pubxml *.publishproj diff --git a/src/PdfSharp/Pdf/PdfDocument.cs b/src/PdfSharp/Pdf/PdfDocument.cs index fe1b9af5..7995c6d1 100644 --- a/src/PdfSharp/Pdf/PdfDocument.cs +++ b/src/PdfSharp/Pdf/PdfDocument.cs @@ -462,17 +462,9 @@ internal override void PrepareForSave() if (info.Elements[PdfDocumentInformation.Keys.Creator] == null) info.Creator = pdfSharpProducer; - // Keep original producer if file was imported. - string producer = info.Producer; - if (producer.Length == 0) - producer = pdfSharpProducer; - else - { - // Prevent endless concatenation if file is edited with PDFsharp more than once. - if (!producer.StartsWith(VersionInfo.Title)) - producer = pdfSharpProducer + " (Original: " + producer + ")"; - } - info.Elements.SetString(PdfDocumentInformation.Keys.Producer, producer); + // Set Producer if value is undefined + if (info.Elements[PdfDocumentInformation.Keys.Producer] == null) + info.Producer = VersionInfo.Producer; // Prepare used fonts. if (_fontTable != null) diff --git a/src/PdfSharp/Pdf/PdfDocumentInformation.cs b/src/PdfSharp/Pdf/PdfDocumentInformation.cs index 11149571..e8d6ae49 100644 --- a/src/PdfSharp/Pdf/PdfDocumentInformation.cs +++ b/src/PdfSharp/Pdf/PdfDocumentInformation.cs @@ -93,11 +93,12 @@ public string Creator } /// - /// Gets the producer application (for example, PDFsharp). + /// Gets or sets the name of the producer application (for example, PDFsharp). /// public string Producer { get { return Elements.GetString(Keys.Producer); } + set { Elements.SetString(Keys.Producer, value); } } ///