How to merge 2 PDF files

Example requests & Code samples for GdPicture Toolkits.
Post Reply
User avatar
paulo moura
Posts: 4
Joined: Thu Sep 06, 2007 9:12 pm
Location: Brasil
Contact:

How to merge 2 PDF files

Post by paulo moura » Thu Nov 29, 2007 7:36 pm

Hi !

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

Thank you !

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Post by Loïc » 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

TMCjason
Posts: 1
Joined: Fri May 29, 2009 6:01 pm

Re: How to merge 2 PDF files

Post by TMCjason » Fri May 29, 2009 6:03 pm

How can I get this to work with GdPicture.NET?

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: How to merge 2 PDF files

Post by Loïc » Sat May 30, 2009 10:54 am

For GdPicture.NET see: viewtopic.php?t=1583

arcadyAbr
Posts: 6
Joined: Mon Aug 08, 2011 8:39 am

Re: How to merge 2 PDF files

Post by arcadyAbr » Wed Sep 14, 2011 2:50 pm

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()

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

arcadyAbr
Posts: 6
Joined: Mon Aug 08, 2011 8:39 am

Re: How to merge 2 PDF files

Post by arcadyAbr » Thu Sep 15, 2011 2:24 pm

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();



}
}
}


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

Gabriela
Posts: 436
Joined: Wed Nov 22, 2017 9:52 am

Re: How to merge 2 PDF files

Post by Gabriela » Fri Jan 18, 2019 10:19 am


siyavarma
Posts: 1
Joined: Fri Feb 08, 2019 1:38 pm
Contact:

Re: How to merge 2 PDF files

Post by siyavarma » Fri Feb 08, 2019 1:45 pm

Thanks Gabriela, for this valuable reply.Helpful :)

Gabriela
Posts: 436
Joined: Wed Nov 22, 2017 9:52 am

Re: How to merge 2 PDF files

Post by Gabriela » Fri Feb 08, 2019 1:49 pm

You're welcome!
We are always happy to hear that.

vedika
Posts: 2
Joined: Tue Feb 19, 2019 9:16 am
Contact:

Re:

Post by vedika » Wed Feb 20, 2019 9:00 am

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.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest