install pdftk in your environment
and you can use this code:
procedure MergeAndEncryptPDFs(const AInputFiles: string; const AOutputFile: string; const AUserPassword: string);
var
CommandLine: string;
StartupInfo: TStartupInfo;
ProcessInfo: TProcessInformation;
begin
CommandLine := 'pdftk ' + AInputFiles + ' cat output ' + AOutputFile + ' user_pw ' + AUserPassword;
FillChar(StartupInfo, SizeOf(StartupInfo), 0);
StartupInfo.cb := SizeOf(StartupInfo);
if CreateProcess(nil, PChar(CommandLine), nil, nil, False, 0, nil, nil, StartupInfo, ProcessInfo) then
begin
WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
CloseHandle(ProcessInfo.hProcess);
CloseHandle(ProcessInfo.hThread);
end
else
raise Exception.Create('not created');
end;
to call it:
procedure TMainForm.UniButton1Click(Sender: TObject);
var
OutPdf: string;
begin
OutPdf := UniServerModule.NewCacheFile('pdf', fileName);
MergeAndEncryptPDFs('example1.pdf,example2.pdf', OutPdf, '');
end;
you can modify the code to omit the password protection for your pdf.
hope it helps