-
May 1st, 2012, 12:30 PM
#1
Thread Starter
Member
[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.
-
May 1st, 2012, 12:34 PM
#2
Re: Automatic .pdf Naming Conundrum
Perhaps if you let us see the code we could identify where the change should be made.
-
May 1st, 2012, 01:27 PM
#3
Thread Starter
Member
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
-
May 2nd, 2012, 06:28 AM
#4
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
-
May 2nd, 2012, 06:30 AM
#5
Re: Automatic .pdf Naming Conundrum
Code:
CommonDialog1.DialogTitle = "My new title"
-
May 2nd, 2012, 08:04 AM
#6
Thread Starter
Member
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.
-
May 2nd, 2012, 04:06 PM
#7
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
-
May 3rd, 2012, 07:48 AM
#8
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|