Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Windows10 print to pdf automation
Message
From
21/03/2016 07:07:03
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
 
 
To
20/03/2016 11:06:19
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 10
Miscellaneous
Thread ID:
01633396
Message ID:
01633415
Views:
261
>the manual way to print with Micrsoft print to pdf in win10 is :
>-choose the MS printer as default (printers panel)
>-Invok any verb "print"
>-fires a dialog box then confirm default printer (MS one)
>-preview document (adjust) and click print.
>-fires a dialog box to choose a filename(path)
>-render the pdf.
>
>How to programmatically print ( any printable file) to PDF file without prompting (silently)
>for filename from vfp using the Microsoft Print To PDF printer that comes with Windows 10 .


Via automation, you only need the first line. The rest is the defense. The checking for the current version of Word (and whether it's an older version with tha pdf exporter add-on) is left to the reader. Mind you, this is NOT printing to pdf, this is export, so no print-to-pdf or dialogs, this just silently exports. Assuming you already have the document open and it's the active document:
Word.Application.ActiveDocument.ExportAsFixedFormat(tcTargetFile, 17, .F.)
lRet=This.WaitForFile(tcTargetFile)

*=================================*
*  PROCEDURE WaitForFile(tcFile)  - wait for the file to twice open and have the same length
*=================================*
	Procedure WaitForFile(tcFile)
	Local lnUntil, lnPrevLen, lnCurLen, h, l, lnInterval
*-- give it 30 seconds into the future
	lnUntil=Seconds()+30
	lnPrevLen=-2
	lnCurLen=-1
	lnInterval=500
*-- assume that whatever writes to a file will do so at least twice a second:
	Do While lnPrevLen#lnCurLen And Seconds()<lnUntil
		This.ASleep(lnInterval)
		h=Fopen(tcFile,10)
		If h>0
*-- zero length doesn't count, still open by creator
			lnPrevLen=Iif(lnCurLen>0, lnCurLen, lnPrevLen)
			lnCurLen=Fseek(h,0,2)
			Fclose(h)
			lnInterval=100	&& once it exists, check more often
		Endif
	Enddo
	l=lnPrevLen=lnCurLen
	If Seconds()>=lnUntil
		This.oLog.Log(Textmerge([Waiting for file "<<tcfile>>" past <<DTOT(DATE())+lnuntil>>]), 3)
	Endif
	If Not l
		This.oLog.Log(Textmerge([Waiting for file "<<tcFile>>", current length <<lncurlen>>, previous <<lnprevlen>>.]))
	Endif
	Return l
Update: now I see you said "any printable file"... ah, this is only for what you can open in Word.

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform