ENG
I have long been waiting for a program to generate PDF files from any text
and which will be an integral part of windows. Finally arrived:
Microsoft Print to PDF
But (there is always someone but) many parameters cannot be set for this pdf printer:
- cannot specify your pdf file name
- cannot specify your folder in which the pdf file will be written
- the start of the PDF reader cannot be switched off and on after the PDF file has been generated
- the file dialog requesting the name of the PDF file cannot be switched off or on
So far, this has not been documented by Microsoft
And then comes Roger Donnay and eXpress ++ ...
The best thing about the whole story is that eXpress ++ is great for working with
printer: Microsoft Print to PDF and gives you the ability to have it all
the functions listed above.
For example, the basic command DCPRINT ON
- from the given string: aTxt,
- create the specified file: PDFTEST.PDF,
- in the specified folder: "D: \ PDF DOCUMENTS"
- does not open a file-dialog for entering the file name (Save As)
- either does not call the PDF reader or
- calls the default PDF reader and displays the pdf file in it: PDFTEST.PDF
SRB
Odavno sam čekao program za generisanje PDF fajlova iz bilo kog teksta
a koji će biti sastavni deo windows-a. Najzad je stigao:
Microsoft Print to PDF
Ali (uvek ima neko ali) tom pdf printeru se ne mogu zadati mnogi parametri:
- ne može se zadati svoj naziv pdf fajla
- ne može se zadati svoj folder u koji će pdf fajl biti upisan
- ne može se isključiti i uključiti start PDF readera posle generisanja PDF fajla
- ne može se isključiti ili uključiti file-dialog sa upitom za naziv PDF fajla
Za sada ovo nije dokumentovano kod Microsofta
I tada dolazi Roger Donnay i eXpress++...
U celoj priči najlepše je to, što eXpress++ odlično podržava rad sa
printerom: Microsoft Print to PDF i daje vam mogućnost da imate sve
gore nabrojane funkcije.
Na primer, osnovna komanda DCPRINT ON
- iz zadatog niza : aTxt,
- kreira zadati fajl : PDFTEST.PDF,
- u zadatom folderu : "D:\PDF DOCUMENTS"
- pri tom ne otvara file-dialog za upis naziva fajla (Save As)
- pri tom ili ne poziva PDF reader ili
- poziva zadati PDF reader i u njemu prikazuje pdf fajl: PDFTEST.PDF
* ---
Code: Select all
FUNCTION PRINT2PDF(cPDFfilePath,aTxt)
LOCAL oPrinter, i, aOptions
LOCAL nFolder, cFolder, x
// cPDFfilePath je PDF fajl koji se generiše iz programa
// cPDFfilePath is a PDF file generated from the program
cPDFfilePath := "D:\PDF DOCUMENTS\PDFTEST.PDF"
// cTxt je niz koga sačinjavaju redovi teksta iz nekog tekst dokumenta: test.txt
// cTxt is a array made up of lines of text from a text document: test.txt
// cTxt := {row1,row2,row3,... row2000}
* ---
// Napravi folder ako ga nema
// Create a folder if it doesn't exist
nFolder:=rat("\",cPDFfilePath)
if nFolder>0
cFolder:=left(cPDFfilePath,nFolder-1)
DIRMAKE(cFolder) // XbToolsIII
endif
// obriši PDF fajl ako ga ima
// delete the PDF file if it exists
IF FExists(cPDFfilePath)
FErase(cPDFfilePath)
ENDIF
* ---
// aktiviraj PDF printer
// activate PDF printer
// MS Windows 10, 11...
DCPRINT ON TO oPrinter NAME "Microsoft Print to PDF" ; // PDF printer Free
TOFILE OUTFILE (cPDFfilePath) // eXpress++
IF oPrinter = NIL .OR. !oPrinter:lActive
RETURN .F.
ENDIF
DCPRINT FONT "8.Consolas" // eXpress++
x:=0
FOR i = 1 TO len(aTxt)
x:=x+1
@ x,2 DCPRINT SAY aTxt[i] // eXpress++
IF x==60
DCPRINT EJECT // eXpress++
x:=0
ENDIF
NEXT i
DCPRINT OFF // eXpress++
// sačekaj da se PDF fajl generiše
// wait for the PDF file to be generated:
DO WHILE FSize(cPDFfilePath) < 10 // 10 byte
Sleep(50)
ENDDO
// prikaži PDF fajl iz PDF reader-a:
// show PDF file from PDF reader:
DC_SpawnUrl(cPDFfilePath) // eXpress++ // Default PDF reader
// Adobe Acrobat Reader DC 11...
*
* or:
*
* exedir := strtran(appname(.t.),appname())
* RUNSHELL('"'+cPDFfilePath+'"', exedir+"SumatraPDF.EXE") // Sumatra PDF reader
* RUNSHELL('"'+cPDFfilePath+'"', exedir+"FoxitReader.EXE") // Foxit PDF reader
RETURN .T.