<< Click to Display Table of Contents >> Navigation: Direct Calls to DLL > pdfMerge / pdfMergeW - Merge PDF files (PLUS Edition) |
If you need to merge different PDF and create one new file you can use the function pdfMerge. It receives the license codes and a list of files (comma delimited) .
The PLUS addon comes with an extra DLL "tiff_to_pdf.dll" which helps to also merge black and white TIF files which were produced by a scanner as if they were PDF files!
Please place this DLL in the same directory as the WPViewPDF main DLL.
If you intend to use the pdfMerge function (or the stamping feature) on an internet or intranet server, you need a special WEB-License. Please see order page.
Please note: pdfMerge expects char * parameters which are ANSI characters. If the filename can contain special characters/umlauts it is better to use pdfMergeW and pass 2 byte unicodes. In both cases the strings have to be terminated by \0.
Private Declare Function pdfMerge Lib "wPDFViewPlus05.dll" ( _
ByVal strFilenames As String, _
ByVal strNewFile As String, _
ByVal strPassword As String, _
ByVal strLicName As String, _
ByVal strLicKey As String, _
ByVal lngLicCode As Long, _
ByVal lngLicPlusCode As Long, _
ByVal strOptions As String _
) As Long
Example - merge a.pdf and b.pdf and extract a total of 4 pages into an encrypted file:
Dim i
i = pdfMerge("""a.pdf"",""b.pdf""", "out.pdf", "", "licname", "lickey", 0, 0, _
"""PAGELIST=1-3,5"",""UPASSWORD=123""")
(Note: to escape a " in VB6 type "" )
Tip: This works in ASP .NET. If you need to use this method in the "old" ASP You can use VB to create a simple ActiveX class which exports just this method.
Public Function pdfMerge_Access(ByVal strFilenames As String, ByVal strNewFile As String) As Long
pdfMerge_Access = pdfMerge(strFilenames, strNewFile, "", LicName, LicKey, LicCode, LicPlusCode, "")
End Function
stdcall int pdfMerge(char *filenames, char *newfile, char *password,
char *licname, char *lickey, uint liccode, uint licpluscode,
char *options);
fktpdfMerge = function(filename: PAnsiChar; newfile: PAnsiChar;
password: PAnsiChar; licname, lickey: PAnsiChar; liccode: Cardinal;
licpluscode: Cardinal; options: PAnsiChar): Integer; stdcall;
fktpdfMergeW = function(filename: PWideChar; newfile: PWideChar;
password: PWideChar; licname, lickey: PWideChar; liccode: Cardinal;
options: PWideChar): Integer; stdcall;
Note: The unit WPViewPDF initializes the function pointer wpview_.... which can be used directly:
wpview_pdfMerge: fktpdfMerge;
wpview_pdfMergeW: fktpdfMergeW;
are initialized by the function WPViewPDFLoadDLL(DLLName: string; Quiet : Boolean = FALSE): Boolean; which is called automatically when a viewer will be created but can also be called directly.
// using System.Runtime.InteropServices;
[DllImport("wPDFViewPlus04.dll", CharSet=CharSet.Ansi)]
public static extern int pdfMerge(string filenames, string newfile, string password,
string license_name, string license_key, int license_code, int license_plus_code,
string options);
Parameters:
filename: a list of filenames separated using comma, each filename in double quotes: "a.pdf","b.pdf","c.pdf"
newfile: the name of the new PDF file which should be created
password: the user password which should be used to open a PDF file
licname: your license name
lickey: the license key
liccode: the license code
licpluscode: obsolete, not used.
options:
This is a string with options, separated by comma
"DEBUG=1" switches on the debug mode. See debug console for messages
"CHECKEXIST=1" files which do not exist will be ignored (creates also debug message)
"TIFF2PDF=path" full path to converter DLL
"LOGFILE=path" logs errors in the specified file. Can be combined with DEBUG=1
"PAGELIST=1,2,3,10-15" merges the input files but only saves the pages in the list
"UPASSWORD=a" Set the user password for the new file to "a"
"OPASSWORD=b" Set the owner password for the new file to "b"
"SECURITY=x" Set the security PFlags
Bit 3: Enable Print (default)
Bit 4: Allow Modification
Bit 5: Copy
Bit 6: Add Annotations
"COPY_NON_ENCRYPTED=1" pdfMerge will simply copy the original file if only one source file was specified and that source file was not encrypted.
This method is useful if pdfMerge is only used to decrypt PDF files. Do not use this option if you need to apply security!
"DeletePDFAFlag=1" will remove any PDFA marker
"DeletePDFMarks=1" will remove the StructTree, akn as PDF Tags
"DELETESOURCE=1" After loading the input files, they are all (!) deleted.
"DeleteFormFields=1" Removes the widget annotations when saving the file.
"FlattenFormFields=1" Applies the appearance streams of the annotations to the PDF file and remove the annotation.
"SaveMode=xx" Sets the save mode using an integer value as used by COMPDF_SetSaveOptions
"PASSWORDxxx=..." additional up to 999 user password to open the PDF files. (xxx is a numer between 1 and 999)
"STAMPFILE=sometextfile.txt" After loading the input files, a stamp script loaded from a file will be applied.
The script uses the same syntax as the command COMPDF_StampText.
"STAMPTEXT=...." uses the provided text as stamp script. It may not contain any quotes. CRNL must be encoded as \r\n since otherwise the options cannot be loaded correctly.
Example Delphi: options := options + ',"STAMPTEXT=' +
StringReplace(StampScript.Lines.Text, #13+#10, '\r\n', [rfReplaceAll])
+ '"';
In case the user password or the owner password is set, the file will be encrypted with 128 bit RC4 security.
Result
The Result is >0 if the operation was successful.
Result = -3 if one or more files could not be converted. You can use the logging to find the problem, i.e. a file could not be found.