Page 1 of 1
Problems with Preview
Posted: Tue Nov 08, 2022 11:07 pm
by dtussman
I'm having problems saving a Previewed document as a PDF file when running my application using a Remote Desktop Connection. No matter what I do it won't save the document as a PDF, even if I choose the Print option and pick a PDF writer as the printer. I suspect it has to do with where the meta file created by the Preview function is stored, although thats just a hunch. Is there any way to tell the Preview function where to store the meta files, or is there some other solution I'm missing?
Re: Problems with Preview
Posted: Wed Nov 09, 2022 9:51 am
by Silvio.Falconi
you tried to delete the temp files because Rpreview saves the files starting with w and wmf or emf in a windows folder
you can set the folder change the function FWSavePreviewToPDF( oPreview, cPDF, lOpen ) you found on Prev2Pdf.prg
I use this
function FWSavePreviewToPDF( oPreview, cPDF, lOpen )
local cOrient, oPDF
local n
cPdf:= oApp:cPdfTemp
if LoadFreeImage() <= 32
MsgAlert( "Freeimage.dll non trovata" )
return nil
endif
DEFAULT cPDF := cGetFile( "PDF File (*.pdf)|*.pdf|", "Seleziona il File PDF da Save", ;
CurDir(), .t. )
....
Re: Problems with Preview
Posted: Thu Nov 10, 2022 8:39 pm
by dtussman
Thanks Silvio. Tried that but it won't compile, doesn't recognize oApp
Re: Problems with Preview
Posted: Thu Nov 10, 2022 8:42 pm
by Antonio Linares
Dear David,
I guess Silvio simply specifies a different path:
instead of cPdf:= oApp:cPdfTemp
use cPdf := "the_path"
Re: Problems with Preview
Posted: Thu Nov 10, 2022 8:55 pm
by Silvio.Falconi
dtussman wrote:Thanks Silvio. Tried that but it won't compile, doesn't recognize oApp
oApp Is Mine....make as Antonio wrote but U must recompile with your application that function U found on fwh source/functions folder
Re: Problems with Preview
Posted: Fri Nov 11, 2022 12:01 am
by dtussman
I'm not sure i've described the problem correctly. When connected to my application using windows Remote Desktop Connection, if I preview a document and then click the button to save as a PDF it saves the document but all the pages are blank. It works fine when not using Remote Desktop Connection.
Re: Problems with Preview
Posted: Fri Nov 11, 2022 9:56 am
by Antonio Linares
Dear David,
I have built FWH\samples\testprn2.prg and then copied the EXE to a remote PC managed with remote desktop.
The preview is properly shown and if I export it to PDF, the PDF is properly seen. Could you please reproduce my test ?
Here you have a screenshot of my test: (click on the url to see the entire screenshot)
https://github.com/FiveTechSoft/screens ... g?raw=true
thanks
Re: Problems with Preview
Posted: Fri Nov 11, 2022 1:47 pm
by karinha
I do like this:
Code: Select all | Expand
FUNCTION Main()
PRIVATE cDirPleno := GETCURDIR()
RETURNÿNIL
function FWSavePreviewToPDF( oDevice, cPDF, lOpen ) // oDevice can be oPrinter or oPreview
local cOrient, oPDF, cPRGPATH
local hWnd
if oDevice:IsKindOf( "TPREVIEW" )
hWnd := oDevice:oWnd:hWnd
oDevice := oDevice:oDevice
endif
#ifndef USEGDI
if LoadFreeImage() <= 32
MsgAlert( FWString( "freeimage.dll not found" ), FWString( "Alert" ) )
return nil
endif
#endif
PRIVATE CDIRPLENO
// AQUI
cPRGPATH := cFILEPATH( "C:\NFEPDF\" )
lCHDIR(cPRGPATH) // AQUI
// ? hb_CurDrive() + ":\" + CurDir() + "\"
DEFAULT cPDF := cGetFile( FWString( "PDF files | *.pdf |" ),;
FWString( "Select PDF File to Save" ),, ;
CurDir(), .T.,,,;
hb_CurDrive() + ":\" + CurDir() + "\" + ;
If( oDevice:IsKindOf( "TPreview" ),;
oDevice:cName, oDevice:cDocument ) + ".pdf" )
if ! Empty( cPDF )
cPDF = cFileSetExt( cPDF, "pdf" )
CursorWait()
cOrient = If( oDevice:nHorzSize() > oDevice:nVertSize(), 'L', 'P' )
oPdf = fwPdf():New( cPdf, cOrient )
AEval( oDevice:aMeta, { | cMeta | oPdf:AddMeta( cMeta ) } )
oPdf:Close()
CursorArrow()
DEFAULT lOpen := MsgYesNo( If( FWLanguageID() == 2, FWString( "¿" ) + " ", "" ) + ;
FWString( "View" ) + ;
" " + cPDF + " " + FWString( "(Y/N)" ) + " ?",;
FWString( "Please select" ) )
if lOpen
ShellExecute( IfNil( hWnd, GetWndDefault() ), "open", cPDF )
endif
else
cPDF := nil
endif
// RETURN TO MASTER - // AQUI
lCHDIR( cDirPleno )
// ? hb_CurDrive() + ":\" + CurDir() + "\"
return cPDF
Regards, saludos.
Re: Problems with Preview
Posted: Fri Nov 11, 2022 2:25 pm
by Otto
Hello Silvio,
sure no rights on the RDP server where you save the preview.
Best regards,
Otto
Re: Problems with Preview
Posted: Fri Nov 11, 2022 2:35 pm
by Otto
... you need read/write for RemoteDesktopUser
Re: Problems with Preview
Posted: Fri Nov 11, 2022 3:25 pm
by Silvio.Falconi
Otto wrote:Hello Silvio,
sure no rights on the RDP server where you save the preview.
Best regards,
Otto
I not must print from remote
Re: Problems with Preview
Posted: Fri Nov 11, 2022 7:23 pm
by dtussman
Hello Antonio,
I compiled and ran your testprn2.prg i and the preview displays the nice pattern of plus signs but the pdf only displays 2 blank pages. As I said before I suspect it has something to do with the application not being able to access the preview temp files or images (I'm not sure exactly what form they are in) which I assume its trying to store on the remote server. I'm running the app on a remote server, not just on another computer.
Regards,
David
Re: Problems with Preview
Posted: Fri Nov 11, 2022 8:22 pm
by Antonio Linares
Dear David,
Please check these values remotely:
MsgInfo( GetEnv( "TEMP" ) )
MsgInfo( GetEnv( "TMP" ) )
MsgInfo( GetWinDir() )
MsgInfo( oPrinter:cDir ) will tell you which one is in use
as this is the code where the preview sets the temporary folder:
Code: Select all | Expand
::cDir = GetEnv( "TEMP" )
if Empty( ::cDir )
::cDir = GetEnv( "TMP" )
endif
if Right( ::cDir, 1 ) == "\"
::cDir = SubStr( ::cDir, 1, Len( ::cDir ) - 1 )
endif
if ! Empty( ::cDir )
if ! lIsDir( ::cDir )
::cDir = GetWinDir()
endif
else
::cDir := GetWinDir()
endif
Check what they return and if you have write access there
Re: Problems with Preview
Posted: Fri Nov 11, 2022 8:53 pm
by Otto
Dear Antonio,
We found out, that on some WINDOWS version you have to create the TEMP DIR yourself.
Best regards,
Otto
Code: Select all | Expand
local cUmgebungTMP := GETENV("TMP")
*----------------------------------------------------------
if lIsDir( cUmgebungTMP ) = .f.
? "TEMP DIR erstellen " + cUmgebungTMP
lMKDir( cUmgebungTMP )
endif
Re: Problems with Preview
Posted: Sat Nov 12, 2022 1:39 am
by dtussman
Hi Antonio,
Both the TEMP and TMP variables were a strange folder that doesn't even exist and that was also the oprinter:cdir folder. So I created my own temp folder and changed oprinter:cdir to that folder. When running your sample code 2 emf files appeared in that folder, but when converting to pdf I still get the same result, 2 blank pages.