public void Set_Kind(PrinterResolutionKind kind) { PrinterResolution pr = new PrinterResolution(); pr.Kind = kind; Assert.Equal(kind, pr.Kind); }
public void PrintPdf(string printJobName, string printQueueName, int paperTray, string paperSizeToPrint) { Margins margin = new Margins(); margin.Top = 0; margin.Left = 0; margin.Right = 0; margin.Bottom = 0; PrinterResolution printerResolution = new PrinterResolution(); printerResolution.X = 720; printerResolution.Y = 720; PrintDocument document = new PrintDocument(); PaperSize paperSize = document.PrinterSettings.PaperSizes.Cast <PaperSize>().FirstOrDefault(e => e.PaperName.StartsWith(paperSizeToPrint)); document.DocumentName = printJobName; document.PrinterSettings.PrintFileName = printJobName; document.PrinterSettings.PrinterName = printQueueName; document.DefaultPageSettings.PaperSource = document.PrinterSettings.PaperSources[paperTray]; document.DefaultPageSettings.PaperSize = paperSize; document.OriginAtMargins = false; document.PrinterSettings.Copies = 1; document.DefaultPageSettings.Color = isColor; document.DefaultPageSettings.PrinterResolution = printerResolution; document.DefaultPageSettings.Landscape = isLandscape; document.PrintPage += new PrintPageEventHandler(document_PrintPageToA4ForA4); document.Print(); }
public void Y_Value_ReturnsExpected(int value) { PrinterResolution pr = new PrinterResolution(); pr.Y = value; Assert.Equal(value, pr.Y); }
public void Kind_ReturnsExpected(PrinterResolutionKind kind) { PrinterResolution pr = new PrinterResolution(); pr.Kind = kind; Assert.Equal(kind, pr.Kind); }
private void btnPrint_Click(object sender, EventArgs e) { PageSettings myPageSettings = new PageSettings(); ValidateTahun(); reportViewer1.Reset(); PrintGaji(tahun, bulan); myPageSettings.Margins.Top = 10; myPageSettings.Margins.Bottom = 0; myPageSettings.Margins.Left = 0; myPageSettings.Margins.Right = 0; //PaperSize size = new PaperSize(); //size.RawKind = (int)PaperKind.Statement; PaperSize size = new PaperSize("Custom", 827, 550); myPageSettings.PaperSize = size; PrinterResolution a = new PrinterResolution(); a.Kind = PrinterResolutionKind.Draft; myPageSettings.PrinterResolution = a; this.reportViewer1.SetPageSettings(myPageSettings); this.reportViewer1.RefreshReport(); btnRefresh.Enabled = true; }
void pd_PrintPage(object sender, PrintPageEventArgs e) { PrinterResolution printerResolution = null; if (_wRes != 0 && _hRes != 0) { foreach (PrinterResolution pr in e.PageSettings.PrinterSettings.PrinterResolutions) { if (pr.X == _wRes && pr.Y == _hRes) { printerResolution = pr; break; } } if (printerResolution != null) { e.PageSettings.PrinterResolution = printerResolution; } } //e.Graphics.CompositingMode = CompositingMode.SourceCopy; e.Graphics.CompositingQuality = CompositingQuality.HighQuality; //e.Graphics.SmoothingMode = SmoothingMode.HighQuality; e.Graphics.TextRenderingHint = TextRenderingHint.SystemDefault; //e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; //e.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; e.Graphics.PageUnit = GraphicsUnit.Pixel; e.Graphics.DrawImage(bmIm, 0, 0, bmIm.Width, bmIm.Height); }
public void Ctor_Default() { var resolution = new PrinterResolution(); Assert.Equal(PrinterResolutionKind.Custom, resolution.Kind); Assert.Equal(0, resolution.X); Assert.Equal(0, resolution.Y); }
private void UstawDPI(PrinterResolution rozdzielczoscDrukarki) { if (rozdzielczoscDrukarki != null) { XDPI = rozdzielczoscDrukarki.X; YDPI = rozdzielczoscDrukarki.Y; } }
public void Ctor_Default() { PrinterResolution pr = new PrinterResolution(); Assert.Equal(PrinterResolutionKind.Custom, pr.Kind); Assert.Equal(0, pr.X); Assert.Equal(0, pr.Y); }
/// <summary> /// Lines the per page. /// </summary> /// <param name="printDoc">The print doc.</param> /// <param name="arguments"> /// The <see cref="System.Drawing.Printing.PrintPageEventArgs"/> /// instance containing the event data. /// </param> /// <param name="graphics">The on graphics.</param> /// <param name="usingFont">The using font.</param> /// <returns> /// The number of lines per page. /// </returns> /// <externalUnit/> /// <revision revisor="dev01" date="4/19/2009" version="1.0.11.7"> /// Member Created /// </revision> private int LinesPerPage( PrintDocument printDoc, PrintPageEventArgs arguments, Graphics graphics, Font usingFont) { int result = 0; if (usingFont != null) { // Font height in pixels int fontHeight = usingFont.Height; if (printDoc != null) { PrinterResolution printerResolution = null; foreach (PrinterResolution res in printDoc.PrinterSettings.PrinterResolutions) { if ((res.X > 65) && (res.Y > 65)) { printerResolution = res; break; } } if (printerResolution != null) { result = (int)( MaxSizeInInches * (double)printerResolution.Y / usingFont.GetHeight( printerResolution.Y) ); } } if ((result == 0) && (arguments != null)) { if (graphics == null) { result = (int) ((double)arguments.PageBounds.Height / (double)fontHeight); } else { result = (int)((double)arguments.PageBounds.Height / usingFont.GetHeight(graphics)); } } } return(result); }
public void Set_Coordinates(int x, int y) { PrinterResolution pr = new PrinterResolution(); pr.X = x; pr.Y = y; Assert.Equal(x, pr.X); Assert.Equal(y, pr.Y); }
public void Y_Value_ReturnsExpected(int value) { var resolution = new PrinterResolution { Y = value }; Assert.Equal(value, resolution.Y); // Set same. resolution.Y = value; Assert.Equal(value, resolution.Y); }
public void Kind_Set_GetReturnsExpected(PrinterResolutionKind value) { var resolution = new PrinterResolution { Kind = value }; Assert.Equal(value, resolution.Kind); // Set same. resolution.Kind = value; Assert.Equal(value, resolution.Kind); }
private void _miPrintCurrentPage_Click(object sender, EventArgs e) { try { if (IsCurrentPrinterLocked()) { UnLockPrinter(); } if (IsCurrentPrinterLocked() == false) { this.Enabled = false; _printDocument.PrinterSettings.PrinterName = _currentPrinterName; _printer.Specifications.DimensionsInInches = false; _printDocument.DefaultPageSettings.Landscape = !_printer.Specifications.PortraitOrient; if (_printer.Specifications.PaperID == 0) { PaperSize paperSize = new PaperSize(); paperSize.PaperName = _printer.Specifications.PaperSizeName; paperSize.Height = Convert.ToInt32(_printer.Specifications.PaperHeight) * 100; paperSize.Width = Convert.ToInt32(_printer.Specifications.PaperWidth) * 100; _printDocument.DefaultPageSettings.PaperSize = paperSize; } else { if (_printer.Specifications.PaperID < _printDocument.DefaultPageSettings.PrinterSettings.PaperSizes.Count) { _printDocument.DefaultPageSettings.PaperSize.RawKind = _printer.Specifications.PaperID; } } PrinterResolution paperResolution = new PrinterResolution(); paperResolution.X = _printer.Specifications.YResolution; paperResolution.Y = _printer.Specifications.YResolution; _printDocument.DefaultPageSettings.PrinterResolution = paperResolution; _printDocument.Print(); } } catch (Exception Ex) { MessageBox.Show(Ex.Message, "LEADTOOLS Printer Demo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } finally { this.Enabled = true; } }
public void PrintMabelCard(MabelCard card) { if ((card.GetCardBackImage() == null) || (card.GetCardFrontImage() == null)) { //throw new Exception("IMAGE_NULL"); // } PrintDocument printDoc = new PrintDocument(); this.pages_printed = 0; printDoc.PrinterSettings.PrinterName = Properties.Settings.Default.LocalPrinter; printDoc.PrinterSettings.Duplex = Duplex.Default; printDoc.DefaultPageSettings.PaperSize = new PaperSize("CR80", 213, 337); printDoc.DefaultPageSettings.Landscape = true; printDoc.DocumentName = "Card-" + card.card_id; PrinterResolution pkResolution; PrinterResolution targetRes = null; for (int i = 0; i < printDoc.PrinterSettings.PrinterResolutions.Count; i++) { pkResolution = printDoc.PrinterSettings.PrinterResolutions[i]; //System.Console.Out.WriteLine("Resolution : " + pkResolution.Kind + " X : " + pkResolution.X + " Y: " + pkResolution.Y); if (pkResolution.Kind.Equals("Custom")) { targetRes = pkResolution; } } if (targetRes != null) { printDoc.DefaultPageSettings.PrinterResolution = targetRes; } else { targetRes = printDoc.DefaultPageSettings.PrinterResolution; } printDoc.PrintPage += new PrintPageEventHandler(printDoc_PrintPage); if (printDoc.PrinterSettings.IsValid) { try { printDoc.Print(); } catch (Exception ex) { lastError = "Printing Error: " + ex.Message; // something went wrong. } } }
private void btnPrint_Click(object sender, EventArgs e) { PageSettings myPageSettings = new PageSettings(); DateTime periodeAwal, periodeAkhir; periodeAwal = dtpPeriodeAwal.Value; periodeAkhir = dtpPeriodeAkhir.Value; reportViewer1.Reset(); if (chkWithJamMakan.Checked) { PrintAbsensi2(periodeAwal, periodeAkhir); } else { PrintAbsensi(periodeAwal, periodeAkhir); } PaperSize size = new PaperSize(); size.RawKind = (int)PaperKind.A4; PrinterResolution a = new PrinterResolution(); a.Kind = PrinterResolutionKind.Draft; //myPageSettings.PaperSize = size; myPageSettings.Margins.Top = 10; myPageSettings.Margins.Bottom = 10; myPageSettings.Margins.Left = 0; myPageSettings.Margins.Right = 0; //myPageSettings.PrinterResolution = a; this.reportViewer1.SetPageSettings(myPageSettings); this.reportViewer1.RefreshReport(); btnRefresh.Enabled = true; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets the default page settings from the default printer on the macine. If no printer /// is installed, set them to null. /// </summary> /// ------------------------------------------------------------------------------------ private static void TryCreateDefaultPageSettings() { if (!s_fTriedToGetDefautSettings) { try { PrinterSettings defaultPrintSettings = new PrinterSettings(); Debug.Assert(defaultPrintSettings.IsDefaultPrinter); // ENHANCE (TE-5917): Detect when the default printer changes and update // accordinly. PageSettings pageSettings = defaultPrintSettings.DefaultPageSettings; s_defaultpaperSize = pageSettings.PaperSize; s_defaultPrinterResolution = pageSettings.PrinterResolution; } catch { // Printer is not installed or maybe there is a problem with the driver. s_defaultpaperSize = null; s_defaultPrinterResolution = null; } s_fTriedToGetDefautSettings = true; } }
// Constructors public PrinterResolutionCollection(PrinterResolution[] array) {}
public void Kind_InvalidEnum_ThrowsInvalidEnumArgumentException(PrinterResolutionKind overflowKind) { PrinterResolution pr = new PrinterResolution(); Assert.Throws <InvalidEnumArgumentException>(() => pr.Kind = overflowKind); }
public int Add(PrinterResolution printerResolution) {}
public void CopyTo(PrinterResolution[] printerResolutions, int index) {}
public void Default_Ctor() { PrinterResolution pr = new PrinterResolution(); Assert.Equal(PrinterResolutionKind.Custom, pr.Kind); }
public void Kind_SetInvalid_ThrowsInvalidEnumArgumentException(PrinterResolutionKind value) { var resolution = new PrinterResolution(); Assert.Throws <InvalidEnumArgumentException>("value", () => resolution.Kind = value); }
public void Set_NotDefinedKind_ThrowsAnException() { PrinterResolution pr = new PrinterResolution(); Assert.Throws <InvalidEnumArgumentException>(() => pr.Kind = (PrinterResolutionKind)999); }
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { PrinterResolution pr = e.PageSettings.PrinterResolution; DrawForm(e.Graphics, pr.X, pr.Y); }
public void ToString_Invoke_ReturnsExpected(PrinterResolution resolution, string expected) { Assert.Equal(expected, resolution.ToString()); }
// NOTE: this code is taken from C1Report printing. /// <summary> /// Creates a PrintDocument based on passed printer settings and current page settings. /// </summary> /// <param name="printerSettings">The printer settings to use. Must not be null.</param> /// <returns>An instance of PrintDocument that has the specified printer and page settings.</returns> /// <remarks> /// The code in this method tries to work around an issue with the standard page setup dialog: /// if the target printer supports papers that are absent from the System.Drawing.Printing.PaperKind /// enum, and such a paper is selected - in certain use scenarios the integrity of the printer and /// page settings is broken by the dialog, and on subsequent calls the dialog shows only the /// default paper. The key to avoiding this seems to be to use a PrintDocument, and to /// set the printer settings with Sethdevnames/Sethdevmode calls, and then to individually /// set the relevant page settings. TFS~~17823. /// </remarks> private PrintDocument _makePageSettingsPrintDocument(PageSettings pageSettings, PrinterSettings printerSettings) { var pdoc = new PrintDocument(); // Set printer settings: pdoc.PrinterSettings.SetHdevnames(printerSettings.GetHdevnames()); pdoc.PrinterSettings.SetHdevmode(printerSettings.GetHdevmode()); // Set relevant page settings (code is copied from C1PageSettings.ToPageSettings): var page = pageSettings; // cache page settings as they are created on the fly // color: pdoc.DefaultPageSettings.Color = page.Color; // orientation: pdoc.DefaultPageSettings.Landscape = page.Landscape; // margins: pdoc.DefaultPageSettings.Margins.Left = page.Margins.Left; pdoc.DefaultPageSettings.Margins.Right = page.Margins.Right; pdoc.DefaultPageSettings.Margins.Top = page.Margins.Top; pdoc.DefaultPageSettings.Margins.Bottom = page.Margins.Bottom; // paper source: PaperSource ps = null; if (page.PaperSource.Kind == PaperSourceKind.Custom) { foreach (PaperSource paperSource in pdoc.PrinterSettings.PaperSources) { if (paperSource.Kind == PaperSourceKind.Custom && paperSource.RawKind == page.PaperSource.RawKind) { ps = paperSource; break; } } } else { foreach (PaperSource paperSource in pdoc.PrinterSettings.PaperSources) { if (paperSource.Kind == page.PaperSource.Kind) { ps = paperSource; break; } } } if (ps == null) { ps = new PaperSource(); ps.SourceName = page.PaperSource.SourceName; ps.RawKind = page.PaperSource.RawKind; } pdoc.DefaultPageSettings.PaperSource = ps; // printer resolution: if (page.PrinterResolution != null && page.PrinterResolution.Kind == System.Drawing.Printing.PrinterResolutionKind.Custom) { PrinterResolution pr = new PrinterResolution(); pr.Kind = page.PrinterResolution.Kind; pr.X = page.PrinterResolution.X; pr.Y = page.PrinterResolution.Y; pdoc.DefaultPageSettings.PrinterResolution = pr; } else { foreach (PrinterResolution printerResolution in pdoc.PrinterSettings.PrinterResolutions) { if (printerResolution.Kind == page.PrinterResolution.Kind) { pdoc.DefaultPageSettings.PrinterResolution = printerResolution; break; } } } // paper size: assigning .NET PaperSize to a size where Kind is one missing from the PaperKind enum // (e.g. A0) causes the PageSetupDialog to break the associated devmode's integrity for subsequent calls, // so we don't mess with such papers at all: if (page.PaperSize.Kind != PaperKind.Custom) { foreach (PaperSize psize in pdoc.PrinterSettings.PaperSizes) { if (psize.Kind == page.PaperSize.Kind && pdoc.DefaultPageSettings.PaperSize.Kind != page.PaperSize.Kind) { pdoc.DefaultPageSettings.PaperSize = page.PaperSize; break; } } } return(pdoc); }
public int Add(PrinterResolution printerResolution) { }
public void GetPrintResolution() { PrinterResolution syz = printDocument.DefaultPageSettings.PrinterResolution; }
void Print(IEnumerable <Image> pages) { var pr = new PrinterResolution { Kind = PrinterResolutionKind.Custom, X = 300, Y = 300 }; var ps = new PaperSize { PaperName = "SC", Width = 221, Height = 345, RawKind = 120 }; var pd = new PrintDocument { PrinterSettings = { PrinterName = CurrentPrinter, Duplex = Duplex.Vertical }, DefaultPageSettings = { PaperSize = ps, PrinterResolution = pr, Landscape = true, Margins = new Margins(0, 0, 0, 0) } }; var jobId = String.Empty; if (!ReferenceEquals(_currentJob, null)) { jobId = _currentJob.Id.ToSafeTrimmedString(); } if (!String.IsNullOrEmpty(jobId)) { pd.DocumentName = jobId; } var pageNumber = 1; var enumerator = pages.GetEnumerator(); enumerator.MoveNext(); pd.PrintPage += (s, a) => { var i = enumerator.Current; var rect = new Rectangle(10, 0, 1014, 639); if (pageNumber % 2 == 0) { rect = new Rectangle(10, 10, 1014, 639); } a.Graphics.SmoothingMode = SmoothingMode.HighQuality; a.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; a.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; a.Graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; a.Graphics.PageUnit = GraphicsUnit.Pixel; a.Graphics.CompositingQuality = CompositingQuality.HighQuality; a.Graphics.Clear(Color.Transparent); a.Graphics.DrawImage(i, rect); pageNumber++; var moveNext = enumerator.MoveNext(); a.HasMorePages = moveNext; if (!moveNext) { enumerator.Dispose(); } }; pd.BeginPrint += pd_BeginPrint; pd.Print(); }