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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print control in foxypreviewer 1

Status
Not open for further replies.

Rhtt

Programmer
Feb 9, 2023
7
RO
Hello
I am using foxypreviewer in my app in visual FOXPRO9 for generating an PDF file from report but i need to deactivate print button from that PDF, how can i do that? It is possible to deactivate it?

Thank you!
 
I don't know what you mean.
You only get a preview and toolbar which have buttons you could suppress, if you don't just print the report, but also use the preview feature.

You can specify all things foxyPreviewer needs to know in advance and just generate a PDF without user interaction, then you don't need to customize the print preview toolbar at all, i.e. that's the ideal solution. Just look into the documentation here in page 51:
Chriss
 
FoxPreviewer has a couple of properties that control the visibility of print buttons:

lShowPrintBtn: Set it to .F. to hide the Print button. This does not affect other printer-related buttons, such as Printer Preferences.

lPrintVisible: Set to .F. to hide all printer-related buttons.

See the FoxPriveiwer docs for more details.

Of course, this won't prevent the user from printing from within your PDF viewer. There's nothing you can do in VFP to prevent that.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
From the docs page 51 (as I recommended to read):

1. lPDFEncryptDocument - logical, determines if the PDF engine will encrypt the PDF document, allowing you to set other restrictions
to the documents, using the properties below
2. lPDFCanPrint - logical, determines if the 'encrypted' PDF document will allow printing. Works only if lPDFEncryptDocument = TRUE
(see above)

So yes, this can be made a feature of the resulting PDF file. You just have to read the documentation. Also in the documentation, how you customize the toolbar and how you don't even need that and determine the PDf file name before printing=generating the file without preview, so the user doesn't pick print (to printer/paper) instead of the save to PDF option.

All things are actually possible. how far the rights management is supported by all pdf viewers after a file is generated encryped and wihtout print permission is beyond my knowledge, though.

Chriss
 
Chriss said:
how far the rights management is supported by all pdf viewers after a file is generated encryped and wihtout print permission is beyond my knowledge, though
.

Yes, that's the key point. You can't know what PDF viewer your users will be using, and you can't know what features that viewer supports. Also, even if the viewer respects the "no print" setting, that won't prevent a determined user from printing the document. There are several utilities available which "unlock" secure PDFs.

Perhaps Rhtt could clarify: Do you want to remove or disable the print button in Foxy? Or do you want to prevent the user from printing within the viewer?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hello Mike, i need to disable the print button if that pdf was printed 1 time user cannot be able to print 2 nd time i need that user can only view that pdf not to print it

I try to set lPDFEncryptDocument = TRUE
lShowPrintBtn= .F.
lPDFCanPrint = .f.

but is the same result with no modification
 
Hello,

maybe you should look in FP doocs for savepropertys, too.

We have a button "preview" which has print and save in FP disabled and sometimes even an additional watermark
and a button "save" which saves without showing the report in preview or "print and save" which additionally prints on "jobprinter" stored in our usersettings.

Regards
tom

 
Oh I forgot. Permission applied with passwords (PDF) only.
Set owner password to samoe string and user password to empty string.

mJindrova
 

I try to set lPDFEncryptDocument = TRUE
lShowPrintBtn= .F.
lPDFCanPrint = .f.

but is the same result with no modification

Just to be clear: You are saying that, even after setting lShowPrintBtn to .F., you can still see the Print button? Is that correct?

If so, be aware that lShowPrintBtn is a property of the FoxpyPrviewer object. It is not a variable. So instead of this:

[tt]lShowPrintBtn= .F.[/tt]

you need to do this:

[tt]_Screen.oFoxyPreviewer.lShowPrintBtn = .F.[/tt]

You do that any time after you do [tt]DO FOXYPREVIEWER.APP[/tt] and before you invoke the preview.

If that doesn't work, there are other ways of achieving your goal, but try this one first.

Note this has got nothing to do with lPDFEncryptDocument or lPDFCanPrint. Those are also properties of FoxPreviewer, but they don't affect what the user can see or do in the preview window. They affect the actual PDF.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike,
The syntax what i used is
_Screen.oFoxyPreviewer. but nothing happen

