How to merge 2 PDF files
Posted: Thu Nov 29, 2007 7:36 pm
Hi !
What is the best way to merge 2 PDF files with GDpicture ?
Thank you !
What is the best way to merge 2 PDF files with GDpicture ?
Thank you !
Community Forums
https://www.gdpicture.com:443/forum/
Code: Select all
Sub Merge2PDF(sInPDFPath1 As String, sInPDFPath2 As String, sOutPDFpath As String)
Dim nCpt As Long
Dim nPDFID As Long
Dim nImageCount As Long
Dim GdViewer1 As Object, Imaging1 As Object
Set GdViewer1 = CreateObject("gdpicturepro5.gdviewer")
Set Imaging1 = CreateObject("gdpicturepro5.imaging")
GdViewer1.SetLicenseNumber ("LICENSE KEY")
Imaging1.SetLicenseNumber ("LICENSE KEY")
Imaging1.PdfNewPdf (sOutPDFpath)
GdViewer1.LockControl = True
nImageCount = 0
GdViewer1.DisplayFromPdfFile (sInPDFPath1)
For nCpt = 1 To GdViewer1.PageCount
GdViewer1.DisplayFrame (nCpt)
If Imaging1.PdfAddImageFromGdPictureImage(GdViewer1.GetNativeImage) <> 0 Then
nImageCount = nImageCount + 1
End If
Next nCpt
GdViewer1.CloseImage
GdViewer1.DisplayFromPdfFile (sInPDFPath2)
For nCpt = 1 To GdViewer1.PageCount
GdViewer1.DisplayFrame (nCpt)
If Imaging1.PdfAddImageFromGdPictureImage(GdViewer1.GetNativeImage) <> 0 Then
nImageCount = nImageCount + 1
End If
Next nCpt
GdViewer1.CloseImage
For nCpt = 1 To nImageCount
Call Imaging1.PdfSetPageDimensions(Imaging1.PdfGetImageWidth(nCpt), Imaging1.PdfGetImageHeight(nCpt))
Imaging1.PdfNewPage
Call Imaging1.PdfDrawImage(nCpt, 0, 0, Imaging1.PdfGetImageWidth(nCpt), Imaging1.PdfGetImageHeight(nCpt))
Imaging1.PdfEndPage
Next nCpt
Imaging1.PdfSavePdf
Set GdViewer1 = Nothing
Set Imaging1 = Nothing
End Sub
Loïc wrote: ↑Fri Nov 30, 2007 12:56 pmHi,
You can only merge existing pdf creating output images content PDF mixing the gdviewer & the imaging classes of the GdPicture Pro SDK .
I give you a simple visual basic function to merge 2 pdf :
Code: Select all
Sub Merge2PDF(sInPDFPath1 As String, sInPDFPath2 As String, sOutPDFpath As String) Dim nCpt As Long Dim nPDFID As Long Dim nImageCount As Long Dim GdViewer1 As Object, Imaging1 As Object Set GdViewer1 = CreateObject("gdpicturepro5.gdviewer") Set Imaging1 = CreateObject("gdpicturepro5.imaging") GdViewer1.SetLicenseNumber ("LICENSE KEY") Imaging1.SetLicenseNumber ("LICENSE KEY") Imaging1.PdfNewPdf (sOutPDFpath) GdViewer1.LockControl = True nImageCount = 0 GdViewer1.DisplayFromPdfFile (sInPDFPath1) For nCpt = 1 To GdViewer1.PageCount GdViewer1.DisplayFrame (nCpt) If Imaging1.PdfAddImageFromGdPictureImage(GdViewer1.GetNativeImage) <> 0 Then nImageCount = nImageCount + 1 End If Next nCpt GdViewer1.CloseImage GdViewer1.DisplayFromPdfFile (sInPDFPath2) For nCpt = 1 To GdViewer1.PageCount GdViewer1.DisplayFrame (nCpt) If Imaging1.PdfAddImageFromGdPictureImage(GdViewer1.GetNativeImage) <> 0 Then nImageCount = nImageCount + 1 End If Next nCpt GdViewer1.CloseImage For nCpt = 1 To nImageCount Call Imaging1.PdfSetPageDimensions(Imaging1.PdfGetImageWidth(nCpt), Imaging1.PdfGetImageHeight(nCpt)) Imaging1.PdfNewPage Call Imaging1.PdfDrawImage(nCpt, 0, 0, Imaging1.PdfGetImageWidth(nCpt), Imaging1.PdfGetImageHeight(nCpt)) Imaging1.PdfEndPage Next nCpt Imaging1.PdfSavePdf Set GdViewer1 = Nothing Set Imaging1 = Nothing End Sub
Best regards,
Loïc