By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,668 Members | 1,716 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,668 IT Pros & Developers. It's quick & easy.

Page Setup to print PDF from WebBrowser control

P: n/a
I want to call Page Setup to set default printer and page size and
orientation before batch printing pdf's silently from WebBrowser controls. I
can print silently using DDE (the NDde library) or Adobe Interapplication
Communication (IAC) DotNet API. There is no Adobe DDE command or IAC API
for Page Setup. I don't see a print silent method for the WebBrowser
control.

I can get a Page Setup dialog to appear by using the code below, but the IAC
or DDE Adobe print methods always use current printer settings and ignore
any changes in the Page Setup dialog settings. The
webBrowser1.ShowPageSetupDialog() does not show when triggered from a button
when a pdf is loaded into a webBrowser control. How can I program Page Setup
to print a pdf from a WebBrowser control?

using NDde.Client;
using Acrobat;

private void btnPageSetup_Click(object sender, EventArgs e)
{
PRINTDLG printdlg = new PRINTDLG();
printdlg.Flags = PD_PRINTSETUP;
printdlg.lStructSize = Marshal.SizeOf(printdlg);
bool result = PrintDlg(printdlg);
}

[DllImport("comdlg32.dll", CharSet = CharSet.Auto)]
static extern bool PrintDlg([In, Out] PRINTDLG lppd);

const int PD_PRINTSETUP = 0x40;

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto, Pack =
1)]
[System.Runtime.InteropServices.ComVisible(false)]
public class PRINTDLG
{
public Int32 lStructSize;
public IntPtr hwndOwner;
public IntPtr hDevMode;
public IntPtr hDevNames;
public IntPtr hDC;
public Int32 Flags;
public Int16 nFromPage;
public Int16 nToPage;
public Int16 nMinPage;
public Int16 nMaxPage;
public Int16 nCopies;
public IntPtr hInstance;
public IntPtr lCustData;
public IntPtr lpfnPrintHook;
public IntPtr lpfnSetupHook;
public IntPtr lpPrintTemplateName;
public IntPtr lpSetupTemplateName;
public IntPtr hPrintTemplate;
public IntPtr hSetupTemplate;
}

private void btnPrint_Click(object sender, EventArgs e)
{
////Adobe IAC API
//CAcroAVDoc avDoc = new AcroAVDocClass();
//avDoc.Open("D:\\06094.pdf", "");
//avDoc.PrintPagesSilent(0, 0, 0, 0, 1);

//Open DDE connection using NDde library
using (DdeClient client = new DdeClient("acroview", "control"))
{
client.Connect();
string fileOpen = "[FileOpen(\"D:\\\\06094.pdf\")]";
string filePrintSilent =
"[FilePrintSilent(\"D:\\\\06094.pdf\")]";
client.Execute(fileOpen, 60000);
client.Execute(filePrintSilent, 60000);
}

--Tim Sprout

Jul 12 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Tim Sprout wrote:
I want to call Page Setup to set default printer and page size and
orientation before batch printing pdf's silently from WebBrowser
controls. I can print silently using DDE (the NDde library) or Adobe
Interapplication Communication (IAC) DotNet API. There is no Adobe DDE
command or IAC API for Page Setup. I don't see a print silent method for
the WebBrowser control.

I can get a Page Setup dialog to appear by using the code below, but the
IAC or DDE Adobe print methods always use current printer settings and
ignore any changes in the Page Setup dialog settings. The
webBrowser1.ShowPageSetupDialog() does not show when triggered from a
button when a pdf is loaded into a webBrowser control. How can I program
Page Setup to print a pdf from a WebBrowser control?

using NDde.Client;
using Acrobat;

private void btnPageSetup_Click(object sender, EventArgs e)
{
PRINTDLG printdlg = new PRINTDLG();
printdlg.Flags = PD_PRINTSETUP;
printdlg.lStructSize = Marshal.SizeOf(printdlg);
bool result = PrintDlg(printdlg);
}

[DllImport("comdlg32.dll", CharSet = CharSet.Auto)]
static extern bool PrintDlg([In, Out] PRINTDLG lppd);

const int PD_PRINTSETUP = 0x40;

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto, Pack
= 1)]
[System.Runtime.InteropServices.ComVisible(false)]
public class PRINTDLG
{
public Int32 lStructSize;
public IntPtr hwndOwner;
public IntPtr hDevMode;
public IntPtr hDevNames;
public IntPtr hDC;
public Int32 Flags;
public Int16 nFromPage;
public Int16 nToPage;
public Int16 nMinPage;
public Int16 nMaxPage;
public Int16 nCopies;
public IntPtr hInstance;
public IntPtr lCustData;
public IntPtr lpfnPrintHook;
public IntPtr lpfnSetupHook;
public IntPtr lpPrintTemplateName;
public IntPtr lpSetupTemplateName;
public IntPtr hPrintTemplate;
public IntPtr hSetupTemplate;
}

private void btnPrint_Click(object sender, EventArgs e)
{
////Adobe IAC API
//CAcroAVDoc avDoc = new AcroAVDocClass();
//avDoc.Open("D:\\06094.pdf", "");
//avDoc.PrintPagesSilent(0, 0, 0, 0, 1);

//Open DDE connection using NDde library
using (DdeClient client = new DdeClient("acroview", "control"))
{
client.Connect();
string fileOpen = "[FileOpen(\"D:\\\\06094.pdf\")]";
string filePrintSilent =
"[FilePrintSilent(\"D:\\\\06094.pdf\")]";
client.Execute(fileOpen, 60000);
client.Execute(filePrintSilent, 60000);
}

--Tim Sprout

Further research indicates that Adobe Acrobat printer settings are
cached and not accessible without an Adobe Developer license.

http://channel9.msdn.com/forums/Tech...-to-a-printer/

--Tim Sprout

Jul 14 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.