1. Avory Rose Pastoral
  2. PowerBuilder
  3. Thursday, 30 November 2023 07:20 AM UTC

Hi everyone, 

 

I have a process that allows the user to print. But every time the user prints, the saveas dialog box keeps on prompting and asking you to supply filename. Below are my scripts. 

 

I do this kind of printing because with that, I can successfully print image with pdf format and I use filecopy to copy the saved pdf file from local to server or any path that I need. 

 

s_newfilename = s_cppath1 + s_name + ".pdf"
s_newfilename2 = s_cppath2 + s_name + ".pdf"
s_newfilename3 = s_cppath3 + s_name + ".pdf"

 

dw_printer.Object.DataWindow.Print.PrinterName = "Microsoft Print to PDF"

dw_printer.Object.DataWindow.Print.FileName = s_newfilename3
dw_printer.Print(false, false)

 

If dw_printer.rowcount() > 0 then
if dw_printer.Print() < 1 then
dw_printer.PrintCancel()
end if
end if

 

s_copypath = "c:/path/"+s_newfilename3
//Messagebox("",s_copypath)



li_FileNum = FileCopy (s_copypath, &
s_newfilename, True )


li_FileNum2 = FileCopy (s_copypath, &
s_newfilename2, True )



li_FileNum3 = FileCopy (s_copypath, &
s_newfilename3, True )

 

iRetVal = ShellExecute(0, "print", s_newfilename3, "", "", 1)



IF iRetVal <= 32 THEN
// Capture the error message
string ls_errorMessage
ls_errorMessage = "Failed to print PDF file. Error code: " + String(iRetVal)

// Display the error message in a messagebox
MessageBox("System Error", ls_errorMessage, StopSign!)
ELSE
MessageBox("Success", "Printing PDF file...")
END IF

 

 

and in my global external function I have this:
Function long ShellExecute( long hwnd,  string lpOperation, string lpFile, string lpParameters,  string lpDirectory,  integer nShowCmd ) Library "shell32.dll"  alias for "ShellExecuteW"


I'm having problem also with re-print. When the document got reprinted or already existing in the server, the newly copied file got corrupted. 

By the way Im using Powerbuilder Claasic 12.5

Please help. TIA.

Andreas Mykonios Accepted Answer Pending Moderation
  1. Friday, 1 December 2023 07:16 AM UTC
  2. PowerBuilder
  3. # 1

I just tried the following code:

dw_1.Object.DataWindow.Print.PrinterName = "Microsoft Print to PDF"
dw_1.Object.DataWindow.Print.FileName = "\\some_server\Devel\Testing\TestTestTest.pdf"
dw_1.print()
sleep(0.5)
dw_1.print()
sleep(0.5)
dw_1.print()

It works fine.

But if I do remove sleep commands then problems start. Second and third print command seems to occurs before writing pdf by first print completes. So, can you try to put some delay after each print?

Of course this issue happens when I try to write to the same file...

Andreas.

Comment
There are no comments made yet.
Andreas Mykonios Accepted Answer Pending Moderation
  1. Thursday, 30 November 2023 10:30 AM UTC
  2. PowerBuilder
  3. # 2

Hi.

For me the following works without showing any prompt window:

s_newfilename3 = "C:\2Check\TestTestTest.pdf"

dw_printer.Object.DataWindow.Print.PrinterName = "Microsoft Print to PDF"
dw_printer.Object.DataWindow.Print.FileName = s_newfilename3 
dw_printer.Print(false, false) 

IF dw_printer.rowcount() > 0 THEN 
	IF dw_printer.Print() < 1 THEN 
		dw_printer.PrintCancel() 
	END IF 
END IF 

Check the value you have in s_newfilename3. But I'm using PB 2022 R2.

Andreas.

Comment
  1. Avory Rose Pastoral
  2. Friday, 1 December 2023 02:55 AM UTC
But in the copied file in server, the pdf file got corrupted. Which I don't understand why because the file saved in local is perfectly fine, but when I tried to open the one in the server it's corrupted, specially if the file is existing and was being replaced with the new one.
  1. Helpful
  1. Andreas Mykonios
  2. Friday, 1 December 2023 06:39 AM UTC
Can't tell you why. But it seems to be an issue related to "Microsoft Print to PDF" and not powerbuilder.

Andreas.
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.