Muhammad Idris Posted February 8 Share Posted February 8 how to combine pdf files into one file with UniSession.SendFile ? The code I made can only download multiple files, it can't combine into one PDF file : QBiaya.Close; QBiaya.SQL.Clear; QBiaya.SQL.Add('SELECT ROW_NUMBER() OVER(ORDER BY A.Id_Hasil ASC) AS Nmr,A.*,C.NAMALENGKAP '+ 'FROM ASESMEN_HASIL_PENUNJANG_LAINNYA_PDF AS A '+ 'INNER JOIN TUSER AS C ON A.NAMAUSER=C.NAMAUSER '+ 'WHERE A.NO_REG = '+QuotedStr(noreg)+' '+ 'ORDER BY A.Id_Hasil'); QBiaya.Open; QBiaya.First; while Not QBiaya.Eof do begin CopyFile(pchar(UniMainModule.folderPath+QBiayaNama_File.AsString),pchar(UniServerModule.LocalCachePath+'\'+QBiayaNama_File.AsString),false); pathfile:=trim( Copy(UniServerModule.LocalCachePath,AnsiPos('cache',UniServerModule.LocalCachePath),length(UniServerModule.LocalCachePath))); UniSession.SendFile(UniServerModule.LocalCachePath+'\'+QBiayaNama_File.AsString); QBiaya.Next; end; Quote Link to comment Share on other sites More sharing options...
Sherzod Posted February 8 Share Posted February 8 7 minutes ago, Muhammad Idris said: The code I made can only download multiple files And that's not a fact either. Quote Link to comment Share on other sites More sharing options...
Muhammad Idris Posted February 8 Author Share Posted February 8 16 minutes ago, Sherzod said: And that's not a fact either. So is there a solution so that several PDF files can become one PDF file? Quote Link to comment Share on other sites More sharing options...
Sherzod Posted February 8 Share Posted February 8 50 minutes ago, Muhammad Idris said: So is there a solution so that several PDF files can become one PDF file? Sorry, this is outside the scope of uniGUI and I don't have a solution at the moment. Quote Link to comment Share on other sites More sharing options...
picyka Posted February 8 Share Posted February 8 1 hora atrás, Muhammad Idris disse: Então, existe uma solução para que vários arquivos PDF possam se tornar um arquivo PDF? I have a routine here that can generate thousands of PDFs, and the solution to downloading them was simple. Just get all pdf and zip it. Download the zip and be happy. Quote Link to comment Share on other sites More sharing options...
andyhill Posted February 8 Share Posted February 8 I build my PDF files at runtime, firstly as HTML Files, then finally converting to PDF so I believe it would be relatively easy to CONCATINATE multiple HTML files before conversion into one PDF. Quote Link to comment Share on other sites More sharing options...
picyka Posted February 9 Share Posted February 9 What do you use to convert from html to pdf? Quote Link to comment Share on other sites More sharing options...
Muhammad Idris Posted February 9 Author Share Posted February 9 Yes, I also want to know how to convert from HTML to PDF? because my needs are not just one click download into one file, but this actually combines file1.pdf with file2.pdf into one pdf file and becomes 2 pages. like that for example Quote Link to comment Share on other sites More sharing options...
andyhill Posted February 9 Share Posted February 9 3 hours ago, picyka said: What do you use to convert from html to pdf? HtmlLib from delphihtmlcomponents.com 1 1 Quote Link to comment Share on other sites More sharing options...
Fred Montier Posted February 10 Share Posted February 10 There are tens of vcl pdf libs you can do that. Even JS libs. PDFium is just one of them and it is free. Not related to uniGUI at all. Quote Link to comment Share on other sites More sharing options...
picyka Posted February 11 Share Posted February 11 On 2/9/2024 at 10:54 PM, Fred Montier said: Existem dezenas de bibliotecas pdf vcl que você pode fazer isso. Até mesmo JS libs. PDFium é apenas um deles e é gratuito. Não está relacionado à uniGUI. Does PdfiumLib convert html to pdf? Quote Link to comment Share on other sites More sharing options...
Kurt Posted February 12 Share Posted February 12 i use pdftk for this. you can try it out. its free 1 Quote Link to comment Share on other sites More sharing options...
Muhammad Idris Posted March 1 Author Share Posted March 1 On 2/12/2024 at 7:46 AM, Kurt said: i use pdftk for this. you can try it out. its free How to run it in Unigui? Quote Link to comment Share on other sites More sharing options...
Kurt Posted March 3 Share Posted March 3 On 3/2/2024 at 12:39 AM, Muhammad Idris said: How to run it in Unigui? 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 Quote Link to comment Share on other sites More sharing options...
Muhammad Idris Posted March 13 Author Share Posted March 13 On 3/3/2024 at 10:34 PM, Kurt said: 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 Thank you sir, I tried but couldn't create a PDF and how do I get the PDF file to be taken from a loop like this? QBiaya.Close; QBiaya.SQL.Clear; QBiaya.SQL.Add('SELECT ROW_NUMBER() OVER(ORDER BY A.Id_Hasil ASC) AS Nmr,A.*,C.NAMALENGKAP '+ 'FROM ASESMEN_HASIL_PENUNJANG_LAINNYA_PDF AS A '+ 'INNER JOIN TUSER AS C ON A.NAMAUSER=C.NAMAUSER '+ 'WHERE A.NO_REG = '+QuotedStr(noreg)+' '+ 'ORDER BY A.Id_Hasil'); QBiaya.Open; QBiaya.First; while Not QBiaya.Eof do begin CopyFile(pchar(UniMainModule.folderPath+QBiayaNama_File.AsString),pchar(UniServerModule.LocalCachePath+'\'+QBiayaNama_File.AsString),false); pathfile:=trim( Copy(UniServerModule.LocalCachePath,AnsiPos('cache',UniServerModule.LocalCachePath),length(UniServerModule.LocalCachePath))); UniSession.SendFile(UniServerModule.LocalCachePath+'\'+QBiayaNama_File.AsString); QBiaya.Next; end; for Path in TDirectory.GetFiles(UniServerModule.LocalCachePath+'\') do begin UniListBox1.Items.Add(ExtractFileName( Path )); end; OutPdf := UniServerModule.NewCacheFile('pdf', fileName); MergeAndEncryptPDFs('EKG MADAA.pdf,KULTUR MADAA.pdf', OutPdf, ''); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.