PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
File name prefilled-VBForums
Results 1 to 15 of 15

Thread: File name prefilled

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 1999
    Location
    Ruinen, Drente, Netherlands
    Posts
    192

    File name prefilled

    With commondialog.showprinter I want to save as a pdf file (W10), I will ask for the file name, I would like to see it already filled in, filled with a name from a text box in vb6. Is that possible?

  2. #2
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    4,516

    Re: File name prefilled

    Hi Kars,

    This is a very interesting question. I've been "basically" doing this for years. However, I've always recommended Power PDF by Nuance to my clients. That was the only PDF print driver I've ever found that correctly handled translucency (say, 50%) from drawings (graphs, etc.) in Office documents (particularly Excel). I've been doing this for years, and Nuance (ScanSoft before Nuance bought them) used several different ways to store and retrieve these "default" file names. My software basically handles them all (some in INI files and some in the registry).

    However, that's all for that Nuance software.

    What's most interesting is that I just tried the Windows 10 "Microsoft Print to PDF" and it correctly handles the translucencies. I'd dearly love to get out from under the need for that Nuance software. Therefore, I'll definitely be looking into this. Also, I'll need precisely what you've asked for (a default pre-filled filename for the PDF file).

    I use only API calls to prompt for which printer to use, and I also know there's a callback option with them. It will probably take this callback to achieve what you're asking. I'll take a look at it and see if I can get it sorted.

    Best Regards,
    Elroy

    EDIT1: And also, for those interested in what I'm talking about with the translucency, just create a Word document with something like the following...

    Name:  translu.png
Views: 182
Size:  7.0 KB

    ... and then use your CutePDF, PrimoPDF, or whatever your favored PDF driver is, and watch what happens.
    Last edited by Elroy; Feb 5th, 2018 at 04:40 PM.
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Apr 1999
    Location
    Ruinen, Drente, Netherlands
    Posts
    192

    Re: File name prefilled

    Hi Elroy,

    Do not make too much work of it, I was hoping for a simple solution. as there are sometimes, but which you then can not find anywhere ...

    kind regards, Kars

  4. #4
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    4,516

    Re: File name prefilled

    Hmmm, well, it's something that may be of use to me, but it is turning out to be a bit more difficult than first glance.

    I can successfully select the "Microsoft Print to PDF" with a callback when calling the PrintDlg, but that doesn't get you where you want to be.

    The problem is, that driver creates another "Save As" dialog that I don't know how to set a hook for. I searched a bit on how I might do that, but couldn't find anything.

    On a lark, I tried using SendKeys, and that actually works. Just use SendKeys to send your filename just before you actually start printing, and it'll buffer those keystrokes and put them into the "Save As" dialog when it pops up.

    However, there's one caveat to that approach. The way I did it, my thread kept the focus so the keyboard buffer just waited until my thread put a window up. However, if your printing is going to take a while, you might click some other window which will allow the keyboard buffer to flush to that other window. I'm not sure I know a solution to that off the top of my head. Ideally, we could set a hook for that "Microsoft Print to PDF" driver and run some code when the "Save As" window pops up.

    Take Care,
    Elroy
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  5. #5
    Fanatic Member wqweto's Avatar
    Join Date
    May 2011
    Posts
    681

    Re: File name prefilled

    @Elroy: I'm pretty sure that populating `pOutputFile` of `pDocInfo` param of `StartDocPrinter` API function works as expected with "Microsoft Print to PDF" printer (produces PDF w/ no Save As dialogs).

    This works with CutePDF too but produces PostScript files that need to be further processed by CutePDF's distribution of GhostScript.

    The `pOutputFile` param didn't use to work with Foxit print to PDF solutions (no idea for recent versions). Probably other print drivers do not implement it correctly too.

    cheers,
    </wqw>

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Apr 1999
    Location
    Ruinen, Drente, Netherlands
    Posts
    192

    Re: File name prefilled

    Hi all,

    Solution found! I have installed DoPDF and DoPDF puts the program name in the input field for the filename.
    After CommonDialog1.ShowPrinter I change the program name with App.Title = mytext.Text and that works perfectly!

  7. #7
    PowerPoster
    Join Date
    Feb 2006
    Posts
    18,968

    Re: File name prefilled

    This doesn't address the file name issue, but you can indeed print to the Windows 10 PDF printer driver and get translucency. A little bit of fiddling, but not that much and once you have the code written you just reuse it as much as required (almost never).

    Name:  sshot.png
