Question:I am searching for methods or libraries to edit metadata of a PDF file. I want to write a program and I need this option in this program. Perhaps you have some samples for c#. Is there any solution on VeryPDF?
Answer: When you need to edit metadata from C#, maybe you can have a free trial of this software VeryPDF Advanced PDF Tools SDK, by which you can edit metadata by two methods. Meanwhile the SDK version provides libraries to edit metadata of a PDF file. One method is that you can edit metadata by editing title, author and others separately and the other is editing metadata by output metadata to XML file and then edit them in XML file. After editing, you can import XML file back to PDF file. Please get more information of this software on homepage, in the following part, I will show you how to use this software.
Step 1. Free download Advanced PDF Tools SDK
- Please download the SDK version as there are some code templates of calling this software from other programming languages.
- When downloading finishes, please extract it to some folder then you can call it from C# more easily.
Step 2. Edit metadata from C#.
- When you need to edit metadata from C#, you may need the following parameters, please have a check.
- Now let us check how to call it from C#.
-t "Title" : Set title
-a "Author" : Set author
-s "Subject" : Set subject
-k "Keywords" : Set keywords
-d "CreatedDate" : Set create date
-m "ModifyDate" : Set modify date
-c "Creator" : Set creator
-p "Producer" : Set producer
-D : Write document summaries into PDF file in ASCII
-e "MetaData" : Set MetaData, select a XML file for set metadata or "" to clear metadata
Here are some code templates:
pdftools -i c:\input.pdf -e "c:\metadata.xml"
pdftools -i c:\input.pdf -o c:\out.pdf -t title -s subject -l c:\err.log
pdftools -i c:\input.pdf -t title -a author -k "123,456" -d "2003-11-11"
pdftools -i c:\input.pdf -k "+PDF Tools"
pdftools -i c:\pdfdir\*.pdf -o d:\ -s subject -k "book,rtf,doc,text,pdf"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <io.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <conio.h>
#include <ctype.h>
#include <windows.h>
__declspec(dllexport)
int WINAPI VeryPDF_PDFTools(LPCTSTR lpCommand);
void main()
{
char szCommandLine[1024];
char *lpLicenseKey = "XXXXXXXXXXXXXX";
sprintf(szCommandLine,""pdftools.exe \"-e="c:\metadata.xml"\
\" -i \"%s\" -o \"%s\"",
lpLicenseKey, "C:\\test.pdf", "C:\\_test.pdf");
int nRet = VeryPDF_PDFTools(szCommandLine);
}
Please note when you need to export XML file for editing metadata, please make sure import XML file back by the following command line template:
pdftools -i c:\input.pdf -o D:\out.pdf -e "c:\metadata.xml"
By this method, you can edit metadata from C# easily. During the using, if you have any question, please contact us as soon as possible.