Hi All, i was trying to convert the doc file to PDF using the ghost script. PDf file is creating but data is not comming in that. that means the PDF is Blank. please help me. the code i am using is…
In declaration part:
Public Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Public Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type
Declare Function WaitForSingleObject Lib “kernel32” (Byval _
hHandle As Long, Byval dwMilliseconds As Long) As Long
Declare Function CreateProcessA Lib “kernel32” (Byval _
lpApplicationName As Long, Byval lpCommandLine As String, Byval _
lpProcessAttributes As Long, Byval lpThreadAttributes As Long, _
Byval bInheritHandles As Long, Byval dwCreationFlags As Long, _
Byval lpEnvironment As Long, Byval lpCurrentDirectory As Long, _
lpStartupInfo As STARTUPINFO, lpProcessInformation As _
PROCESS_INFORMATION) As Long
Declare Function CloseHandle Lib “kernel32” (Byval _
hObject As Long) As Long
Public Const NORMAL_PRIORITY_CLASS = &H20&
Public Const INFINITE = -1&
In Initialization:
Sub Initialize
%REM
Author - Abhijeet
Created On - 2/03/04
Description -
Global -
Version - 1.0
%END REM
On Error Goto catchGeneralError
Dim session As New notessession
Dim rtitem As NotesRichTextItem
Dim rtitem1 As NotesRichTextItem
Dim filepath As String
Set db = session.currentdatabase
Set agent = session.CurrentAgent
paramid$ = agent.ParameterDocID
Set doc = db.GetDocumentByID(paramid$)
Set rtitem = doc.GetFirstItem("Rtxt_Attach")
filepath="c:\Temp"
Folders$ = Dir$(filepath, 16)
If Folders$="" Then
Mkdir filepath
End If
If doc.HasEmbedded Then
If ( rtitem.Type = RICHTEXT ) Then
Forall o In rtitem.EmbeddedObjects
pdfpath$=filepath &"\"& Strleftback(o.name,".")
TempFilePath$ = filepath &"\"& paramid$&".doc"
Print "TempFilePath$--->" TempFilePath$
Call o.ExtractFile(TempFilePath$)
Print "After TempFilePath$"
End Forall
End If
End If
Dim worddoc As Variant
Dim wordapp As Variant
Set wordapp=CreateObject("Word.Application.8")
If wordapp Is Nothing Then
Set wordapp=CreateObject("Word.Application")
End If
wordapp.documents.open TempFilePath$
wordapp.documents.save noprompt=True
Set worddoc=wordapp.activedocument
wordapp.visible=False
worddoc.activate
PSFileName =filepath &"\"& paramid$&".ps"
' printing word to adobe distiller printer to convert to .ps file
worddoc.PrintOut False, False ,0,PSFileName,,,,1,,, True, True
pdffile=filepath &"\"& paramid$&".pdf"
GS$="gswin32c -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pdfwrite -sOutputFile="+{"}+ pdffile +{"}+" -dPDFSETTING=/default -c .setpdfwrite -f "+{"}+ PSFileName+{"}
Print "GS---->" +GS$
Call ShellAndWait(GS$)
Dim object As Variant
Set rtitem1 = New NotesRichTextItem (doc, "Rtxt_PDFAttach" )
Set rtitem1 = doc.GetFirstItem("Rtxt_PDFAttach")
Name pdffile As pdfpath$&".pdf"
Set object = rtitem1.EmbedObject( EMBED_ATTACHMENT, "", pdfpath$&".pdf")
Print "file attached"
Call doc.save(True, True)
Print "file saved"
wordapp.documents.save noprompt=True
worddoc.close
wordapp.quit
Set objDist=Nothing
Set worddoc=Nothing
Set wordapp=Nothing
Kill TempFilePath$
Kill PSFileName
Kill pdfpath$ &".pdf"
Done1:
Exit Sub
catchGeneralError:
If Not wordapp Is Nothing Then
worddoc.close
wordapp.quit
End If
Set worddoc=Nothing
Set wordwin=Nothing
Kill TempFilePath$
Call ErrorMsg(Err)
Resume Done1
End Sub
In SUB:
Public Sub ShellAndWait(Byval RunProg As String)
’ From Kevin Pauli (kcpauli@usa.net)
Dim RetVal As Long
Dim proc As PROCESS_INFORMATION
Dim StartInf As STARTUPINFO
StartInf.wShowWindow = 6
StartInf.cb = Len(StartInf)
'Execute the given path
RetVal = CreateProcessA(0&, RunProg, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, 0&, StartInf, proc)
'Disable this app until the shelled one is done
Print "process started"
RetVal = WaitForSingleObject(proc.hProcess, INFINITE)
Print "process finished"
RetVal = CloseHandle(proc.hProcess)
End Sub
please help me.
Regards,
Archana