Views: 157
Size:  3.9 KB

    Snipped from Acrobat Reader DC
    Attached Files Attached Files

  8. #8
    Fanatic Member wqweto's Avatar
    Join Date
    May 2011
    Posts
    681

    Re: File name prefilled

    https://gist.github.com/wqweto/f3f47...3ef1/revisions

    This 6 line patch adds optional `OutputFile` to `UPrinter.OpenPrinter` method so when using "Microsoft Print to PDF" printer you can specify output PDF filename w/o the driver showing Save As dialog at all.

    Basicly it's optionally populating DOCINFO's member w/ this:
    vb Code:
    1. mOutputFile = OutputFile
    2. If LenB(mOutputFile) <> 0 Then
    3.     DOCINFO.lpszOutput = StrPtr(mOutputFile)
    4. End If
    This built-in feature works for other print-to-pdf solutions too as already mentioned above.

    cheers,
    </wqw>

  9. #9
    PowerPoster
    Join Date
    Feb 2006
    Posts
    18,968

    Re: File name prefilled

    Good catch.

    I misread the above and assumed it only applied to DOCINFO_1 and StartDocPrinter. But yes, this of course works.

    If you are going to do this though you need to choose the printer driver in code rather than letting the user do it from a list or dialog. Otherwise you wouldn't even know which file extension to use.

  10. #10
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    4,516

    Re: File name prefilled

    For me, I sort of set this aside for a bit. But it would be nice to get it worked out. And yes, Dilettante, from my testing, I was quite pleased at the way the "Microsoft Print to PDF" driver printed the translucency. Other than Nuance, it's the only one I've seen do a good job with it.

    I sort of set it aside because there are basically two ways I do my printing. 90% of it is done through Word and Excel automation; and 10% of it is done with the Printer object (just changing the default printer as needed). I suppose, when using the Printer object, I could rewrite that code to use hPrinter and API calls. However, the Office automation is a different story. Let me give an example of how I now do it.

    First, I call this procedure named SetPdfCreatorDefaultPath. I'd show it but it's a bit long and I'm not sure others are really interested. Basically, it just patches up the default file-path for Nuance PDF Creator before its used.

    And then, I run all print occurrences through one of the following:

    Code:
    
    Public Sub WordPrint(doc As Object)
        doc.Application.DisplayAlerts = wdAlertsNone
        doc.PrintOut False  ' The False tells Word to not do anything until the document has completed printing.
        doc.Application.DisplayAlerts = wdAlertsMessageBox
    End Sub
    
    Public Sub ExcelPrint(wsh As Object)
        wsh.PrintOut
    End Sub
    
    If I were to start recommending the "Microsoft Print to PDF" to my clients rather than the "Nuance PDF Creator", I'm not sure how I'd work out that default file name (which is actually quite important). Also, Nuance offers another feature that the Microsoft driver doesn't seem to offer. If the file exists, you get prompted on whether you should "Append" or "Over-write".

    Best Regards,
    Elroy
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  11. #11
    Fanatic Member wqweto's Avatar
    Join Date
    May 2011
    Posts
    681

    Re: File name prefilled

    Quote Originally Posted by Elroy View Post
    First, I call this procedure named SetPdfCreatorDefaultPath. I'd show it but it's a bit long and I'm not sure others are really interested. Basically, it just patches up the default file-path for Nuance PDF Creator before its used.
    Btw, `PrintOut` method already has `OutputFileName` parameter and together with `PrintToFile:=True` should work with "Microsoft Print to PDF" or any other print driver that uses PDF format internally for queuing print jobs.

    cheers,
    </wqw>

  12. #12
    Hyperactive Member
    Join Date
    Aug 2016
    Posts
    263

    Re: File name prefilled

    Quote Originally Posted by Elroy View Post
    For me, I sort of set this aside for a bit. But it would be nice to get it worked out. And yes, Dilettante, from my testing, I was quite pleased at the way the "Microsoft Print to PDF" driver printed the translucency. Other than Nuance, it's the only one I've seen do a good job with it.

    I sort of set it aside because there are basically two ways I do my printing. 90% of it is done through Word and Excel automation; and 10% of it is done with the Printer object (just changing the default printer as needed). I suppose, when using the Printer object, I could rewrite that code to use hPrinter and API calls. However, the Office automation is a different story. Let me give an example of how I now do it.

    First, I call this procedure named SetPdfCreatorDefaultPath. I'd show it but it's a bit long and I'm not sure others are really interested. Basically, it just patches up the default file-path for Nuance PDF Creator before its used.

    And then, I run all print occurrences through one of the following:

    Code:
    
    Public Sub WordPrint(doc As Object)
        doc.Application.DisplayAlerts = wdAlertsNone
        doc.PrintOut False  ' The False tells Word to not do anything until the document has completed printing.
        doc.Application.DisplayAlerts = wdAlertsMessageBox
    End Sub
    
    Public Sub ExcelPrint(wsh As Object)
        wsh.PrintOut
    End Sub
    
    If I were to start recommending the "Microsoft Print to PDF" to my clients rather than the "Nuance PDF Creator", I'm not sure how I'd work out that default file name (which is actually quite important). Also, Nuance offers another feature that the Microsoft driver doesn't seem to offer. If the file exists, you get prompted on whether you should "Append" or "Over-write".

    Best Regards,
    Elroy

    You are experts

    i have never usd print through Word and Excel

    this used api print ,may be a good example.
    https://github.com/JoshyFrancis/VB6-Print-Class

  13. #13
    Hyperactive Member
    Join Date
    Aug 2016
    Posts
    263

    Re: File name prefilled

    Quote Originally Posted by dilettante View Post
    This doesn't address the file name issue, but you can indeed print to the Windows 10 PDF printer driver and get translucency. A little bit of fiddling, but not that much and once you have the code written you just reuse it as much as required (almost never).

    Name:  sshot.png