I'm thinking to use report preview instead of pdf with pdfviewer

But then i need to hide that print button too
 
I can't see why that shouldn't work. Are you sure your code is correct?

That said, another option would be to output the PDF without the preview. You can do that in FoxyPreviewer, or by "printing" the report to a PDF printer driver.

If you want to provide a preview but without any printing facilities, you can do that in VFP's native preview window. Something like this:

Code:
LOCAL loPreview
loPreview = NULL
DO (_REPORTPREVIEW) WITH loPreview

loPreview.AllowPrintFromPreview = .F.
  && This is the important bit

loPreview.AllowPrintFromPreview = .F.
loListener = CREATEOBJECT("ReportListener")
loListener.PreviewContainer = loPreview
lolistener.ListenerType = 1

REPORT FORM MyReport OBJECT loListener

You could then provide separate buttons somewhere else in your interface to output the report to PDF and to print it. Doing it that way would also allow you to disable the Print button after the user has printed one copy of the report, which I think is what you originally asked for.

But, as I said earlier, none of this will prevent the user from printing the PDF outside your application.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike, that's all fine, but actually you don't even need a pdf printer driver, as FoxyPreviewer generates PDF with a library directly, you just need to set some properties of the foxyprevviewer object and then print in its PDF mode without a preview.

In the FAQs section of the documentation page

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

