Share via


Visual studio using VB.net or C# to edit PDF properties

Question

Friday, October 16, 2020 8:54 AM | 1 vote

HI All,

I am trying to automate to remove PDF authors in visual studio environment. The code is similar to this.

However, I can't find a build-in DLL for the visual studio for the reference. the PdfSharp.pdf was a external dll i found in the web. Just want to avoid installing outside visual studio dlls. Thanks in advance.

using System;
using PdfSharp.Pdf;
using PdfSharp.Pdf.IO;

namespace ConsoleApplication1
{
  class Program
  {
    static void Main (string[] args)
    {
      Program p = new Program();
      p.Test();

    }

    public void Test ()
    {
      PdfDocument document = PdfReader.Open ("Test.pdf");

      document.Info.Author = "ME";  --> I need DLL so it can read the variables

      document.Save ("Result");
    }
  }

All replies (4)

Friday, October 16, 2020 1:56 PM ✅Answered | 1 vote

.NET does not have any support for PDFs. You have to use a third party library. All third party libraries can be installed using NuGet. Realistically you cannot build a modern app without relying on external libraries so this is built into the infrastructure. The entire .NET Core/.NET 5 runtimes are provided via NuGet only now.

Go to your solution in Solution Explorer, right click and select Manage Nuget packages for Solution. Then Browse for the PDF library you want to use and install it in the projects that need it. You can then use the library. The build system will download the library(ies) at build time so you don't need to do anything else.

For PDF support you mentioned PdfSharp. I know nothing about that library so you can try it if you want. The other popular PDF library is iText7. Find the library that works best for your needs. For support using a specific library you'll need to post in their forums as we don't provide third-party library help here.

Michael Taylor http://www.michaeltaylorp3.net


Monday, October 19, 2020 7:49 AM ✅Answered

There is no built-in dll in .NET that supports working with pdf files. You can search and install spire.pdf library via nuget, and then add the below code to edit or remove pdf properties. 

using System;
using Spire.Pdf;

namespace PDFProperties
{
    class Properties
    {
        static void Main(string[] args)
        {
            PdfDocument document = new PdfDocument();
            document.LoadFromFile(@"E:\Documents\Sample.pdf");

            //Edit document properties
            document.DocumentInformation.Author = "Author";
            document.DocumentInformation.Title = "Title";
            document.DocumentInformation.Producer = "Producer";
            document.DocumentInformation.Keywords = ".NET, PDF";

            //Remove document properties
            //document.DocumentInformation.Author = " ";
            //document.DocumentInformation.Title = " ";
            //document.DocumentInformation.Producer = " ";
            //document.DocumentInformation.Keywords = " ";
            
            document.SaveToFile("properties.pdf");
        }
    }
}

Monday, October 19, 2020 5:29 AM

Thanks for your answer. I tried third party DLL that worked however it has a watermark on it, well we need to buy license in this case. Thanks again. 

Cheers.


Thursday, October 22, 2020 2:51 AM

nice, thanks! yes we use a third party dll. thanks for your help!!