dcsimg
Results 1 to 8 of 8

Thread: [RESOLVED] Automatic .pdf Naming Conundrum

  1. #1

    Thread Starter
    Member
    Join Date
    May 2008
    Posts
    51

    Resolved [RESOLVED] Automatic .pdf Naming Conundrum

    Hiya folks,

    My program has a main form that is a picture box that I capture an image from and print through the print menu. In the dialog where I list available printers is a .pdf option. Once this option has been chosen, the document is printed with the command: Printer.print.

    This brings up a save dialog box, of course, in which you get to choose the .pdf file name. And therein lies the rub. The save dialog box has an automatic file title which is "Microsoft Visual Basic". This seems pretty unprofessional for my tastes and I want to change it. But I'm not sure where this magical dialog is.

    My fear is that this means I have to rewrite this whole .pdf interface. Please tell me, no don't worry about that, all you have to do is add one line of code - there, there.

    Thanks.

  2. #2
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Automatic .pdf Naming Conundrum

    Perhaps if you let us see the code we could identify where the change should be made.

  3. #3

    Thread Starter
    Member
    Join Date
    May 2008
    Posts
    51

    Re: Automatic .pdf Naming Conundrum

    Right. So the dialog pops up just after the Printer.Print command.

    Public Sub PrintPictureBox(Box As PictureBox, BoxScale As Single)
    Dim rv As Long
    Dim ar As Boolean
    Dim printerWidth As Double
    Dim printerHeight As Double
    Dim printerPicWidth As Double
    Dim printerPicHeight As Double

    On Error GoTo Exit_Sub
    With Box
    ar = .AutoRedraw 'save autoredraw
    .AutoRedraw = True 'temporarily change autoredraw
    Printer.Orientation = cdlLandscape 'landscape orientation
    Printer.Print 'Wake up printer
    'draw everything inside picture box - controls, etc.
    rv = SendMessage(.HWND, WM_PAINT, .hDC, 0)
    rv = SendMessage(.HWND, WM_PRINT, .hDC, PRF_CHILDREN Or PRF_CLIENT Or PRF_OWNED)
    .Picture = .Image 'must refresh image to picture property




    ' Calculate the dimentions of the printable area in HiMetric.
    printerWidth = Printer.ScaleX(Printer.ScaleWidth, Printer.ScaleMode, vbHimetric)
    printerHeight = Printer.ScaleY(Printer.ScaleHeight, Printer.ScaleMode, vbHimetric)
    printerWidth = printerWidth * BoxScale
    printerHeight = printerHeight * BoxScale
    printerPicWidth = Printer.ScaleX(printerWidth, vbHimetric, Printer.ScaleMode)
    printerPicHeight = Printer.ScaleY(printerHeight, vbHimetric, Printer.ScaleMode)
    printerWidth = 0.5 * (Printer.ScaleWidth - printerPicWidth)
    printerHeight = 0.5 * (Printer.ScaleHeight - printerPicHeight) + Printer.ScaleHeight * 0.02
    'print picture box
    Printer.PaintPicture Box, printerWidth, printerHeight, printerPicWidth, printerPicHeight
    .AutoRedraw = ar 'restore autoredraw




    Dim Wid As Single
    Dim Hei As Single
    Dim picwid As Single
    Dim pichei As Single
    Wid = Form1.Picture1.ScaleX(Form1.Picture1.ScaleWidth, Form1.Picture1.ScaleMode, vbHimetric)
    Hei = Form1.Picture1.ScaleY(Form1.Picture1.ScaleHeight, Form1.Picture1.ScaleMode, vbHimetric)
    Wid = Wid * BoxScale
    Hei = Hei * BoxScale
    picwid = Form1.Picture1.ScaleX(Wid, vbHimetric, Form1.Picture1.ScaleMode)
    pichei = Form1.Picture1.ScaleY(Hei, vbHimetric, Form1.Picture1.ScaleMode)
    Wid = 0.5 * (Form1.Picture1.ScaleWidth - picwid)
    Hei = 0.5 * (Form1.Picture1.ScaleHeight - pichei) + Form1.Picture1.ScaleHeight * 0.02
    Form1.Picture1.PaintPicture Box, Wid, Hei, picwid, pichei

    End With

    Exit_Sub:
    If Err.Number Then MsgBox Err.Description, vbOKOnly, "Printer Error"
    End Sub

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,247

    Re: Automatic .pdf Naming Conundrum

    i assume that you are printing to some pdf printer driver

    some can be automated, others can not
    as you do not specify which you are using, hard to guess
    some can have settings in registry to automate and specify next file name
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5
    Fanatic Member
    Join Date
    Dec 2007
    Location
    West Yorkshire, UK
    Posts
    790

    Re: Automatic .pdf Naming Conundrum

    Code:
    CommonDialog1.DialogTitle = "My new title"

  6. #6

    Thread Starter
    Member
    Join Date
    May 2008
    Posts
    51

    Re: Automatic .pdf Naming Conundrum

    Okay. Humbled as usual. Here is what is happening: the list of available printers is automatically populated by my code and the pdf writer (which will be different for different computers) is just one of the printers on my computer. This pdf writer uses the name of the program that calls it as the default file name. This means that when I was debugging the program the title was Microsoft Visual Basic. However, when my program calls the writer, the file title is my program title. So I guess I could pretty easily just change the program title while calling the writer.

    I think most of the problem here is the external program that has a really irritating file naming system.

  7. #7
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,247

    Re: [RESOLVED] Automatic .pdf Naming Conundrum

    which pdf printer driver are you using?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  8. #8

    Thread Starter
    Member
    Join Date
    May 2008
    Posts
    51

    Re: [RESOLVED] Automatic .pdf Naming Conundrum

    I have Adobe Acrobat on my computer.

Tags for this Thread

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