Set Document Information for a PDF

The code below shows you how to set Document Information for a PDF file.

This sample requires a Tools license.

C#
using System;
using SolidFramework.Pdf;

namespace PDFDocInfo
{
    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            // Call your Solid Documents License
            SolidFramework.License.Import(@"C:\MyFolder\license.xml");

            // Set the location of your the file you want to convert
            String pdfPath = @"C:\YourFolder\yourpdf.pdf";

            //*PDF Document Information*//

            // Create a new PdfDocument Object called document and assign the selected PDF file to it 
            using (PdfDocument document = new PdfDocument(pdfPath))
            {
                // Open the file
                document.Open();

                // Assign some document information values
                document.Info.Author = "Sample Author";
                document.Info.Subject = "My sample PDF";

                // If the document has been modified, save it

                if (document.IsModified)
                {
                    document.Save(SolidFramework.Plumbing.OverwriteMode.ForceOverwrite);
                }
            }
        }
    }
}

C++
#include "stdafx.h"
#include "SolidFramework.h"

using namespace std;

int main()
{
    // Call your Solid Documents License
    SolidFramework::License::Import(L"c:\\MyFolder\\yourlicense.xml");

    // Add the PDF file to convert
    wstring pdfPath(L"c:\\YourFolder\\yourpdf.pdf");

    //*PDF Document Information*//

    // Create a new PdfDocument Object called document and assign the selected PDF file to it 
    SolidFramework::Pdf::PdfDocumentPtr document(new SolidFramework::Pdf::PdfDocument(pdfPath));

    // Open the file
    document->Open();

    // Assign some document information value.    
    document->getInfo()->setAuthor(L"Sample Author");
    document->getInfo()->setSubject(L"My sample PDF");

    // If the document has been modified, save it
    if (document->getIsModified())
    {
        document->SaveAs(pdfPath, SolidFramework::Plumbing::OverwriteMode::ForceOverwrite);
    }

    document->Close();
    document->Dispose();

    return 0;
}
VB.Net
Imports SolidFramework.Plumbing
Imports SolidFramework.Pdf

Module PDFDocInfo

    Sub Main()

        ' Call your Solid Documents License
        SolidFramework.License.Import("C:\MyFolder\license.xml")

        'Define a variable for your source file
        Dim sPdfPath As String

        ' Define a PDF Document object
        Dim myDocument As SolidFramework.Pdf.PdfDocument

        ' Set values to your variables 
        sPdfPath = "C:\YourFolder\filepdf.pdf"
        myDocument = New PdfDocument(sPdfPath)

        ' Open the file
        myDocument.Open(sPdfPath)

        ' Assign some document information values
        myDocument.Info.Author = "New PDF Author"
        myDocument.Info.Subject = "New PDF Subject"

        ' If the document has been modified, save it
        If myDocument.IsModified Then
            myDocument.Save(OverwriteMode.ForceOverwrite)
        End If

        ' Clean up
        myDocument.Close()
        myDocument.Dispose()

    End Sub

End Module