Hello All,
I am trying to modify TestGtkEmbed on a Linux machine to print without
presenting the print dialog box. I set the options in C++ code, including
the option for silent printing. Still, the print dialog appears. Is this
function of silent printing not implemented at all? Or am I doing it
incorrectly?
Below is the callback I created for a print button. In it I get the
nsIPrintOptions interface (into printService) and use it to set the margins
and set it to print silently. The dialog still comes up, but the margin
values I specify are correctly present in the dialog, as is the name of the
file to print to, so I know something is being set properly. Could someone
please explain why this silent printing is not working?
While I'm on the topic, check this out: Even if I set these values, and then
don't pass the printService pointer into the browserAsPrint->Printfunction
(i.e. send nsnull for the second arg of browserAsPrint->Print) the same
exact behovior takes place. Somehow those values are set despite the fact
that I did not pass in the printService object's pointer. Can someone please
explain this?
void
print_clicked_cb (GtkButton *button, TestGtkBrowser *browser)
{
nsIWebBrowser *webBrowser;
g_print("print_clicked_cb\n");
gtk_moz_embed_get_nsIWebBrowser(GTK_MOZ_EMBED(browser->mozEmbed),
&webBrowser);
if(webBrowser){
g_print("\tgot webBrowser from browser->mozEmbed.\n");
nsCOMPtr<nsIWebBrowserPrint> browserAsPrint =
do_QueryInterface(webBrowser);
nsCOMPtr<nsIDOMWindow> window;
webBrowser->GetContentDOMWindow(getter_AddRefs(window));
if (window) {
g_print("\tgot window from webBrowser.\n");
PrintListener *listener = new PrintListener();
nsCOMPtr<nsIPrintListener> printListener =
do_QueryInterface(listener);
// Set up the print options
nsresult rv;
nsCOMPtr<nsIPrintOptions> printService =
do_GetService(kPrintOptionsCID, &rv);
if (printService){
g_print("\tgot printService\n");
printService->SetPrintSilent(PR_TRUE);
printService->SetMarginTop( (double)0 );
printService->SetMarginLeft( (double)0.25 );
printService->SetMarginRight( (double)0.25 );
printService->SetMarginBottom( (double)0 );
printService->SetPrintToFile(TRUE);
gchar *szOutFileName = "printedOutput.ps";
printService->SetToFileName(NS_ConvertASCIItoUCS2(szOutFileName).GetUnicode(
));
} else {
g_print("\nfailed to get printService\n");
}
browserAsPrint->Print(
/* nsIDOMWindow * */ window,
/* nsIPrintOptions * */ printService,
/* nsIPrintListener * */ printListener);
} else g_print("\tfailed to get window from webBrowser.\n");
} else g_print("\tfailed to get webBrowser from browser->mozEmbed.\n");
g_print("leaving print_clicked_cb\n");
}
Thanks for any input anyone can provide.
Raj Tanikella