In FP v3
Just use the "TO FILE" clause, and FPv3 will use the File extension used to determine automatically the best reportlistener to create your output! In short, in the new version [highlight #FCE94F]you don't need to use the "OBJECT TYPE" clause at all![/highlight]

Code:
DO FoxyPreviewer.App && only necessary once in main, not for every report
* Make PDF
REPORT FORM yorreport ;
   TO FILE "c:\TestReport.Pdf"



Chriss
 
Mike

Code:
LOCAL loPreview
loPreview = NULL
DO (_REPORTPREVIEW) WITH loPreview

loPreview.AllowPrintFromPreview = .F.
  && This is the important bit

loPreview.AllowPrintFromPreview = .F.
loListener = CREATEOBJECT("ReportListener")
loListener.PreviewContainer = loPreview
lolistener.ListenerType = 1

REPORT FORM MyReport OBJECT loListener

i tried your exemple for vfp report but it wont deactivate print button
 
It work now, my bad, thank you so much for y'all help
 
We now don't know what you finally ended up with, but what you showed was still not using the essential line of code necessary to use foxypreviewer at all.

If you want to use foxypreviewer the starting point is having this line of code
Code:
DO FoxyPreviewer.App
Has that at least become clear by now?

And then you can use reports a you did without foxypreviewer and you have some more properties/settings and also the TO FILE clause of REPORT commands will make foxypreviewer process that as necessary. Without a reportlistener, without an OBJECT clause.

What you have there is likely sample code for usage of older foxypreviewer versions. It'll also work for downward compatibility, but all in all foxypreviewer usage is much simpler as even Mike told you. Haven't you found the paragraph I quoted from the documentation?

I even highlighted the quoted portion saying you don't need the OBJECT TYPE clause. Thus you also don't need a reportlistener object. Foxypreviewer is triggered, can analyze the code and clauses and then use its own appropriate reportlistener, for example for generating PDF. If you use your own, I bet it'll override that anyway. And a base class reportlistener. Which has no implementation that makes it do anything special like creating HTML or DOC or PDF output. If you use a reportlistnere, then it's always a class derived from the reportlistener, that actual has some code in events and methods that does something different than the usual report engine does.

Chriss
 
I use the below together with other code, to produce a PDF that can be previewed with no PRINT button on the toolbar:

*This is at the start of my prg

Code:
#DEFINE PrintFromPreview .F.

LOCAL loPreviewContainer AS FORM, ;
  loReportListener AS REPORTLISTENER, ;
  loExHandler AS ExtensionHandler OF SYS(16)

loPreviewContainer = NULL
DO (_REPORTPREVIEW) WITH loPreviewContainer
loReportListener = NEWOBJECT('ReportListener')
loReportListener.LISTENERTYPE = 1 &&Preview
loReportListener.PREVIEWCONTAINER = loPreviewContainer
loPreviewContainer.AllowPrintfromPreview = PrintFromPreview
loPreviewContainer.TextOnToolbar = .F.
loExHandler = NEWOBJECT('ExtensionHandler')
loPreviewContainer.SetExtensionHandler( loExHandler )

* The following command is later issued


Code:
REPORT FORM MYFORM NOCONSOLE PREVIEW FOR SOMETHING=msomething OBJECT loReportListener  && Example only


* The below is at the end of my prg

Code:
DEFINE CLASS ExtensionHandler AS CUSTOM
  *-- Ref to the Preview Container's Preview Form
  PreviewForm  = NULL

  *-- Here you implement (hook into) the PreviewForm_Assign
  *-- event of the preview container's parent proxy

  PROCEDURE PreviewForm_Assign( loRef )
  *-- Perform default behavior: assign obj ref.
  THIS.PreviewForm = loRef

  *-- Grab the obj ref to the preview form and bind to its
  *-- ShowToolbar() method. This lets the
  *-- STB_Handler() method of this extension handler
  *-- to run code whenever the Preview toolbar is shown
  *-- by the PreviewForm.ShowToolbar() method.
  IF !ISNULL( loRef )
    BINDEVENT(THIS.PreviewForm, ;
    'ShowToolbar', THIS, 'STB_Handler')
  ENDIF
  ENDPROC

  PROCEDURE STB_Handler(lEnabled)
  *-- Here you work around the setting
  *-- persistence problem in the Preview toolbar. 
  *-- The Preview toolbar class (frxpreviewtoolbar)
  *-- already has code that you can use to enforce
  *-- setting's persistence; it is just not called. Here,
  *-- you call it.
  WITH THIS.PreviewForm.TOOLBAR
  .REFRESH()
  *-- When you call frxpreviewtoolbar::REFRESH(), the
  *-- toolbar caption is set to its Preview form,
  *-- which differs from typical behavior. You must revert that
  *-- to be consistent. If you did not do this,
  *-- you would see " - Page 2" appended to the toolbar
  *-- caption if you skipped pages.
  .CAPTION = THIS.PreviewForm.formCaption
  ENDWITH
  ENDPROC

  *-- A preview container requires these methods
  *-- to be implemented in an associated preview extension handler.
  *-- They are not used in this example, but still must be here.
  PROCEDURE AddBarsToMenu( cPopup, iNextBar )
  PROCEDURE SHOW( iStyle )
  ENDPROC
  PROCEDURE HandledKeyPress( nKeyCode, nShiftAltCtrl )
  RETURN .F.
  ENDPROC
  PROCEDURE PAINT
  ENDPROC
  PROCEDURE RELEASE
  RETURN .T.
  ENDPROC

ENDDEFINE

I see you've already mentioned you resolved your question but it might be useful to tell us what you did.

Thank you

Steve Williams
VFP9, SP2, Windows 10
 
I always wonder why people use their own preview window. With the report engine replacement Foxypreviewr is, you actually suppress all the features it has in its own enhanced preview and only use half of it. At least that's my gut feeling, I haven't investigated it all.

The _Screen.oFoxyPreviewer object and all its properties are influencing foxypreviewers own preview window. And that's started by simply using the PREVIEW clause of REPORT FORM command. No more, no less.

Chriss
 
Hello
Mike, i have a New problem with this code

Code:
loPreview loPreview = NULL 
DO (_REPORTPREVIEW) WITH loPreview loPreview.AllowPrintFromPreview = .F. 
&& This is the important bit 

loPreview.AllowPrintFromPreview = .F. loListener = CREATEOBJECT("ReportListener") loListener.PreviewContainer = loPreview lolistener.ListenerType = 1 
REPORT FORM MyReport OBJECT loListener

Until I build my app it work just fine but after I built it win32 exe It give me this Errol

"LOPREVIEW is not an object"
It wont let me to generate report
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top