Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Save as PDF File option on FoxyPreviewer preview toolbar not appearing 1

Status
Not open for further replies.

Rajesh Karunakaran

Programmer
Sep 29, 2016
545
MU
Hi,

I am using the below code to print 2 report one after the other. I made 2 FRX files only because the design is considerably different for 1st page and the rest and it was difficult to manage controlling in one FRX.

I downloaded the new version (2.99z) of FoxyPreviewer and copied in the application folder.

Code:
DO FoxyPreviewer.app  && this may not be necessary here and I can set at application start.

_screen.oFoxyPreviewer.lSaveAsPDF = .t.

loListener = NEWOBJECT('_ReportListener', '_ReportListener.vcx')
loListener.ListenerType = 1
loListener.AddReport('rep_pg1.frx', 'noPageEject')
loListener.AddReport('rep_rest.frx')
loListener.RunReports()

DO FoxyPreviewer.app WITH 'Release'  && this may not be necessary here and I can set at application start.

1. Now, even though I have set '_screen.oFoxyPreviewer.lSaveAsPDF = .t.', my preview toolbar 'Save Report' button shows only the 'Save as Image File' option. I am not getting the PDF save option. What setting (other required parameters, if any) I am missing here?

In the above code, if I just use "REPORT FORM rep_pg1 PREVIEW" without going through the Report Listener, I am getting all options in the Save File As button. But I will get only page 1. That's the problem.

2. So, other than using the Listener explicitly in my code, in FoxyPreviewer is there a way to print 2 frx files in succession, ie as if they were one ?

Thanks in advance,
Rajesh

 
How to create a PDF file without showing dialog box and then after print?
 
Rajesh,

At first glance, your code looks OK to me. I assume you have .nShowToolBar set to 1, to make the entire toolbar appear.

I suggest you start by simplifying your code, so that you can focus on the PDF issue. This is the minimum code you need to enable the PDF button:

Code:
DO FoxyPreviewer.APP
WITH _Screen.oFoxyPreviewer
	.nShowToolBar = 1			
	.nDockType = 0			&& dock toolbar at top of window
	.nWindowState = 2		&& maximised
	.lOpenViewer = .T.		&& opens PDF viewer after saving to PDF
	.lSaveAsPDF = .T.
ENDWITH

then preview the report in the normal way:

Code:
REPORT FORM "MyReport" TO PRINTER PROMPT PREVIEW NOCONSOLE


The only other suggestion that comes to mind is that you check that you have a file named libhpdf.dll in your FoxyPreviewer folder. That file provides the PDF library for Foxy. If is it is not there, try re-installing Foxy.

Sorry I can't suggest anything else just now.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi Mike,

I already have the .lSaveAsPDF = .T. setting done. Window maximising & PDF opening, I don't mind.

I can issue as in 'REPORT FORM "MyReport" TO PRINTER PROMPT PREVIEW NOCONSOLE'. But my problem is that, then I will get only the 1st report. I have 2 reports which need to be printed in succession (as if they are in a single FRX).

Through report listener and using AddReport method, I am getting it the way mentioned above. But then, there I don't have the PDF option in the 'Save File As' button of the toolbar (even though I set .lSaveAsPDF = .T., is doesn't appear)

Any more thoughts/ideas?

Rajesh
 
No idea why you have the foxypreviewer toolbar but not the save as PDF option, but there is the NOPAGE§EJECT clause so you can chain two reports. It mainly means VFP keeps the current print job open, which is what you need. NOt sure this is possible with a preview, though.



Chriss
 
Rajesh,

At the risk of over simplifying and not using Report Listener, I use something generally like this:

Code:
DO FoxyPreviewer.app
REPORT FORM Report1 OBJECT TYPE 10 NEXT 1 NOCONSOLE TO FILE MyFile NOPAGEEJECT
REPORT FORM Report2 OBJECT TYPE 10 NEXT 1 NOCONSOLE TO FILE MyFile

It offers my user (with any pdf reader) a multi-page preview and a chance to "Save As".

NEXT 1 reports only the current record. Eliminate it to SCAN, etc.

Steve
 
Rajesh,

First, the code I posted was only intended to help with the first of your two questions: how to get the PDF button to appear. Cut out all the references to loListener, and just focus on getting a preview with the toolbar. I'm not suggesting that will be the solution. It is just to help you eliminate the non-essential stuff.

Regarding the question of getting two reports in the same print job, I would echo was Chris said. In general, you need NOPAGEEJECT on each of the reports except the last. I expect you already knew that.

When I use Foxpreview to preview or print reports, I never reference the listener. I only set the properties of _Screen.oFoxyPreviewer. With that in mind, here is my entire code.

First, the initialisation:

Code:
DO FoxyPreviewer.APP

WITH _Screen.oFoxyPreviewer
	.nShowToolBar = 1			
	.nDockType = 0			&& dock toolbar at top of window
	.nWindowState = 2		&& maximised
	.nCanvasCount = 1		&& no. of pages to show at a time
	.nZoomLevel = 5			&& 100% 
	.nButtonSize = 2		&& 32 x 32 buttons in toolbar
	.cTitle = "Preview"	        && overrides default, which contains FRX filename
	.cToolbarTitle = "Preview"	&& ditto
	.lOpenViewer = .T.		&& opens PDF viewer after saving to PDF
	.lSendToEmail = .F.	        && no email button
	.lPrinterPref = .F.	        && hide printer preferences button
	.lShowSearch = .F.		&& hide search button
	.lShowSetup = .F.		&& hide options button
	.lSendToEmail = .F.	        && hide email button
	.cImgPrint = "Print-16.bmp"	&& icon for Print button
	.cImgSave = "PDF-16.bmp"	&& icon for Save button
	.lShowPrinters = .F.	        && hides the printer combo; this means that the Print button
	 				&& will always open the Windows Printers dialogue
	.lShowCopies = .F.		&& hide spinner for no. of copies 
	* Next few settings are for contents of "Save" menu
	.lSaveAsImage = .F.
	.lSaveAsHTML = .F.
	.lSaveAsMHT = .F.
	.lSaveAsRTF = .T.
	.lSaveAsXLS = .F.
	.lSaveAsPDF = .T.
	.lSaveAsTXT = .F.
	 
