1

Working on a legacy application. im looking for a way to preset the output filename & Bypass 'Save As' dialogue after sending document to pdf printer VB6. Im printing a report but i want to programmatically set the filename and avoid seeing the 'save as' common dialog. Pls help

'Determine Default Printer
    
Dim PrintData As Printer
Dim defprinterpos%
Lstprinter.Clear
For Each PrintData In Printers
    ' Add printer name and port to list
    Lstprinter.AddItem PrintData.DeviceName '& " at: " & PrintData.Port
    ' Check for default printer
    If PrintData.DeviceName = Printer.DeviceName Then defprinterpos = Lstprinter.NewIndex
Next
Lstprinter.ListIndex = defprinterpos%
    frmmain.lblPrinter.Caption = Lstprinter.List(Lstprinter.ListIndex)
    
   ' SetPrinter ("Microsoft Print to PDF")
   If Check4.Value = 1 Then
                Dim PrinterName As String
                PrinterName = "Microsoft Print to PDF" '"CutePDF Writer"
                Dim w As New WshNetwork
                w.SetDefaultPrinter (PrinterName)
                Set w = Nothing
  End If
    
    ' print the Sales Invoice
   rptsales.printreport
    
StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
  • This will depend on what PDF printer you are using. For instance, I use both [Win2PDF](https://www.win2pdf.com/) which requires payment to remove watermarks and [Bullzip PDF Printer](https://www.bullzip.com/products/pdf/info.php) which is free for a limited number of users. Both use the registry to set the output path and filename for the PDF file which can be done via VB6 but they use very different methods which is detailed in their documentation. As far as I know it's not possible to programatically set the filename/path on the built-in offering in Windows 10. – John Eason Jul 24 '21 at 17:53
  • You can do it, but you need to call `StartDoc()` in GDI32. That means you'll need to print using `TextOut()` or `DrawText()` as well as GDI32 `StartPage()`, `EndPage()`, and `EndDoc()` calls. You can't use the methods of the `Printer` object. – Bob77 Jul 24 '21 at 22:47
  • @Bob77 Fair enough but I was rather dismissing creating the entire page programatically which could be **a lot** of work! :^) – John Eason Jul 24 '21 at 23:55
  • Unfortunately, you haven't mentioned the source file format of the reports from which you attempt to create a PDF. If it already is HTML or you can (re-)create your reports in HTML, have a look at [wkhtmltopdf](https://wkhtmltopdf.org/). It's a console application that can create PDFs from HTML files _(and even add a thing or two to the created PDF)_. I've used it with create success in the past, creating literally tens of thousands of PDFs. – Hel O'Ween Jul 26 '21 at 08:36
  • Here's example code for setting a file name from VB6 using [Win2PDF](https://www.win2pdf.com): [https://www.win2pdf.com/doc/usingtheprinterobject.html](https://www.win2pdf.com/doc/usingtheprinterobject.html) – Craig Lebakken Jul 26 '21 at 16:41
  • [Here](https://github.com/VBForumsCommunity/vbimg2pdf) as a VB6 utility that uses "Microsoft Print to PDF" and `Start/EndDoc` API functions with `DOCINFO.lpszOutput` set to output PDF filename. – wqw Aug 03 '21 at 14:37

0 Answers0