DCPRINT with Microsoft Print To PDF
Posted: Wed Mar 15, 2017 6:54 am
The printer "Microsft Print To PDF" is a part of WIN10
Has anyone done this ?
How ?
Has anyone done this ?
How ?
Donnay Software Web Forums
http://donnay-software.com/DONNAY/
This is how Bullzip works. I had to put code in _DCPRC.PRG to use their ActiveX control for routing the output to a file.PrinterDocument object and PrinterSettings object
Code: Select all
#if XPPVER > 1900000
IF Upper(cPrinterName) == 'BULLZIP PDF PRINTER' .AND. ;
AScan(XbpPrinter():new():list(),{|c|Upper(c)=='BULLZIP PDF PRINTER'})>0
::lToFile := .f.
lToFile := .f.
::oBullZip := ActiveXObject():create('Bullzip.PDFPrinterSettings')
::oBullZip:SetValue('Output',::cOutFile)
::oBullZip:SetValue('ShowSaveAs','never')
::oBullZip:SetValue('ShowSettings','never')
::oBullZip:SetValue('ShowPdf','no')
::oBullZip:SetValue('ConfirmOverwrite','no')
::oBullZip:SetValue('ShowProgressFinished','no')
::oBullZip:SetValue('ShowProgress','no')
::oBullZip:WriteSettings()
ENDIF
#endif
Code: Select all
XbpPrinter:setPrintFile()
Set file to print to.
:setPrintFile( [<cFileName>] ) --> cOldFileName | NIL
Parameters
<cFileName>
<cFileName> must be set either to a legal file name to spool to or to the #define constant XBPPRN_FILE_PROMPT. Passing a null string ("") resets the "print to file" option.
Return
The method returns the name of the file previously set or "", if printing to a file was previously disabled. If the driver does not support this option, the return value is NIL.
Description
This method is used to re-direct print output to a file. If the constant XBPPRN_FILE_PROMPT is used for <cFileName>, the user is prompted for a file name when the :startDoc() method is executed.
Code: Select all
/// <summary>
/// Convert a file to PDF using office _Document object
/// </summary>
/// <param name="InputFile">Full path and filename with extension of the file you want to convert from</param>
/// <returns></returns>
public void PrintFile(string InputFile)
{
// convert input filename to new pdf name
object OutputFileName = Path.Combine(
Path.GetDirectoryName(InputFile),
Path.GetFileNameWithoutExtension(InputFile)+".pdf"
);
// Set an object so there is less typing for values not needed
object missing = System.Reflection.Missing.Value;
// `doc` is of type `_Document`
doc.PrintOut(
ref missing, // Background
ref missing, // Append
ref missing, // Range
OutputFileName, // OutputFileName
ref missing, // From
ref missing, // To
ref missing, // Item
ref missing, // Copies
ref missing, // Pages
ref missing, // PageType
ref missing, // PrintToFile
ref missing, // Collate
ref missing, // ActivePrinterMacGX
ref missing, // ManualDuplexPrint
ref missing, // PrintZoomColumn
ref missing, // PrintZoomRow
ref missing, // PrintZoomPaperWidth
ref missing, // PrintZoomPaperHeight
);
}
Code: Select all
oPrinter1 := XbpPrinter():new()
aPrinters := oPrinter1:list()
nPrinter := ascan(aPrinters,{|x| upper(x)=='SCREENPRINT'})
DCPRINT ON TO oPrinter NAME aPrinters[nPrinter] ORIENTATION 2 RESOLUTION {300,300} TOFILE OUTFILE C:\PDFEXPORT\TEST111.PDF
@ 0,1 DCPRINT BITMAP oBitMap PRINTER oPrinter SCALE 2
@ 64,1 DCPRINT SAY 'Printed by ' + m->SCompCode + '/' + m->oper_init PRINTER oPrinter
DCPRINT OFF PRINTER oPrinter
Code: Select all
#INCLUDE "dcdialog.CH"
#INCLUDE "dcprint.CH"
FUNCTION Main()
LOCAL oPrinter, i
DCPRINT ON NAME "Microsoft Print to PDF" TOFILE OUTFILE ('Print2Pdf.Pdf') ;
TO oPrinter
IF oPrinter = NIL .OR. !oPrinter:lActive
RETURN .f.
ENDIF
FOR i := 1 TO 50
@ i,10 DCPRINT SAY 'This is line ' + Alltrim(Str(i))
NEXT
DCPRINT OFF
RETURN nil
* ----------
PROC appsys ; RETURN