简体   繁体   中英

How can I change the name of a print job in the printer queue?

My goal is to load up a file (htm file) in a WebBrowser control on my form. Once I have the htm file loaded I want to print it with the default printer settings.

在此处输入图片说明

Currently I can do everything above. The one thing that I can NOT do is give the print job a name. It just uses the default "file:///C:/Users/blah/blah/myfilename.htm" for the title of the print job. This is what I want to change.

Is this possible via the WebBrowser control or via the print spooler (changing the job title after the fact)?

According to the MSDN on WebBrowser.Print() ...

Prints the document currently displayed in the WebBrowser control using the current print and page settings .

So, it is a matter of changing the WebBrowser print settings. According to Microsoft, that is not allowed without changing the registry on the fly .

As a potential starting point for a workaround, there is a way to get the default PrinterSettings and set the PrintFileName like so:

PrinterSettings settings = new PrinterSettings();
settings.PrintFileName = "YourFileNameHere";

If there were a way to then assign those printer settings to your WebBrowser object, that'd be swell! Sadly, that cannot be done. But, you may be able to use the above code to engineer another solution, likely outside the scope of WebBrowser .

This is the best way i fount to print an HTML from a string

void PrintString(string strHTMLText)
{
    WebBrowser wbPrintString = new WebBrowser() { DocumentText = string.Empty };
    wbPrintString.Document.Write(strHTMLText);
    wbPrintString.Document.Title = "Type The Header You Want Here";
    Microsoft.Win32.RegistryKey rgkySetting = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Internet Explorer\\PageSetup", true);
    rgkySetting.SetValue("footer", "Type THe Footer You Want Here");
    rgkySetting.Close();
    wbPrintString.Parent = this;
    wbPrintString.ShowPrintPreviewDialog();
    wbPrintString.Dispose();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM