本文整理匯總了C#中System.Drawing.Printing.PrintDocument.Dispose方法的典型用法代碼示例。如果您正苦於以下問題:C# PrintDocument.Dispose方法的具體用法?C# PrintDocument.Dispose怎麽用?C# PrintDocument.Dispose使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Drawing.Printing.PrintDocument
的用法示例。
在下文中一共展示了PrintDocument.Dispose方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: createXmlApp
//如下的這個方法可以注釋掉,沒有任何的作用
public void createXmlApp()
{
// 首先創建文件
FileStream fs = File.Create(Application.StartupPath + "\\xmlAPP.xml");
fs.Close();//關閉文件
//創建 XmlDocument 以便操作
XmlDocument xmlDoc = new XmlDocument();
//xml 唯一的根,我設置的根都是root
XmlElement xmlEleRoot = xmlDoc.CreateElement("root");
// 這個配置還有一個是必須的,就是打印機的DPI, 其他的都不是必要的
XmlElement xmlElePrinter = xmlDoc.CreateElement("printer");
//打印機名稱,這裏直接設置默認打印機
PrintDocument printDoc = new PrintDocument();
xmlElePrinter.SetAttribute("PrinterName", printDoc.PrinterSettings.PrinterName);
printDoc.Dispose();//釋放資源
//DPI有兩個
xmlElePrinter.SetAttribute("DPIX", "600");
xmlElePrinter.SetAttribute("DPIY", "600");
//如下是兩個添加操作了
xmlEleRoot.AppendChild(xmlElePrinter);
xmlDoc.AppendChild(xmlEleRoot);
//保存操作
xmlDoc.Save(Application.StartupPath + "\\xmlAPP.xml");
}
示例2: Debito
public void Debito(string debitoID)
{
string today = DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year;
SqlDataReader q = dbc.query_single("SELECT c.CL_NOMBRE, r.DEBITOID ,r.PRESTAMOID ,CONVERT(VARCHAR(15), r.HE_FECHA, 105) AS FECHA ,r.CL_CODIGO ,(r.HE_MONTO + r.HE_DESC + r.HE_MORA) As CUOTA ,r.HE_OBSERV FROM debitos r inner join clientes c on (c.CL_CODIGO=r.CL_CODIGO ) where DEBITOID=" + debitoID);
if (q.Read())
{
rlines[0] = company;
rlines[1] = String.Format("{0} \t\t\t\t\t Fecha: {1}", address, q["FECHA"].ToString());
rlines[2] = string.Format("Tel.: {0}, Cel.: {1}", phone, cell);
rlines[3] = "____________________________________________ ";
rlines[4] = "\t\t\tRecibo De Debito ";
rlines[5] = "Recibo No.: " + q["DEBITOID"].ToString() + " Fecha.: " + q["FECHA"].ToString() + " Prestamo.: " + q["PRESTAMOID"].ToString() + " Cliente.: " + q["CL_CODIGO"].ToString();
rlines[6] = "Nombre.......: " + q["CL_NOMBRE"].ToString();
string[] cuotastr = q["CUOTA"].ToString().Split('.'); // split the quota into whole amount and cents
long monto = long.Parse(cuotastr[0]);
string montocent = cuotastr[1];
rlines[7] = String.Format("Monto Ingreso: {0}Pesos Con {1}/100", Number2Word(monto), montocent).ToUpper();
rlines[8] = "RD$..........: " + q["CUOTA"].ToString();
rlines[9] = "Concepto.....: " + q["HE_OBSERV"].ToString();
rlines[10] = "Valido Si Esta Debidamente Firmado y Cellado\t\t\t____________________";
rlines[11] = "1. Original Cliente / 2. Caja Ingreso / 3. Expediente Cliente";
/// print data
PrintDocument pd = new PrintDocument();
// set printing document margins
pd.DefaultPageSettings.Margins.Top = 25;
pd.DefaultPageSettings.Margins.Left = 25;
pd.DefaultPageSettings.Margins.Right = 25;
pd.PrintPage += new PrintPageEventHandler(Recibo_PrintPage);
// Print the document.
pd.Print();
pd.Dispose();
}
q.Close();
// return lines;
}
示例3: PrintBarcode2
/// <summary>
/// 這個方法是充滿打印
/// </summary>
/// <param name="printDetails"></param>
private void PrintBarcode2(queuePrintItem printDetails)
{
//深度拷貝,因為在打印事件中需要調用這個方法
currentQueueItem = ClsXmlSerialization.DeepCopy<queuePrintItem>(printDetails);
Shapes myShapes;
//首先也是取得紙張的行數和列數
try
{
myShapes = ClsXmlSerialization.Load<Shapes>(currentQueueItem.ShapesFileName);
}
catch (System.Exception ex)
{
return;//如果不能取得,那麽就直接返回
}
int intNumOfLine = myShapes.BarcodePageSettings.BarcodePaperLayout.NumberOfLine;
int intNumOfColumn = myShapes.BarcodePageSettings.BarcodePaperLayout.NumberOfColumn;
while ((currentQueueItem.IntCount > 0))
{
//如下的才能打印
if (!isprintDocument_PrintPage)
{
//如下的就是具體構造每一個printDocument了
myPrintDocument = new PrintDocument();
myPrintDocument.DefaultPageSettings.Landscape = myShapes.BarcodePageSettings.BarcodePaperLayout.LandScape;//設置是否橫向
int intP = ((queuePrintItemRowAndPages)currentQueueItem.arrlistqueuePrintItemRowAndPages[0]).intPages;
//設置多少張紙,這個打印份數隻是一個數據的,因為如果第一個沒有充滿紙張,那麽就沒必要多份了。
intPrintPage = (int)(intP / (intNumOfLine * intNumOfColumn));
if (intPrintPage == 0)//有時候會出現不足一張的情況
intPrintPage = 1;
//根據紙張的連續等問題
//設置打印機
if (strPrinterName != "")
{
myPrintDocument.PrinterSettings.PrinterName = strPrinterName;
}
myPrintDocument.PrintController = new StandardPrintController();//這個據說可以不顯示那個打印進度對框框
myPrintDocument.DocumentName = "打印條形碼";//設置完後可在打印對話框及隊列中顯示(默認顯示document)
//打印輸出(過程)
myPrintDocument.PrintPage += new PrintPageEventHandler(myPrintDocument_PrintPage);
myPrintDocument.OriginAtMargins = false;//從位於可打印區域的左上角打印
//必須得設置自定義紙張,要不然會存在頂點問題,比如說有些條形啊打印機的打印寬度為4英寸,而實際紙張寬度不是4英寸,就會存在打印時候頂點是打印機的頂點,而不是實際紙張的頂點。
myPrintDocument.DefaultPageSettings.PaperSize = myShapes.BarcodePageSettings.BarcodePaperLayout.BarcodePaperSize;//設置紙張
//如下是設置邊距
/**如下的經測試會產生不可預測的偏移
myPrintDocument.DefaultPageSettings.Margins.Top = (int)(barcodeCanvas.myShapes.BarcodePageSettings.BarcodePaperLayout.Top / 0.254);
myPrintDocument.DefaultPageSettings.Margins.Bottom = (int)(barcodeCanvas.myShapes.BarcodePageSettings.BarcodePaperLayout.Bottom / 0.254);
myPrintDocument.DefaultPageSettings.Margins.Left = (int)(barcodeCanvas.myShapes.BarcodePageSettings.BarcodePaperLayout.Left / 0.254);
myPrintDocument.DefaultPageSettings.Margins.Right = (int)(barcodeCanvas.myShapes.BarcodePageSettings.BarcodePaperLayout.Right / 0.254);
* */
//每次打印
myPrintDocument.PrinterSettings.Copies = (short)intPrintPage;//首先就是一次性全部打印完畢,設置份數就是頁數.
if (myPrintDocument.PrinterSettings.MaximumCopies < intPrintPage)//如果最高能打印的份數比要打印的頁數少,就按照最高能打印的份數.
myPrintDocument.PrinterSettings.Copies = (short)myPrintDocument.PrinterSettings.MaximumCopies;
//如果能多份打印,就需要提前刪掉那些,比如說要打印5個,每張紙可以打印2個,那麽這裏第一次的份數就是2,但是在打印進程中隻會減少2個,會造成重複打印
((queuePrintItemRowAndPages)currentQueueItem.arrlistqueuePrintItemRowAndPages[0]).intPages = ((queuePrintItemRowAndPages)currentQueueItem.arrlistqueuePrintItemRowAndPages[0]).intPages - (myPrintDocument.PrinterSettings.Copies - 1) * (intNumOfLine * intNumOfColumn);
try
{
isprintDocument_PrintPage = true;
myPrintDocument.Print();
//這裏發出打印消息。
//isprintDocument_PrintPage = true;// 因為上一個打印進程也需要時間,所以這裏先設置了。
myPrintDocument.Dispose();//釋放
}
catch (Exception ex)
{
MessageBox.Show("沒有打印成功,原因:" + ex.Message);
isprintDocument_PrintPage = false;
return;
}
}
}
//保存打印記錄,這裏用比較省事的方法
ClsDataBase myClsDataBase = new ClsDataBase();
foreach (queuePrintItemRowAndPages item in printDetails.arrlistqueuePrintItemRowAndPages)
{
myClsDataBase.commandAddPrintedRecord(printDetails.strTableName, item.arrlistRow, item.intPages);
OnBarcodePrinted(new printedEventArgs());//發出打印消息
}
}
示例4: populateVariable
//.........這裏部分代碼省略.........
barcodeCanvas.Loader(ShapeFileName);//先加載模板
}
catch (Exception ex)
{
ClsErrorFile.WriteLine("不能加載模板,所以不能打印", ex);
MessageBox.Show("不能加載模板,所以不能打印,原因是"+ ex.Message);
return 0;
//throw;
}
barcodeCanvas.setArrKeyValue(arrlist);//這個是導入變量用。
int intNumOfLine = barcodeCanvas.myShapes.BarcodePageSettings.BarcodePaperLayout.NumberOfLine;
int intNumOfColumn = barcodeCanvas.myShapes.BarcodePageSettings.BarcodePaperLayout.NumberOfColumn;
myPrintDocument.DefaultPageSettings.Landscape = barcodeCanvas.myShapes.BarcodePageSettings.BarcodePaperLayout.LandScape;//設置是否橫向
//設置多少張紙
intPrintPage = (int)(intPage / (intNumOfLine*intNumOfColumn));
if ((intPage %( intNumOfLine*intNumOfColumn)) != 0)//如果不能整除就多一張紙
intPrintPage++;
if (intPrintPage == 0)//有時候會出現不足一張的情況
intPrintPage = 1;
int intQty = intPrintPage * intNumOfLine*intNumOfColumn;
//如上是計算了要打印多少頁,因為有些條形碼紙一行有多個,需要在這裏打印。
//根據紙張的連續等問題
//設置打印機
if (strPrinterName!="")
{
myPrintDocument.PrinterSettings.PrinterName = strPrinterName;
}
myPrintDocument.PrintController = new StandardPrintController();//這個據說可以不顯示那個打印進度對框框
myPrintDocument.DocumentName = "打印條形碼";//設置完後可在打印對話框及隊列中顯示(默認顯示document)
//打印輸出(過程)
myPrintDocument.PrintPage += new PrintPageEventHandler(printDocument_PrintPage);
myPrintDocument.OriginAtMargins = false ;//從位於可打印區域的左上角打印
//必須得設置自定義紙張,要不然會存在頂點問題,比如說有些條形啊打印機的打印寬度為4英寸,而實際紙張寬度不是4英寸,就會存在打印時候頂點是打印機的頂點,而不是實際紙張的頂點。
myPrintDocument.DefaultPageSettings.PaperSize = barcodeCanvas.myShapes.BarcodePageSettings.BarcodePaperLayout.BarcodePaperSize;//設置紙張
//如下是設置邊距
/**如下的經測試會產生不可預測的偏移
myPrintDocument.DefaultPageSettings.Margins.Top = (int)(barcodeCanvas.myShapes.BarcodePageSettings.BarcodePaperLayout.Top / 0.254);
myPrintDocument.DefaultPageSettings.Margins.Bottom = (int)(barcodeCanvas.myShapes.BarcodePageSettings.BarcodePaperLayout.Bottom / 0.254);
myPrintDocument.DefaultPageSettings.Margins.Left = (int)(barcodeCanvas.myShapes.BarcodePageSettings.BarcodePaperLayout.Left / 0.254);
myPrintDocument.DefaultPageSettings.Margins.Right = (int)(barcodeCanvas.myShapes.BarcodePageSettings.BarcodePaperLayout.Right / 0.254);
* */
//每次打印
myPrintDocument.PrinterSettings.Copies = (short)intPrintPage;//首先就是一次性全部打印完畢,設置份數就是頁數.
if (myPrintDocument.PrinterSettings.MaximumCopies < intPrintPage)//如果最高能打印的份數比要打印的頁數少,就按照最高能打印的份數.
myPrintDocument.PrinterSettings.Copies = (short)myPrintDocument.PrinterSettings.MaximumCopies;
try
{
isprintDocument_PrintPage = true;
myPrintDocument.Print();
//這裏發出打印消息。
myPrintDocument.Dispose();//釋放
}
catch (Exception ex)
{
MessageBox.Show("沒有打印成功,原因:" + ex.Message);
isprintDocument_PrintPage = false;
return 0;
}
//如下是判斷是否需要打印間隔
if (isPrintJiange)
{
PrintDocument printDocPrintJianGe = new PrintDocument();
printDocPrintJianGe.PrintController = new StandardPrintController();
printDocPrintJianGe.DocumentName = "打印間隔";
printDocPrintJianGe.PrinterSettings.Copies = 1;// 間隔隻打一份。
printDocPrintJianGe.PrintPage += new PrintPageEventHandler(printDocPrintJianGe_PrintPage);
try
{
printDocPrintJianGe.Print();
printDocPrintJianGe.Dispose();//釋放資源
}
catch (Exception ex)
{
MessageBox.Show("沒有打印成功,原因:" + ex.Message);
return 0;
}
}
return intQty;//返回實際打印的數量
}
示例5: FormSameSize
/// <summary>
/// Whether pageheight and pagewidth of the form are same with the specific ones
/// </summary>
public static bool FormSameSize(string PrinterName, string FormName, decimal Width, decimal Height)
{
bool bolRet = false;
System.Drawing.Printing.PrintDocument pd = new System.Drawing.Printing.PrintDocument();
pd.PrinterSettings.PrinterName = PrinterName;
foreach (System.Drawing.Printing.PaperSize ps in pd.PrinterSettings.PaperSizes)
{
if (ps.PaperName == FormName)
{
decimal decWidth = FromInchToCM(System.Convert.ToDecimal(ps.Width));
decimal decHeight = FromInchToCM(System.Convert.ToDecimal(ps.Height));
if (System.Math.Round(decWidth, 0) == System.Math.Round(Width, 0) && System.Math.Round(decHeight, 0) == System.Math.Round(Height, 0))
bolRet = true;
break;
}
}
pd.Dispose();
return bolRet;
}
示例6: FormInPrinter
/// <summary>
/// Whether the specific form is in the selected printer
/// </summary>
public static bool FormInPrinter(string PrinterName, string PaperName)
{
bool bolRet = false;
System.Drawing.Printing.PrintDocument pd = new System.Drawing.Printing.PrintDocument();
pd.PrinterSettings.PrinterName = PrinterName;
foreach (System.Drawing.Printing.PaperSize ps in pd.PrinterSettings.PaperSizes)
{
if (ps.PaperName == PaperName)
{
bolRet = true;
break;
}
}
pd.Dispose();
return bolRet;
}
示例7: button17_Click
private void button17_Click(object sender, EventArgs e)
{
PrintDocument PD = new PrintDocument();
PD.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage);
PrintPreviewDialog pdlg = new PrintPreviewDialog();
pdlg.Document = PD;
pdlg.ShowDialog();
try
{
PD.Print();
}
catch
{
Console.WriteLine("Yazici çiktisi alinamiyor...");
}
finally
{
PD.Dispose();
}
}
示例8: PrintPreviewDLG
public PrintPreviewDLG(DataTable tblMatrix, DataTable tblVocab)
{
InitializeComponent();
this.PrintPreviewCtrl.Paint += PrintPreviewCtrl_Paint;
this.ZoomFitPageRadio.CheckedChanged += ZoomRadio_CheckedChanged;
this.ZoomWidthRadio.CheckedChanged += ZoomRadio_CheckedChanged;
this.PrinterTDdl.Items.Clear();
// Do not do the Printer Setup Stuff in Visual Studio Design Mode
if (!System.Reflection.Assembly.GetExecutingAssembly().Location.Contains("VisualStudio"))
{
// Load the Printer Selection List
foreach (string sPrinterName in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
{
this.PrinterTDdl.Items.Add(sPrinterName);
}
this.PrinterTDdl.SelectedIndex = -1;
if (this.PrinterTDdl.SelectedIndex < 0)
{
// Set the Selected Printer to the Default System Printer
System.Drawing.Printing.PrintDocument pd = new System.Drawing.Printing.PrintDocument();
this.PrinterTDdl.SelectedIndex = this.PrinterTDdl.Items.IndexOf(pd.PrinterSettings.PrinterName);
pd.Dispose();
}
}
Layout_ToolBars();
if (System.Reflection.Assembly.GetExecutingAssembly().Location.Contains("VisualStudio"))
{
// Abort if IDE Design Mode
return;
}
m_MatrixTbl = tblMatrix.Copy();
ReportTools.ReportXPropertiesAdd(ref m_MatrixTbl, true, 0.0f, "CM", 0.0f, 0.0f, 0.0f, 0.0f, "");
m_VocabTbl = tblVocab.Copy();
ReportTools.ReportXPropertiesAdd(ref m_VocabTbl, true, 0.0f, "CM", 0.0f, 0.0f, 0.0f, 0.0f, "");
// Default Page Settings
XPageSettings = new PrinterSettings().DefaultPageSettings;
XPageSettings.Margins = new Margins(50, 50, 50, 50);
XPageSettings.Landscape = false;
this.PrintTBtn.Visible = true;
this.Width = Convert.ToInt32(Application.OpenForms[0].Width * 0.80);
this.Height = Convert.ToInt32(Application.OpenForms[0].Height * 0.80);
// Generate the Preview
Preview_Puzzle();
}
示例9: DoPrint
private void DoPrint()
{
PrintDocument printDocument = null;
try
{
Status = PrintJobStatus.Printing;
OnStatusUpdate("Printing Started");
var printerSettings = new PrinterSettings
{
PrinterName = "Microsoft XPS Document Writer",
PrintToFile = true,
PrintFileName =
string.Format(
"{0}\\{1}.xps",
FullPrintJobFolder,
SOPInstanceUID.UID)
};
printDocument = new PrintDocument
{
PrinterSettings = printerSettings,
DocumentName = Thread.CurrentThread.Name,
PrintController = new StandardPrintController()
};
printDocument.QueryPageSettings += OnQueryPageSettings;
printDocument.PrintPage += OnPrintPage;
printDocument.Print();
Status = PrintJobStatus.Done;
OnStatusUpdate("Printing Done");
}
catch
{
Status = PrintJobStatus.Failure;
OnStatusUpdate("Printing failed");
}
finally
{
if (printDocument != null)
{
//dispose the print document and unregister events handlers to avoid memory leaks
printDocument.QueryPageSettings -= OnQueryPageSettings;
printDocument.PrintPage -= OnPrintPage;
printDocument.Dispose();
}
}
}
示例10: Prestamo
public void Prestamo(string prestamoID)
{
string today = DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year;
SqlDataReader q = dbc.query_single("SELECT c.CL_NOMBRE, p.PRESTAMOID ,CONVERT(VARCHAR(15), p.CO_FECHA, 105) AS FECHA ,p.CL_CODIGO,p.CO_CAPITAL, p.CO_INTERES,p.CO_CANPAG, p.CO_TIPPAG FROM prestamos p inner join clientes c on (c.CL_CODIGO=p.CL_CODIGO ) where p.PRESTAMOID=" + prestamoID);
if (q.Read())
{
double cuotafija = GenPrestamoCuotas(q["CO_CAPITAL"].ToString(), q["CO_INTERES"].ToString(), q["CO_CANPAG"].ToString(), q["CO_TIPPAG"].ToString(), q["FECHA"].ToString());
plines[0] = String.Format(company);
plines[1] = String.Format("{0} \t\t\t\t\t Fecha: {1}",address, q["FECHA"].ToString());
plines[2] = String.Format("Tel.: {0}, Cel.: {1}",phone,cell);
plines[3] = String.Format("____________________________________________ ");
plines[4] = String.Format("\t\t\tTABLA DE AMORTIZACION ");
plines[5] = String.Format("Numero De Prestamo..: {0}", q["PRESTAMOID"].ToString());
plines[6] = String.Format("Codigo Cliente......: {0}\t{1}",q["CL_CODIGO"].ToString(),q["CL_NOMBRE"].ToString());
plines[7] = String.Format("Fecha...............: {0}", q["FECHA"].ToString());
plines[8] = String.Format("Capital.............: {0:N}", Double.Parse(q["CO_CAPITAL"].ToString()));
plines[9] = String.Format("Taza De Interes.....: {0} %", q["CO_INTERES"].ToString());
plines[10] = String.Format("Cantidad De Cuotas.: {0:F0}", Double.Parse(q["CO_CANPAG"].ToString()));
plines[11] = String.Format("Forma De Pago......: {0}",getTypo(q["CO_TIPPAG"].ToString()));
plines[12] = String.Format("Gasto Legales %....: ");
plines[13] = String.Format("Cuota Fija.........: {0:N}", cuotafija);
plines[14] = String.Format("FECHA {0,12}{1,15}{2,10}{3,14}{4,10}", "No.Cuota", "Capital", "Interes", "Total Cuota", "Balance");
plines[15] = String.Format("__________ __________ ______________ ___________ ______________ ____________");
/// print data
PrintDocument pd = new PrintDocument();
// set printing document margins
pd.DefaultPageSettings.Margins.Top = 25;
pd.DefaultPageSettings.Margins.Left = 25;
pd.DefaultPageSettings.Margins.Right = 25;
pd.PrintPage += new PrintPageEventHandler(Prestamo_PrintPage);
// Print the document.
pd.Print();
pd.Dispose();
}
q.Close();
// return lines;
}
示例11: PrintMenuClick
/// <summary>
/// The action of [print] menu click.
/// show SelectPluginDialog of PluginManager and select the plugin.
/// </summary>
/// <param name="sender">object(ToolStripMenuItem)</param>
/// <param name="e">EventArgs</param>
private void PrintMenuClick(object sender, EventArgs e)
{
PrintPluginDialog d = new PrintPluginDialog(m_env.PluginManager);
DialogResult result = d.ShowDialog();
if (result == DialogResult.OK)
{
if (d.SelectedItem.Plugin.IsDirect())
{
d.SelectedItem.Plugin.Print(d.SelectedItem.Portion);
d.Dispose();
return;
}
PrintDocument pd = new PrintDocument();
PrintDialog pdlg = new PrintDialog();
pdlg.Document = pd;
pdlg.AllowSomePages = true;
if (pdlg.ShowDialog() == DialogResult.OK)
{
pd.PrintPage += delegate(object o, PrintPageEventArgs pe)
{
Bitmap bmp = new Bitmap(d.SelectedItem.Plugin.Print(d.SelectedItem.Portion), pe.PageBounds.Width, pe.PageBounds.Height);
pe.Graphics.DrawImage(bmp, new Point(0, 0));
bmp.Dispose();
};
pd.Print();
}
pd.Dispose();
}
d.Dispose();
}
示例12: printToolStripMenuItem_Click
private void printToolStripMenuItem_Click(object sender, EventArgs e)
{
System.Drawing.Printing.PrintDocument doc = new System.Drawing.Printing.PrintDocument();
doc.DefaultPageSettings.Landscape = true;
doc.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(doc_PrintPage);
printDialog1.Document = doc;
if (printDialog1.ShowDialog() == DialogResult.OK)
{
doc.Print();
}
doc.Dispose();
}
示例13: DoPrint
private void DoPrint()
{
try
{
Status = PrintJobStatus.Printing;
OnStatusUpdate("Printing Started");
var printerSettings = new PrinterSettings
{
PrinterName = "Microsoft XPS Document Writer",
PrintToFile = true,
PrintFileName = string.Format("{0}\\{1}.xps", FullPrintJobFolder, SOPInstanceUID.UID)
};
_printDocument = new PrintDocument
{
PrinterSettings = printerSettings,
DocumentName = Thread.CurrentThread.Name,
//PrintController = new StandardPrintController()
};
_printDocument.PrinterSettings.Collate = true;
_printDocument.PrinterSettings.Copies = (short)Session.NumberOfCopies;
_printDocument.QueryPageSettings += OnQueryPageSettings;
_printDocument.PrintPage += OnPrintPage;
PreviewProc();
// I would use some kind of if statement below in a production environment and flow a variable
//throught to the sever to triger it "_preview"
//if (_preview)
// PreviewProc(printDocument);
//else
// printDocument.Print();
Status = PrintJobStatus.Done;
OnStatusUpdate("Printing Done");
}
catch
{
Status = PrintJobStatus.Failure;
OnStatusUpdate("Printing failed");
}
finally
{
if (_printDocument != null)
{
//dispose the print document and unregister events handlers to avoid memory leaks
_printDocument.QueryPageSettings -= OnQueryPageSettings;
_printDocument.PrintPage -= OnPrintPage;
_printDocument.Dispose();
}
}
}
示例14: Print
private void Print()
{
PrintDialog printDialog = new PrintDialog();
PrintDocument printImage = new PrintDocument();
printImage.DocumentName = "Cropper Captured Image";
printImage.PrintPage += OnPrintPage;
printDialog.Document = printImage;
DialogResult result = printDialog.ShowDialog();
// Send print message
try
{
if (result == DialogResult.OK)
printImage.Print();
}
catch (InvalidPrinterException)
{
ShowPrintError();
}
finally
{
printImage.Dispose();
printDialog.Dispose();
}
}
示例15: Print
public void Print( bool preview )
{
if( curr == null )
return;
curr.DoOperation( GUI.View.EditOperation.SelectNone );
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
pd.DefaultPageSettings.Landscape = true;
pd.DocumentName = curr.name;
pd.DefaultPageSettings.Margins = new Margins( 25,25,25,25 );
pages_printed = 0;
PrintDialog d = new PrintDialog();
d.Document = pd;
DialogResult res = d.ShowDialog();
if( res != DialogResult.OK )
return;
pd.PrinterSettings = d.PrinterSettings;
if( preview ) {
PrintPreviewDialog ppd = new PrintPreviewDialog();
ppd.Document = pd;
ppd.ShowDialog();
} else {
pd.Print();
}
pd.Dispose();
}