• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1279
  • Last Modified:

Blondie trying Shell Executing pdftk.exe on server to fill form using asp

I need to execute pdftk.exe command on the server using asp.

the pdftk program is going to take a .fdf file in one dir and fill a form into a template pdf file in another dir then write that filled pdf file out to a new file flattened, (Challenge Note: I have done this before using cold fusion but that execute function  is disabled by the sys admins fear of configuring iuser. )

I am of course out of time due to this change of language so help me back...

Here is what i have gotten thrown together so far, can you tell me the right way to exectute this code, as I do not understand the examples I am finding online that well...


' execute the shell
' is this wscript.shell the correct one to use?

Set server_shell = Server.CreateObject("wscript.shell")

server_shell.Run "%comspec% /c c:\web\x\htdocs\cgi-bin\pdftk.exe c:\web\x\htdocs\x\pdf\template\applicationtemplate.pdf fill_form c:\web\x\htdocs\x\pdf\102.fdf output c:\web\x\htdocs\x\pdf\temp\102.pdf flatten"

'or should I use something more like

server_shell.Run ("c:\web\x\htdocs\cgi-bin\pdftk.exe
c:\web\x\htdocs\x\pdf\template\applicationtemplate.pdf fill_form c:\web\x\htdocs\x\pdf\102.fdf output c:\web\x\htdocs\x\pdf\temp\102.pdf flatten")

'what does this do for me .. server.mappath? should I be using it? could something else be messing this up permissions? what about error handling please let me know!

Damsel Distressed
0
madpuppy
Asked:
madpuppy
  • 4
  • 2
1 Solution
 
INSDivision6Commented:
Above calls should produce the same results.  The first one calls CMD.EXE and call your coomand out of console window.  The second does not.  You can redirect the output in a file (output.txt below) to read it after program terminates in order to find errors/status (depends on your program output):

server_shell.Run "%comspec% /c "  & chr(34) & "c:\web\x\htdocs\cgi-bin\pdftk.exe c:\web\x\htdocs\x\pdf\template\applicationtemplate.pdf fill_form c:\web\x\htdocs\x\pdf\102.fdf output c:\web\x\htdocs\x\pdf\temp\102.pdf flatten" & chr(34) & " > " & chr(34) & " c:\output.txt"  & chr(34)

chr(34) - is quote
0
 
madpuppyAuthor Commented:
INS i am an american girl,,,

Per your suggestion:This is code ~and output now sorry newbie verbose:
I am not getting the output.txt or the pdf I am expecting to have the exe build.

<%
    'Create a variable named FID

    Dim fid

    'Read the search form variable. We will use CStr
    'to make sure we are getting a string.

    ' fid = CStr(Request("FID"))
     fid = 102


   ' set the paths  
  basePDF=server.mappath("\x\pdf\template\xapplicationtemplate.pdf")
  dataFDF=server.mappath("\x\pdf\" & fid & ".fdf")
  mergedPDF=server.mappath("\x\pdf\temp\xJobApp_" & fid & ".pdf")
  pfdtkAppl=server.mappath("\cgi-bin\pdftk.exe")
  paramCmd=" " & basePDF & " output " & mergedPDF & " verbose"
  mergeCmd="%comspec% /c "  & chr(34) & pfdtkAppl & paramCmd & chr(34) & " > " & chr(34) & " c:\web\x\htdocs\x\pdf\temp\output.txt"  & chr(34)

Set fs = Server.CreateObject("Scripting.FileSystemObject")

Response.Write("<BR>")
Response.Write(basePDF)
 If fs.FileExists(basePDF) Then
          Response.Write "<BR>BASEPDF OK<HR>"
     Else
          Response.Write "<BR>NO BASEPDF<HR>"
     End If
Response.Write("<BR>")
Response.Write(dataFDF)
 If fs.FileExists(dataFDF) Then
          Response.Write "<BR>dataFDF OK<HR>"
     Else
          Response.Write "<BR>NO dataFDF<HR>"
     End If
Response.Write("<BR>")
Response.Write(mergedPDF)
Response.Write("<BR>")
 If fs.FileExists(mergedPDF) Then
          Response.Write "<BR>mergedPDF OK<HR>"
     Else
          Response.Write "<BR>NO mergedPDF That is OK!<HR>"
     End If
Response.Write(pfdtkAppl)
Response.Write("<BR>")
 If fs.FileExists(pfdtkAppl) Then
          Response.Write "<BR>pfdtkAppl OK<HR>"
     Else
          Response.Write "<BR>NO pfdtkAppl<HR>"
     End If
Response.Write(mergeCmd)
Response.Write("<BR>")

 Set server_shell = Server.CreateObject("WScript.Shell")
 Return = server_shell.Run(mergeCmd, 10,TRUE)
 set server_shell = nothing

response.write "PDF File was written sucessfully! "
Response.Write(Return)

%>

***output****

c:\web\x\htdocs\pipecareers\pdf\template\xapplicationtemplate.pdf
BASEPDF OK
--------------------------------------------------------------------------------

c:\web\x\htdocs\x\pdf\102.fdf
dataFDF OK
--------------------------------------------------------------------------------

c:\web\x\htdocs\x\pdf\temp\xJobApp_102.pdf

NO mergedPDF That is OK!
--------------------------------------------------------------------------------
c:\web\x\htdocs\cgi-bin\pdftk.exe

pfdtkAppl OK
--------------------------------------------------------------------------------
%comspec% /c "c:\web\x\htdocs\cgi-bin\pdftk.exe c:\web\x\htdocs\x\pdf\template\xapplicationtemplate.pdf output c:\web\x\htdocs\x\pdf\temp\xobApp_102.pdf verbose" > " c:\web\x\htdocs\x\pdf\temp\output.txt"

PDF File was written sucessfully! 1
0
 
madpuppyAuthor Commented:


When I took out the %comspec% /c  I got the error error '80070002' on the run line (file not found? but I tested all the files and they are found right?)

I sound alot like the end of this one, what do you think?

http://www.experts-exchange.com/Web/Web_Languages/ASP/Q_21046917.html

But I do not have access to the sa - I have to ask thier grumppynesses what do I ask them to do?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
INSDivision6Commented:
Start MS DOS Prompt and try your command there.  Is it working?

c:\web\x\htdocs\cgi-bin\pdftk.exe c:\web\x\htdocs\x\pdf\template\xapplicationtemplate.pdf output c:\web\x\htdocs\x\pdf\temp\xobApp_102.pdf verbose > c:\web\x\htdocs\x\pdf\temp\output.txt

0
 
madpuppyAuthor Commented:
I do not have a dos access on this webshared server.

I have tired a simpler test , 4 is the proper return but no file gets copied..

<%
mergeCmd = "%COMSPEC% /c xcopy  c:\web\x\htdocs\x\after.htm  c:\web\x\htdocs\x\pdf\temp\"

Response.Write("<HR>")
Response.Write(mergeCmd)
Response.Write("<HR>")

 Set server_shell = Server.CreateObject("WScript.Shell")
 Return = server_shell.Run(mergeCmd, 1,TRUE)
 set server_shell = nothing

 response.write "PDF File was written sucessfully! <BR> return is "
 Response.Write(Return)
%>
--------------------------------------------------------------------%COMSPEC% /c xcopy c:\web\x\htdocs\x\after.htm c:\web\x\htdocs\x\pdf\temp\
--------------------------------------------------------------------PDF File was written sucessfully!
return is 4
0
 
madpuppyAuthor Commented:
Hey thanks but  I found that
'''WshShell.Exec is nicer then the 'run' command as it gives you access to the stdout and stderr streams, for better processing of output
Dim WshShell, oExec, input
Set WshShell = CreateObject("WScript.Shell")
Set oExec    = WshShell.Exec(mergeCmd)
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now