Question:I have various PDF files say file1.pdf, file2.pdf.......... Now I want to create a new PDF document say MainDoc.pdf. And this MainDoc.pdf will contain File1.pdf,File2.pdf... as attachments.Tried this code but it is giving error, I hope I can find a solution on VeryPDF?
Answer:According to your needs, maybe you can have a free trial of this software: VeryPDF Advanced PDF Tools Command Line, by which you can add attachment to PDF either by command line or together with other application like C#. By this software, you can also edit PDF description, PDF custom description, PDF OpenAction options, PDF page view options, PDF metadata contents, and so on. Please check more information of this software on homepage in the following part, let us check how to use this software.
Step 1. Download Advanced PDF Tools Command Line
- As this is command line version software, when downloading finishes, there will be a zip file in downloading folder. Please extract it to some folder then you can use it normally.
- This is command line version I download here. If you need to use the SDK version, there is also available, which is much more easier to call it from C#.
Step 2. Add attachment to PDF
- When you use this software, please refer to the usage of this software.
- Usage:[options] { [-i ] "input-file" } "output-file"
- Here are some example for your reference for adding attachment to PDF:
- When call this software from C# for adding attachment to PDF, please refer to the following code templates:
Attach various files to PDF files:
pdftools -S "attachfiles=C:\1.pdf|C:\2.pdf|C:\3.pdf" -i C:\in.pdf -o C:\out.pdf
pdftools -S "attachfiles=C:\*.*" -i C:\in.pdf -o C:\out.pdf
pdftools -S "attachfiles=C:\filelist.lst" -i C:\in.pdf -o C:\out.pdf
pdftools -S collection=true -S "attachfiles=C:\filelist.lst" -i C:\in.pdf -oC:\out.pdf
Related parameters, please have a check.
-S "attachfiles=file1|file2|file3|file4" : Attach files into PDF file
e.g. -S "attachfiles=C:\1.txt|C:\2.jpg|C:\3.pdf"
-S "attachfiles=C:\filelist.lst" : Retrieve files from a .txt file
-S "collection=true" : Enable collection feature for attachments
-S "collection=false" : Disable collection feature for attachments
#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 \"-$\" \"%s\" -S \
"attachfiles=C:\1.pdf|C:\2.pdf|C:\3.pdf\" -i \"%s\" -o \"%s\"",
lpLicenseKey, "C:\\test.pdf", "C:\\_test.pdf");
int nRet = VeryPDF_PDFTools(szCommandLine);
}
During the using, if you have any question, please contact us as soon as possible.