Views: 157
Size:  3.9 KB

    Snipped from Acrobat Reader DC
    Alpha:=100 can msg err .my printer do not support this function.

    i have a ider, may print the txt in a picture, then print picture to paper ...

  14. #14
    PowerPoster
    Join Date
    Feb 2006
    Posts
    18,968

    Re: File name prefilled

    Look for a more sophisticated version in the CodeBank. Not all printer drivers support all GDI features.

  15. #15
    Fanatic Member wqweto's Avatar
    Join Date
    May 2011
    Posts
    681

    Re: File name prefilled

    Quote Originally Posted by wqweto View Post
    https://gist.github.com/wqweto/f3f47...3ef1/revisions

    This 6 line patch adds optional `OutputFile` to `UPrinter.OpenPrinter` method so when using "Microsoft Print to PDF" printer you can specify output PDF filename w/o the driver showing Save As dialog at all.

    Basicly it's optionally populating DOCINFO's member w/ this:
    vb Code:
    1. mOutputFile = OutputFile
    2. If LenB(mOutputFile) <> 0 Then
    3.     DOCINFO.lpszOutput = StrPtr(mOutputFile)
    4. End If
    This built-in feature works for other print-to-pdf solutions too as already mentioned above.

    cheers,
    </wqw>
    No good deed goes unpunished: I just got "Unattributed Code warning" private message from the admins for the link with the *diff* above. . .

    Unfortunately there is no easy way to post a link to the diff *only* on gist.github.com. Built-in diff shows the previous (original) version as well.

    Sigh.

    cheers,
    </wqw>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width