Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Merge two pdf documents using Ghostscript

Posted on 2006-11-20
9
Medium Priority
?
1,082 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 

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 2000 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

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.

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Microsoft Office Picture Manager has a Picture Shortcuts pane that shows a list with the Recently Browsed folders. While creating my video Micro Tutorial here at Experts Exchange showing How to Install Microsoft Office Picture Manager in Office 2013…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

610 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