DCPRINT with Microsoft Print To PDF

If you are converting a text-based Clipper application, a FoxPro application or just writing an application from scratch, use this forum for your eXpress++ questions.
Message
Author
Koverhage
Posts: 150
Joined: Mon Feb 01, 2010 8:45 am

DCPRINT with Microsoft Print To PDF

#1 Post by Koverhage »

The printer "Microsft Print To PDF" is a part of WIN10
Has anyone done this ?
How ?
Klaus

User avatar
rdonnay
Site Admin
Posts: 4722
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: DCPRINT with Microsoft Print To PDF

#2 Post by rdonnay »

I am now working in Win 10 and I have been meaning to test this.

I will get to it soon.
The eXpress train is coming - and it has more cars.

User avatar
alepap
Posts: 94
Joined: Tue Jul 28, 2015 5:15 am

Re: DCPRINT with Microsoft Print To PDF

#3 Post by alepap »

DCPRINT works fine for me with Microsoft Print to PDF.

I use it as a printer. The printer name is not pre-defined. The printer select window will allow you to select this printer.
You than need to specify the file name of your choice.

Koverhage
Posts: 150
Joined: Mon Feb 01, 2010 8:45 am

Re: DCPRINT with Microsoft Print To PDF

#4 Post by Koverhage »

I know that, but this is not what i want.
I want use the OUTFILE clause as with Bullzip PDF or Microsoft Image Writer.
Klaus

User avatar
rdonnay
Site Admin
Posts: 4722
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: DCPRINT with Microsoft Print To PDF

#5 Post by rdonnay »

I understand that you want it to work like Bullzip but I don't yet know how to do that.
I'll try to get to it this week.
The eXpress train is coming - and it has more cars.

Cliff Wiernik
Posts: 605
Joined: Thu Jan 28, 2010 9:11 pm
Location: Steven Point, Wisconsin USA
Contact:

Re: DCPRINT with Microsoft Print To PDF

#6 Post by Cliff Wiernik »

I see an example for C# that uses there PrinterDocument object and PrinterSettings object. Then they use the doc.Printout() method with one of the parameters being OutputFileName. However, I do not yet know how to make that work in Xbase++.

http://stackoverflow.com/questions/3189 ... me-in-c-sh

I don't use the Xbase++/Express++ printing much so my exposure is limited.

User avatar
rdonnay
Site Admin
Posts: 4722
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: DCPRINT with Microsoft Print To PDF

#7 Post by rdonnay »

PrinterDocument object and PrinterSettings object
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.
See below.

It will take time to figure out how to do this with the Microsoft Print to PDF.

Also, this technique is not thread-safe.
You must be careful not to run more than 1 print job simultaneously.
I found this out when using BULLZIP in an application that creates PDF reports in multiple threads.

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
The eXpress train is coming - and it has more cars.

Cliff Wiernik
Posts: 605
Joined: Thu Jan 28, 2010 9:11 pm
Location: Steven Point, Wisconsin USA
Contact:

Re: DCPRINT with Microsoft Print To PDF

#8 Post by Cliff Wiernik »

I found this code at the stackoverflow link provide in the post two items above. This c# code gave me the idea that the way the Micrsoft Print to PDF drive was implemented is in the standard windows printer dialog was you just define the xbpprinter:setprintfile() method to the desired file name. I did not check Roger's DCPRINT code to see if the TOFILE OUTFILE was implementing the :setprintfile() method but I thought is was. So in my included code snippet below, I just simply took my screen print routine that sends the capture screen image oBitMap to the current default printer, which prints it normally on a printer, and changed the code to instead use the DCPRINT ... TOFILE OUTFILE .... commands to see if took the screen image, generated it as a PDF and sent it to the desired file.

Well it appears to work correctly without any special Express++ code changes or handling. You just specify your "Microsoft Print to PDF" driver as the printer and use the TO FILE c:\pdfexport\test111.pdf clause and it generated the attached PDF file which is an exact replica of the printed page. So it is working as desired.

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
The above code creates the printer object, gets the default printer, which I set as the "Microsoft Print to PDF" driver, set the output file to "C:\PDFEXPORT\TEST111.PDF" and then prints out the screen image captured in oBitMap. It generated the PDF, readable by Adobe DC and with the specified filename. No manual intervention. The test111.pdf generated is included in the attached test111.zip file.
test111.zip
(247.72 KiB) Downloaded 987 times

skiman
Posts: 1183
Joined: Thu Jan 28, 2010 1:22 am
Location: Sijsele, Belgium
Contact:

Re: DCPRINT with Microsoft Print To PDF

#9 Post by skiman »

Hi Cliff,

Thanks for sharing this. It is working as a charm. No need anymore to do an install of PdfCreator (which we were using). I modified my software to check if 'Microsoft print to PDF' is available and use it as standard PDF writer/creator if it is.

It is very fast, much faster according to PDFCreator. The PDF is larger, but this is not a big deal.
Best regards,

Chris.
www.aboservice.be

User avatar
rdonnay
Site Admin
Posts: 4722
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: DCPRINT with Microsoft Print To PDF

#10 Post by rdonnay »

Wow! I didn't expect it to be that simple, especially after my experiences with Win2PDF and BullZip.

Here's a little test program that works.
Now I'm going to add support for Microsoft Print to PDF as a print previewer.

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
The eXpress train is coming - and it has more cars.

Post Reply