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

Report should print JPEG when exist.

Status
Not open for further replies.

newtofoxpro

Programmer
Sep 16, 2007
301
IN
I have build report having logo.JPEG image. It runs fine. But when image does not exist, vfp open file picker. I want report should print when image exist in same folder and should not print when image does not exist and should not generate any error or file picker.

Thanks in advance
 
if file("logo.JPEG")
repo from repowithlogo.frx
else
repo from repowithoutlogo.frx
endif

Is it possible with only repowithlogo.frx
 
I haven't tried this, but perhaps in the PRINT WHEN condition: FILE("logo.JPEG")

You could also supply a "blank" image and set your output expression to IIF(File("logo.JPEG"),"logo.JPEG","empty.jpeg")
 
Yes, I think this is possible.

1. In the report designer, place a new image in the report, and open its Properties dialogue.

2. In the General tab, choose "Expression or variable name"

3. For the control source, enter an expression similar to this one:

[tt]IIF(FILE("MyFile"), "MyFile", "")[/tt]

4. On the Print When tab, enter an expression like this one:

[tt]FILE("MyFile")[/tt]

(In both cases, precede MyFile with the full path if necessary.)

I've just run a quick test, and the above seems to work. But check it for yourself.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Don't forget that FILE() is a bit 'clever' and may return false positives if the file in question is in VFPs search path, even if you specify a full path.

I use an UDF as a direct replacement for FILE()

Code:
FUNCTION MYFILE
	PARAMETER m.FILENAME
	PRIVATE m.FILENAME,m.FLG
	M.FLG = .F.
	IF !EMPTY(m.FILENAME)
		IF ADIR(TMPDIRFILES,m.FILENAME) > 0
			M.FLG = .T.
		ENDIF
	ENDIF
	RETURN(m.FLG)

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are not good for you.
 
If you simply keep the control source type to "image file name" and set the controlsource to an image file name, this will be embedded in the exe together with the frx and it'll always find the picture, too.

Bye, Olaf.

 
If you simply keep the control source type to "image file name" and set the controlsource to an image file name, this will be embedded in the exe together with the frx and it'll always find the picture, too.

That's true. But, if I've understood the problem correctly, different users will have different logos, and some users might not have a logo at all. Hence the need to decide at run time how to deal with it.

That is just a guess on my part, but I think that's what the OP is trying to achieve.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 

Sorry, I could not apply this. I think some detailed explanation is needed.


Thank you for reading my mind. Yes, different users will have different logos,

And some users might not have a logo at all because they have pre-printed logos on the paper. But they want logos when they make pdf/rtf file to make an electronic document. And off-course they need logos when they pre-view reports.

Sorry for little complications. I can manage if simply JPG exist = Print and JPG not exist should not print

Thank you
Best Regards.
 
Sorry, I could not apply this. I think some detailed explanation is needed.

I gave you step-by-step instructions. Which part didn't you understand? I think my method will work, and I'm happy to clarify the instructions. But tell me more specifically what you need to know.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
OK, the part about showing the logo on condition to preview and not when printing makes it even a bit more complicated, as you also need to react to the current report mode SYS(2040) to decide for Preview or Output. You also need to know whther output is to PDF or printer.

So let me comment on Mikes instructions:

>1. In the report designer, place a new image in the report, and open its Properties dialogue.
As you most certainly already have an image in your report, you get to it's properties by right clickinng on it and starting properites from the context menu.
In general, if you want to find out about something, many things in VFP have context menu, so remember there is a right mouse button.

>2. In the General tab, choose "Expression or variable name"
...as the Control source type. That enables you to dynamically define the file name via a variable or a field in your report table.

>3. For the control source, enter an expression similar to this one: IIF(FILE("MyFile"), "MyFile", "")
In that case no variable, Mike simply distinguishes the cases the file is there or not. MyFile obviously needs to be the fll pathname to a file. You might take that from some configuration, you have to know the file location of a logo. For not printing a logo an empty gif or jpg is a better choice than just no file name, to avoid the piompt for a file, but Mike typically is right, so I expect a "" would work for no logo, too.

>4. On the Print When tab, enter an expression like this one: FILE("MyFile"))
The "Print When" tab is the second tab of the properties dialog you opened in step 1. The condition could also include reacting to SYS(2040) and you may predefine if a PDF is generated or the report is printed to paper with corporate logo already preexisting in a variable llPrintLogo you eitheer set .T. or .F.

All variables you have defined in the same code you start the report via REPORT FORM can be used in the report in such expressions. So you might also set a variable lcLogoFilename and set it to either the logo or an empty JPG beforehand. The PrintWhen will still be useful to add the logo in preview mode, so in general if there is a file you should specify it and then decide whether to print or not depending on the mode and destination you might "pass in" into the report by defining variables the report can evaluate. As simple as that, we don't need to switch to a Reportlistener class or put some info into the data reported to let a report see it.

So call your report this way:
Code:
LOCAL llPrintLogo, lcLogoFilename
lcLogoFilename = file name of either logo or an empty jpg
llPrintLogo = NOT <<condition to print to pdf>>
REPORT FORM ....

In the image control the Control Source type then will need to be Expression or variable name, as Mike suggests, and the Control Source then simply is lcLogoFilename. In the print when tab you set the Print only when expression is true expression to (llPrintLogo OR SYS(2040)="1") AND FILE(lcLogoFilename).

Bye, Olaf.
 
Aside of working on variables, an expression for a report control can be any expression, not just a field name of the table you report, so you could also define functions the report can call, eg GetLogoFilename() and PrintLogo(), this way you wouldn't depend on variables to be defined before the report is started, but you will depend on the functions called being defined via SET PROCEDURE or at least SET PATH.

Bye, Olaf.
 

My fault, yes your method is working for me.

Thanks & Best Regards.


Yes, that's true. But I have build my custom-made preview-reports. where two function defined...

function FRXPrint
***************** Its job is to print frx it fires on button at preview

function FRXExprot
****************** Its job is to Export frx. it fires on button at preview

As adviced

I have added file("myfile.jpg") AND !upper("FRXPrint")$SYS(16)

Thank you
Best Regards.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top