jeudi 17 avril 2014

impression - PrintDocument c# ne fonctionne pas avec l'imprimante de FUJI FILM - Stack Overflow


My friend has a FUJI FILM ASK-2500 printer and I wrote a small program to print images using it. I test with Microsoft XPS Document writer and PDFCreater virtual printer, it worked, but it didn't work with the FUJI printer.


After click Print, the document appears on printing queue of FUJI, status is "Printing", but it disappears right after that. The printer doesn't print.


Problem is not driver, because my friend can use Windows Print Images dialog to print from FUJI. Anybody knows what is happening here?


Here is the main code


    private PrinterSettings printer;
private PrintDocument pd;
private Image i;

public string GetDefaultPrinterName()
{
var query = new ObjectQuery("SELECT * FROM Win32_Printer");
var searcher = new ManagementObjectSearcher(query);

foreach (ManagementObject mo in searcher.Get())
{
if (((bool?)mo["Default"]) ?? false)
{
return mo["Name"] as string;
}
}

return null;
}

private void button1_Click(object sender, EventArgs e)
{
try
{
pd = new PrintDocument();
pd.PrinterSettings.PrinterName = GetDefaultPrinterName();
// handle event
pd.PrintPage += new PrintPageEventHandler(print_page);
i = new Image(path);
if (i != null)
{
pd.Print();
}
}
catch (Exception ex)
{
MessageBox.Show(this, "Error : " + ex.Message, "Printer does not work.", MessageBoxButtons.OK);
}
}

private void print_page(object sender, PrintPageEventArgs args)
{
try
{
args.Graphics.DrawImage(i, args.Graphics.VisibleClipBounds);
//b.Dispose();
}
catch (Exception ex)
{
MessageBox.Show(this, "Error : " + ex.Message, "Printer does not work.", MessageBoxButtons.OK);
}
}


My friend has a FUJI FILM ASK-2500 printer and I wrote a small program to print images using it. I test with Microsoft XPS Document writer and PDFCreater virtual printer, it worked, but it didn't work with the FUJI printer.


After click Print, the document appears on printing queue of FUJI, status is "Printing", but it disappears right after that. The printer doesn't print.


Problem is not driver, because my friend can use Windows Print Images dialog to print from FUJI. Anybody knows what is happening here?


Here is the main code


    private PrinterSettings printer;
private PrintDocument pd;
private Image i;

public string GetDefaultPrinterName()
{
var query = new ObjectQuery("SELECT * FROM Win32_Printer");
var searcher = new ManagementObjectSearcher(query);

foreach (ManagementObject mo in searcher.Get())
{
if (((bool?)mo["Default"]) ?? false)
{
return mo["Name"] as string;
}
}

return null;
}

private void button1_Click(object sender, EventArgs e)
{
try
{
pd = new PrintDocument();
pd.PrinterSettings.PrinterName = GetDefaultPrinterName();
// handle event
pd.PrintPage += new PrintPageEventHandler(print_page);
i = new Image(path);
if (i != null)
{
pd.Print();
}
}
catch (Exception ex)
{
MessageBox.Show(this, "Error : " + ex.Message, "Printer does not work.", MessageBoxButtons.OK);
}
}

private void print_page(object sender, PrintPageEventArgs args)
{
try
{
args.Graphics.DrawImage(i, args.Graphics.VisibleClipBounds);
//b.Dispose();
}
catch (Exception ex)
{
MessageBox.Show(this, "Error : " + ex.Message, "Printer does not work.", MessageBoxButtons.OK);
}
}

0 commentaires:

Enregistrer un commentaire