Solved

Merge two pdf documents using Ghostscript

Posted on 2006-11-20
9
1,038 Views
Last Modified: 2013-12-02
I have just installed Ghostscript 8.54. It works great. Does anyone know of a way to use ghostscript to merge the printed document with another pdf document on file (eg. C:\Temp\test.pdf)? I am using the email function to attach the created document to the Outlook Message form that opens.
0
Comment
Question by:wnerbun
  • 6
  • 3
9 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 17985472
there is this toolkit called pdftk that may help you  http://www.accesspdf.com/pdftk/

and according to this, u can use ghostscript and run it as a dos command

gswin32 -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=Merged.pdf -dBATCH 1.pdf 2.pdf 3.pdf

taken from
https://www.cs.tcd.ie/Shane.OConchuir/Misc/MergingPDFs.html

0
 

Author Comment

by:wnerbun
ID: 17988229
I've tried both of the following as an event procedure to merge two files (15100.pdf and eSurvey.pdf) and neither work:
gswin32 -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=Merged.pdf -dBATCH 15100.pdf eSurvey.pdf
or
pdftk 15100.pdf eSurvey.pdf cat output merged.pdf

I've tried adding the path to the statement and that does not seem to help. Any ideas as to what I'm doing wrong?
0
 

Author Comment

by:wnerbun
ID: 17997655
evidently my Ghostscript and pdftk programs are "not registered" because when I run the command line from Start\Run, I get the following message: "Windows cannot find pdfgk." (or gswin32). How do I register the program with windows?
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 

Author Comment

by:wnerbun
ID: 17997911
ok, I registered the program and can now run it from the Start\Run window, but now I'm trying to figure out how to get it to execute from a Command Button on my form. Anyone know the proper syntax??
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17998256
Hi wnerbun,

I dont have Ghostscript hence the link supplied

Regarding the code however, that I can do

Now, how do u determine what pdf files u want merging?
0
 

Author Comment

by:wnerbun
ID: 18007966
file #1 path=C:\VendorPDFs\[Vendor].pdf (e.g., 15100.pdf)
file #2 path=C:\VendorPDFs\eSurvey.pdf

merged file name and path=C:\VendorPDFs\VendorSurvey.pdf
0
 
LVL 65

Accepted Solution

by:
rockiroads earned 500 total points
ID: 18008161
so is this line working?
gswin32 -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=Merged.pdf -dBATCH 15100.pdf eSurvey.pdf


if so, u can try using Shell command

dim sVendor as string

'say u set your vendor here, it could be a form variable like Me.vendor or something
sVendor = "15100"

chdir("C:\VendorPDF")
Shell("gswin32 -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=eSurvey.pdf -dBATCH " & sVendor & ".pdf")


another way is to create a temp dos batch script and run that

dim iHandle as integer
dim sFile as String

sFile="tmp.bat"
iHandle = freefile
open sFile for output as #iHandle
print #iHandle, "Cd \VendorPDF"
print #iHandle, "gswin32 -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=eSurvey.pdf -dBATCH " & sVendor & ".pdf"
close iHandle

Shell("tmp.bat")

0
 

Author Comment

by:wnerbun
ID: 18019821
The following statement works:
gswin32 -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE="C:\VendorPDFs\Merged.pdf" -dBATCH C:\VendorPDFs\15100.pdf C:\VendorPDFs\eSurvey.pdf

I will  try your shell command today.
0
 

Author Comment

by:wnerbun
ID: 18020388
Eureka! Kudos! Bravo Zulu! You've solved my problem! Points to you!!!
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Office Picture Manager is not included in Office 2013. This comes as a shock to users upgrading from earlier versions of Office, such as 2007 and 2010, where Picture Manager was included as a standard application. This article explains how…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
This video Micro Tutorial is the second in a two-part series that shows how to create and use custom scanning profiles in Nuance's PaperPort 14.5 (http://www.experts-exchange.com/articles/17490/). But the ability to create custom scanning profiles a…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question