Page 1 of 1

How to merge 2 PDF files

Posted: Thu Nov 29, 2007 7:36 pm
by paulo moura
Hi !

What is the best way to merge 2 PDF files with GDpicture ?

Thank you !

Posted: Fri Nov 30, 2007 12:56 pm
by Loïc
Hi,

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

Re: How to merge 2 PDF files

Posted: Fri May 29, 2009 6:03 pm
by TMCjason
How can I get this to work with GdPicture.NET?

Re: How to merge 2 PDF files

Posted: Sat May 30, 2009 10:54 am
by Loïc
For GdPicture.NET see: viewtopic.php?t=1583

Re: How to merge 2 PDF files

Posted: Wed Sep 14, 2011 2:50 pm
by arcadyAbr
Hello, I am having an "Out of Memory" error when I try to open the resulting file in Acrobat X. What should I be looking at?
I work in PowerBuilder11.5 and this is my code:
//------------------------------------------
inv_imaging.PdfNewPdf (as_dst_pdf, "Title", "Creator", "Author", "Producer")
inv_imaging.PdfSetMeasurementUnits(2)

ll_font = inv_imaging.PdfAddFont("Arial")
ll_image = inv_imaging.PdfAddImageFromFile(as_pic_file)
ll_width = inv_imaging.PdfGetImageWidth(ll_image)
ll_height = inv_imaging.PdfGetImageHeight(ll_image)
inv_imaging.PdfSetPageDimensions(ll_width + 5, ll_height + 5)
rc = inv_imaging.PdfNewPage()
inv_imaging.PdfDrawText(5, 10, "Arial Text Size 7", ll_font, 7)
inv_imaging.PdfDrawImage(ll_image, 1, 1, ll_width, ll_height)
inv_imaging.PdfEndPage()

inv_imaging.PdfSavePdf()

//----------------------------------------

Re: How to merge 2 PDF files

Posted: Thu Sep 15, 2011 2:24 pm
by arcadyAbr
Actually, now I am getting the same problem when trying to use it with c#:
//--------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Security;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string ls_src_pdf, ls_dst_pdf, ls_src_pic, ls_args;
int ll_image;
XmlDocument ls_xml = new XmlDocument();

ls_args = "<Root><SourcePDF></SourcePDF><SourcePic>.\\test.jpg</SourcePic>";
ls_args += "<DestPDF>.\\reg_card_78582_1_signed.pdf</DestPDF></Root>";
ls_xml.InnerXml = ls_args;

ls_src_pdf = ls_xml.DocumentElement.ChildNodes[0].InnerText;
ls_src_pic = ls_xml.DocumentElement.ChildNodes[1].InnerText;
ls_dst_pdf = ls_xml.DocumentElement.ChildNodes[2].InnerText;

GdPicturePro5.cImaging ln_imaging = new GdPicturePro5.cImaging();
ln_imaging.SetLicenseNumber("XXXXXX");
ln_imaging.PdfNewPdf(ls_dst_pdf);
ll_image = ln_imaging.PdfAddImageFromFile(ls_src_pic);
ln_imaging.PdfSetMeasurementUnits(1);

ln_imaging.PdfNewPage();
ln_imaging.PdfSetPageDimensions(200, 150);
if (ll_image != 0)
{
ln_imaging.PdfDrawImage(ll_image, 100, 100, 30, 25);
}
ln_imaging.PdfEndPage();

ln_imaging.PdfSavePdf();



}
}
}


//--------------------------------------

Re: How to merge 2 PDF files

Posted: Fri Jan 18, 2019 10:19 am
by Gabriela

Re: How to merge 2 PDF files

Posted: Fri Feb 08, 2019 1:45 pm
by siyavarma
Thanks Gabriela, for this valuable reply.Helpful :)

Re: How to merge 2 PDF files

Posted: Fri Feb 08, 2019 1:49 pm
by Gabriela
You're welcome!
We are always happy to hear that.

Re:

Posted: Wed Feb 20, 2019 9:00 am
by vedika
Loïc wrote:
Fri Nov 30, 2007 12:56 pm
Hi,

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

Thanks for this code. It worked for me. I was stuck for long time, it helped me out t complete my project.