Print .jpg in pdf print
Moderator: Rathinagiri
Re: Print .jpg in pdf print
Yes Red2,
rename will work but not with *`s you must use complete file names. I am working on directory as it brings in all of the files starting with w.
At this point I am trying to create a loop for the renaming. I have the first file working. I am not sure whether to use a do while loop or a for loop.
fdir:= DIRECTORY('w*.jpg')
msgbox(fdir[1,1]) and msgbox(fdir[2,1]) gives me the complete file names.
I am working on
d:= fdir[1,1]
c:= 'q'+d
copy file d to c
erase(d) or something lik this.
??????????????
All the best,
Franco
rename will work but not with *`s you must use complete file names. I am working on directory as it brings in all of the files starting with w.
At this point I am trying to create a loop for the renaming. I have the first file working. I am not sure whether to use a do while loop or a for loop.
fdir:= DIRECTORY('w*.jpg')
msgbox(fdir[1,1]) and msgbox(fdir[2,1]) gives me the complete file names.
I am working on
d:= fdir[1,1]
c:= 'q'+d
copy file d to c
erase(d) or something lik this.
??????????????
All the best,
Franco
All The Best,
Franco
Canada
Franco
Canada
- AUGE_OHR
- Posts: 2060
- Joined: Sun Aug 25, 2019 3:12 pm
- DBs Used: DBF, PostgreSQL, MySQL, SQLite
- Location: Hamburg, Germany
Re: Print .jpg in pdf print
Tip : use Constant instead of Number
Code: Select all
#include "directry.ch"
msgbox(fdir[1,F_NAME]) and msgbox(fdir[2,F_NAME])
when Soure and Target are on Different Physical Drive it will work that Way but if on same Physical Drive it is better to "Move" Files.franco wrote: ↑Thu Jan 02, 2020 10:12 pm I am working onCode: Select all
d:= fdir[1,1] c:= 'q'+d copy file d to c erase(d)
or something lik this.
---
i use Windows API Function SHFileOperation()
have a look at c:\hmg.3.4.4\HARBOUR\contrib\hbwin\tests\shfileop.prg
it use a Array for Source and a Array for Target so will "RENAME" it "on-fly"
btw. as it is the same Way like Explorer you will get "Animation" if you like
p.s. use full Path + Filename in Array
have fun
Jimmy
Jimmy
Re: Print .jpg in pdf print
I now have this all working and have a sample i would like to post. I need one more request.
Does anyone know how to find a folder in hmg when you know the drive and the final folder name in winows 10.
My windows camera keeps files in a certain folder and can not change name of the folder where it keeps the jpg files.
You can change the drive letter in windows but not folder. I can find it manually but it is hard for my clients.
I know the folder is in the C: drive and the final folder name is CAMERA ROLL.
My folder is c:\users\fr\pictures\camera roll.
How can I find this inside a program. a:= directory( C:\*camera roll) does not work
Any thoughts
Thanks in advance
Franco
Does anyone know how to find a folder in hmg when you know the drive and the final folder name in winows 10.
My windows camera keeps files in a certain folder and can not change name of the folder where it keeps the jpg files.
You can change the drive letter in windows but not folder. I can find it manually but it is hard for my clients.
I know the folder is in the C: drive and the final folder name is CAMERA ROLL.
My folder is c:\users\fr\pictures\camera roll.
How can I find this inside a program. a:= directory( C:\*camera roll) does not work
Any thoughts
Thanks in advance
Franco
All The Best,
Franco
Canada
Franco
Canada
Re: Print .jpg in pdf print
Try
hb_DirScan(<cPath>, [<cFileMask>], [<cAttr>]) ➜ aFiles
similar to 'hb_Directory()' with the difference that it scans not only <cPath> but also all subdirectories below <cPath> (recursively)
hb_DirScan(<cPath>, [<cFileMask>], [<cAttr>]) ➜ aFiles
similar to 'hb_Directory()' with the difference that it scans not only <cPath> but also all subdirectories below <cPath> (recursively)
- AUGE_OHR
- Posts: 2060
- Joined: Sun Aug 25, 2019 3:12 pm
- DBs Used: DBF, PostgreSQL, MySQL, SQLite
- Location: Hamburg, Germany
Re: Print .jpg in pdf print
use Environment "USERPROFILE"
Code: Select all
LOCAL cUserDir := Getenv("USERPROFILE")
LOCAL cImageDir := cUserDir+"\pictures\camera\"
LOCAL aDir := Directory(cImageDir+"*.*")
have fun
Jimmy
Jimmy
Re: Print .jpg in pdf print
Edk do you have a sample I can not get yours to work.
Auge_Ohr Thanks for responce.
There are 2 possible folders where windows 10 keeps picture files.
Getenv("USERPROFILE")+"\pictures'+'\camera roll"
Getenv("USERPROFILE")+"\onedrive\pictures'+'\camera rol"
This code will work but seems to be a lot of code to find if a folder exists plus the folder needs a file in it to work.
All the best,
Franco
Auge_Ohr Thanks for responce.
There are 2 possible folders where windows 10 keeps picture files.
Getenv("USERPROFILE")+"\pictures'+'\camera roll"
Getenv("USERPROFILE")+"\onedrive\pictures'+'\camera rol"
This code will work but seems to be a lot of code to find if a folder exists plus the folder needs a file in it to work.
Code: Select all
function ncam
LOCAL PD := .F., LSUCCESS, tfile, ffile, ffile2
LOCAL fdir := {} , filen := 0, filen1 := 0
LOCAL tf,df
ffile := Getenv("USERPROFILE")+'\pictures'+'\camera roll\' // name of folder where windows saves pictures
ffile2:=ffile
fdir:= DIRECTORY(ffile2+'*.*')
filen:= len(fdir)
if filen = 0
ffile := Getenv("USERPROFILE")+'\onedrive\pictures'+'\camera roll\' // name of folder where windows saves pictures
ffile2:=ffile
fdir:= DIRECTORY(ffile2+'*.*')
filen:= len(fdir)
if filen = 0
msgbox(ffile2+' Is Incorrect Or Picture is Empty. No Picture Taken** Folder Must Have a Picture From Windows Camera In It.')
endif
endif
do while filen <> 0
if filen == 0
exit
endif
df:= ffile+fdir[filen,1]
tf:= ffile+'Q'+fdir[filen,1]
rename &df to &tf
filen := filen -1
loop
enddo
if file(tf)
msgbox('y')
endif
msgbox(tf)
return
Franco
All The Best,
Franco
Canada
Franco
Canada
Re: Print .jpg in pdf print
Code: Select all
#include "hmg.ch"
#include "directry.ch"
FUNCTION Main()
Local aFolders, aFiles, cDirName, aAllFiles:={}
Local cStartPath:=GetEnv("USERPROFILE") + "\"
msgbox('Search for files in all "Camera Roll" subfolders of the "' + cStartPath + '"' )
aFolders:=hb_DirScan( cStartPath, "Camera Roll", "D" /* Folders */)
AEVAL ( aFolders, { |aDir| ( cDirName:=aDir [ F_NAME ], aFiles:=hb_Directory ( cStartPath + cDirName + "\*.*" ), AEVAL ( aFiles, { |aFile| AADD (aAllFiles , cStartPath + cDirName + "\" + aFile [ F_NAME ] ) } ) ) } )
MsgDebug (aAllFiles)
Return Nil
Re: Print .jpg in pdf print
Edk This is what I came up with and works perfectly
Thanks so much.
PS have you looked at my camera problem hmg camera does not create real jpg files to put in pdf.
Mustafa came up with working solution but a lot of code and not quite as clear of picture.
Code: Select all
#include "hmg.ch"
#include "directry.ch"
FUNCTION Main()
Local aFolders, aFiles, cDirName, aAllFiles:={}
Local cStartPath:=GetEnv("USERPROFILE") + "\", cCamPath
aFolders:=hb_DirScan( cStartPath, "Camera Roll", "D" /* Folders */)
AEVAL ( aFolders, { |aDir| ( cDirName:=aDir [ F_NAME ], aFiles:=hb_Directory ( cStartPath + cDirName + ' '),; //"\*.*" ) ,;
AEVAL ( aFiles, { |aFile| AADD (aAllFiles , cStartPath + cDirName + "\" + aFile [ F_NAME ] ) } ) ) } ) //*MsgDebug(aAllFiles)
cCamPath:=cStartPath+cdirname
msgbox(cCamPath)
Return Nil
PS have you looked at my camera problem hmg camera does not create real jpg files to put in pdf.
Mustafa came up with working solution but a lot of code and not quite as clear of picture.
All The Best,
Franco
Canada
Franco
Canada
Re: Print .jpg in pdf print
This is a complete little program that will work on win10 laptop or tablet.
Thanks to all that have helped me with this.
Thanks to all that have helped me with this.
Code: Select all
#include <hmg.ch>
#include "directry.ch"
Function Main
PRIVATE mpic := '1234-1'
PUBLIC mcamname, mpickfold := ''
* a:= hb_DirScan(c: [camera roll],[.jpg])
files()
ffile:= mpickfold+'*.*'
if ! file(ffile)
msgbox('Picture Folder Not Set Correctly Or No Pictures In Folder ** '+mpickfold+ ' ** Must Have A Picture')
return
endif
DEFINE WINDOW Form_1 ;
AT 0,0 ;
WIDTH 1200 ;
HEIGHT 700 ;
MAIN;
TITLE 'Button Test'
define button button_1
row 550
col 200
height 30
width 100
caption 'Get Picture'
action winpick()
end button
define button button_2
row 550
col 400
height 30
width 100
caption 'Exit'
action form_1.release
end button
define image image_1
row 30
col 200
height 300 //getdesktopheight()-110
width 360 //getdesktopwidth()-50 //-50
picture mpic+'.jpg'
stretch .t.
ADJUSTIMAGE .T.
end image
END WINDOW
ACTIVATE WINDOW Form_1
Return
Function winpick
LOCAL pd := .F., lSuccess, tfile, ffile, ffile2
LOCAL fdir := {} , filen := 0, filen1 := 0
LOCAL tf,df
ffile := mpickfold // name of folder where windows saves pictures
ffile2:=ffile
fdir:= DIRECTORY(ffile2+'w*.jpg')
filen:= len(fdir)
do while filen <> 0
if filen == 0
exit
endif
df:= ffile+fdir[filen,1]
tf:= ffile+'Q'+fdir[filen,1]
rename &df to &tf
filen := filen -1
loop
enddo
if len(alltrim(mcamname)) > 0
mycam()
endif
msgbox('Take Picture','Escape to Exit')
ffile:= (ffile2+'w*.jpg')
if ! file(ffile)
msginfo('Picture Not Taken')
return
endif
fdir:= DIRECTORY(ffile) //+'w*.jpg')
filen:= len(fdir)
df:= ffile2+fdir[filen,1]
tf:=alltrim(mpic)+'.jpg'
copy file &df to &tf
tfile := mpic+'.jpg'
do while filen <> 0 // takes out pictures taken by program not by windows camera
if filen == 0
exit
endif
df:= ffile2+fdir[filen,1]
erase(df)
filen := filen -1
loop
enddo
IF MSGYESNO('Do You Want to Print to PDF')
SELECT PRINTER PDF mpic+'.pdf' TO lSuccess
IF LSUCCESS == .F.
MSGINFO('PDF File Not Available')
RETURN
ENDIF
PD := .T.
ELSE
SELECT PRINTER DEFAULT TO lSUCCESS preview ;
ORIENTATION PRINTER_ORIENT_PORTRAIT ;
PAPERSIZE PRINTER_PAPER_LETTER ;
QUALITY PRINTER_RES_MEDIUM
ENDIF
IF LSUCCESS == .F.
MSGINFO('Printer Not Available')
RETURN
ENDIF
START PRINTDOC
START PRINTPAGE
PL := 8
@ PL,10 PRINT ' Hello to all:' SIZE 10
@ PL,170 PRINT 'Date: '+DTOC(DATE()) SIZE 10
PL:= PL+20
IF FILE(tfile)
@ PL,10 PRINT IMAGE tfile WIDTH 80 HEIGHT 60 TYPE JPG stretch
ENDIF
@ 100,90 PRINT 'End of Report:'
END PRINTPAGE
END PRINTDOC
IF PD = .T.
EXECUTE FILE mpic+'.PDF'
ENDIF
PD := .F.
Form_1.image_1.picture := mpic+'.jpg'
return
Function mycam
LOCAL cCMD
cCMD := mcamname //'start microsoft.windows.camera:'
hb_RUN (cCMD)
return
function files
if ! file('control.dbf')
CF := {}
aADD(CF,{'CAMNAME' ,'C' , 80,0})
aADD(CF,{'PICTFOLD' ,'C' , 80,0})
DBCREATE( 'CONTROL.DBF',CF )
USE
USE CONTROL NEW SHARED
APPEND BLANK
REPLACE CAMNAME WITH 'start microsoft.windows.camera:'
USE
endif
USE CONTROL EXCLUSIVE
GO 1
MCAMNAME := CAMNAME
IF LEN(ALLTRIM(PICTFOLD)) = 0
newcam2()
*MPICKFOLD := INPUTBOX('Enter Picture Folder Name Must End With \') // you must know where windows camera keeps pictures
REPLACE PICTFOLD WITH MPICKFOLD+'\'
ENDIF
MPICKFOLD := ALLTRIM(PICTFOLD)
USE
return
function newcam2
*#include "hmg.ch"
*#include "directry.ch"
*FUNCTION Main()
Local aFolders, aFiles, cDirName, aAllFiles:={}
Local cStartPath:=GetEnv("USERPROFILE") + "\" //, mPickFold
aFolders:=hb_DirScan( cStartPath, "Camera Roll", "D" /* Folders */)
AEVAL ( aFolders, { |aDir| ( cDirName:=aDir [ F_NAME ], aFiles:=hb_Directory ( cStartPath + cDirName + ' '),; //"\*.*" ) ,;
AEVAL ( aFiles, { |aFile| AADD (aAllFiles , cStartPath + cDirName + "\" + aFile [ F_NAME ] ) } ) ) } ) //*MsgDebug(aAllFiles)
MpickFold := cStartPath + cDirName
Return Nil
All The Best,
Franco
Canada
Franco
Canada
Re: Print .jpg in pdf print
Check my solution (auto capture new jpg files from Camera Roll folders):
Code: Select all
#include <hmg.ch>
#include "directry.ch"
Function Main
Local aCamFolders:=getcamfolders() //List of Camera Roll folders
Public aCamFiles:=getcamfiles( aCamFolders ) //List of current cam files in all Camera Roll folders
DEFINE WINDOW Form_1 ;
AT 0,0 ;
WIDTH 1200 ;
HEIGHT 700 ;
MAIN;
TITLE 'Button Test'
define button button_1
row 550
col 50
height 30
width 200
caption 'Start Windows Cam'
action hb_RUN ('start microsoft.windows.camera:')
end button
define button button_2
row 550
col 300
height 30
width 100
caption 'Exit'
action form_1.release
end button
define button button_3
row 550
col 450
height 30
width 150
caption 'Check Cam Folders'
action CheckCamFolder( aCamFolders )
end button
DEFINE CHECKBOX AutoCheck
ROW 550
COL 650
CAPTION "Auto Check Cam Folders"
WIDTH 160
VALUE .T.
ON CHANGE (Form_1.button_3.Enabled := !Form_1.AutoCheck.VALUE, Form_1.CheckCamFolder.Enabled:=Form_1.AutoCheck.VALUE )
END CHECKBOX
Form_1.button_3.Enabled := !Form_1.AutoCheck.VALUE
DEFINE CHECKBOX MakePDF
ROW 550
COL 850
CAPTION "Make PDF"
VALUE .T.
END CHECKBOX
define image image_1
row 30
col 200
height 300 //getdesktopheight()-110
width 360 //getdesktopwidth()-50 //-50
picture ""
stretch .f.
ADJUSTIMAGE .f.
end image
DEFINE TIMER CheckCamFolder OF Form_1 INTERVAL 1000 ACTION CheckCamFolder( aCamFolders )
Form_1.CheckCamFolder.Enabled:=Form_1.AutoCheck.VALUE
END WINDOW
ACTIVATE WINDOW Form_1
Return
**********************************************************
Function CheckCamFolder( aCamFolders )
LOCAL aCurrentCamFiles
Local aNewCamFiles := {}, cFile
Local lSuccess:=.F., cFileName, hBitmap1
Form_1.CheckCamFolder.Enabled := .F.
aCurrentCamFiles := getcamfiles( aCamFolders )
//Compare file lists
IF Len( aCurrentCamFiles ) = 0
aCamFiles := aCurrentCamFiles
IF Form_1.AutoCheck.Value
Form_1.CheckCamFolder.Enabled := .T.
ELSE
MsgInfo ("No new .jpg files in Camera Roll folders")
ENDIF
Return
ENDIF
AEVAL ( aCurrentCamFiles , { |x| If (ASCAN( aCamFiles, x) = 0 , AADD (aNewCamFiles, x), Nil ) } )
aCamFiles := aCurrentCamFiles
IF Len(aNewCamFiles) = 0
IF Form_1.AutoCheck.Value
Form_1.CheckCamFolder.Enabled := .T.
ELSE
MsgInfo ("No new .jpg files in Camera Roll folders")
ENDIF
RETURN
ENDIF
FOR EACH cFile IN aNewCamFiles
IF Upper( HB_FNameExt ( cFile ) ) = '.JPG'
Do Events
IF File ( cFile ) .And. (hBitmap1:=BT_BitmapLoadFile (cFile)) # 0 //if still file exist and is valid jpg file`
BT_BitmapRelease (hBitmap1)
cFileName := HB_FNameName ( cFile )
Form_1.Image_1.picture:=cFile
form_1.image_1.refresh
IF Form_1.MakePDF.VALUE
SELECT PRINTER PDF cFileName+'.pdf' TO lSuccess
ELSE
SELECT PRINTER DEFAULT TO lSUCCESS preview ;
ORIENTATION PRINTER_ORIENT_PORTRAIT ;
PAPERSIZE PRINTER_PAPER_LETTER ;
QUALITY PRINTER_RES_MEDIUM
ENDIF
IF !lSuccess
IF Form_1.AutoCheck.Value
Form_1.CheckCamFolder.Enabled := .T.
ENDIF
RETURN
ENDIF
START PRINTDOC
START PRINTPAGE
@ 8,10 PRINT ' Hello to all:' SIZE 10
@ 8,170 PRINT 'Date: '+DTOC(DATE()) SIZE 10
@ 28,10 PRINT IMAGE cFile WIDTH 80 HEIGHT 60 TYPE JPG stretch
@ 100,90 PRINT 'End of Report:'
END PRINTPAGE
END PRINTDOC
IF Form_1.MakePDF.VALUE .AND. File( cFileName+'.pdf' )
EXECUTE FILE cFileName+'.pdf'
ENDIF
ELSEIF hBitmap1 = 0 .AND. !Form_1.AutoCheck.Value
MsgStop ( 'Invalid .jpg file: ' + cFile )
ENDIF File ( cFile ) .And. (hBitmap1 := BT_BitmapLoadFile (cFile)) # 0
ENDIF Upper( HB_FNameExt ( cFile ) ) = '.JPG'
NEXT
RELEASE MEMORY
IF Form_1.AutoCheck.Value
Form_1.CheckCamFolder.Enabled := .T.
ENDIF
Return
**********************************************************
function getcamfolders( )
Local aCamDirs:={}
Local cStartPath:=GetEnv("USERPROFILE") + "\"
AEVAL (hb_DirScan( cStartPath, "Camera Roll", "D" /* Folders */), { |aDir| AADD (aCamDirs, cStartPath + aDir [ F_NAME ] ) } )
Return aCamDirs
**********************************************************
function getcamfiles( aCamFolders )
Local cDirName, aAllFiles:={}
AEVAL ( aCamFolders, { |cDir| (cDirName:=cDir, ;
AEVAL ( hb_Directory ( cDirName + '\*.jpg' ), { |aFile| AADD (aAllFiles , cDirName + "\" + aFile [ F_NAME ] ) } ) ) } )
Do Events
Return aAllFiles