ENDWITH

Obviously, you would need to adjust the above code to reflect your own requirements.

Then, at the point of outputting the report:

Code:
REPORT FORM (lcReportName) TO PRINTER PROMPT PREVIEW NOCONSOLE

And finally, at close-down:

Code:
DO FoxyPreviewer.APP WITH "Release

So, on that basis, you could trying doing the REPORT FORM (as above) for each of the reports, with the NOPAGEEJECT clause for each of them except the last. However, I don't know if that works in conjunction with the PREVIEW clause. You might need to issue a separate series of REPORT FORM .... NOPAGEEJECT commands just for the printing, without doing the preview.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi Everyone,

It appears I got it solved. Need to check at clients PC as well.
I am giving like this. No report listener object used explicitly.

Code:
DO FoxyPreviewer.app

*/ Here I can do all those toolbar customization using _Screen.oFoxyPreviewer object.  Need to check that.

REPORT FORM rep_pg1.frx OBJECT TYPE 1 NOPAGEEJECT NORESET
REPORT FORM rep_pg2.frx OBJECT TYPE 1 PREVIEW

DO FoxyPreviewer.app WITH 'Release'

Now, I am getting the preview with pages from both reports in succession. I have all options in the Save As File button as well. If I go for Save as PDF, it creates single PDF with pages from both FRXs.

I think, Steve has given a solution similar to this but with OBJECT 10 which is direct PDF creation, isn't it?

I need to check in client's PC.

Thank you all very much for your time.
Rajesh
 
Rajesh,

That's what I've been telling you. You don't need to refer to the listener object, because the PDF support is built into FoxyPreviewer. As you can see from the code I posted above, you just need to initialise Foxy, set its properties, and call REPORT FORM in the usual way (not with an OBJECT clause).

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi Mike,

Yeah! I saw that.
I adopted the customization part indeed.
But I wanted it for 2 FRXs to show in preview in succession as if it's only 1 FRX
That was where I was confused.

Also, the 'NOPAGEEJECT NORESET' against the 1st report and only 'PREVIEW' against the 2nd report are doing the trick it seems.

Thank you Mike!
Rajesh
 
Well, Mike, the dicumenttion also mentions OBJECT TYPE 10 for creating PDFs. There is a difference though, when you REPORT FORM... OBJECT TYPE 10 PREVIEW, what you do isn't just allowing the user to choose PDF in the Save as option, you explicitly tell foxypreviewer to create a PDF and the preview clause tells foxypreviewer to show the final PDF in your default PDF viewer.

See FAQS question "How can I generate a PDF (or any other available type) without opening the preview window ?"

Maybe you actually want a PDF and tell users to use this save as option. Now you see how OBJECT TYPE 10 can be used to simply let VFP create the PDF and automaically show it with a users default PDF viewer, not inside a VFP report preview.

Chriss
 
Hi Chriss,

Yes, OBJECT TYPE 10 along with a file name will directly create PDF. Btw, I believe Mike knows about OBJECT TYPE 10 already and its advantages.

In my case, however, I didn't want it to create PDF always. Instead, I would show the preview and if the user thinks he needs a PDF, he would select the save as from toolbar, select a folder and specify filename in the dialog, and he gets it.

But, the earlier problem was I tried to achieve that through report listener object. Even though everything was okay, I didn't get the PDF option in the Save As button of preview toolbar. That's was the only problem. Still I do not know the cause, why the report listener disturbs the config of the preview toolbar.

But now, I get the desired result by using two REPORT FORM commands for the 2 FRX files. Too, I have PDF option in the preview toolbar. So, problem solved!

Thanks to everyone
Rajesh
 
Rajesh (and Chris), good to hear that you have solved the problem.

I must admit that I was a bit confused about OBJECT TYPE 10. I hope I didn't mislead you, I have never used the OBJECT clause with FoxyPreviewer, and never directly addressed the listener object.

I have always done what you wanted to do, that is, to give the user the choice of creating a PDF via the toolbar button, which is why I focused on that part of the problem.

Also, I wasn't sure how well NOPAGEEJECT would work with the preview. Given that you have to specify the order in which the reports appear within the printjob, I thought you would need some way of forcing the user to preview the reports in that same order. But that doesn't seem to be an issue.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I think the reason the reportlistener solution doesn't work is because the way foxypreviewer works is based on a reportlistener itself, hooked upon a normal REPORT FORM. So when you start your own (the default reportlisterner of the reportlistener.vcx coming with VFP) you circumvent using foxypreviewer.

I'm not sure, like I and Mike weren't sure about how preview can work with a report spanning multiple frxes, but it's good to see this works, too.

I also think you can cahin reportlisteners or even fork, ie print something to PDF, printer and HTML, but I'm not deep into reportlisteners functionality.

Chriss
 
Rajesh,

I used OBJECT 10 only because I wasn't aware of Mike's (properties) method. Apparently each will work depending on your exact requirement.

I also neglected to mention the (obvious?) need to open the reader to view the pdf. In my case I create 3 6-18 page reports viewed in 3 tabs. The user can then print selected page(s) combine, save, discard, etc. In my opinion this is even better than a PREVIEW. FWIW I've had problems with VFP's PREVIEW.

Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top