/// <summary> /// Set the paper size of the output document /// </summary> /// <param name="size"> /// The standard paper size /// </param> public void SetPaperSize(PaperKind size) { switch (size) { case PaperKind.Letter: this.Width = "21.59cm"; this.Height = "27.94cm"; break; case PaperKind.Tabloid: this.Width = "27.94cm"; this.Height = "43.18cm"; break; case PaperKind.Legal: this.Width = "21.59cm"; this.Height = "35.56cm"; break; case PaperKind.Statement: this.Width = "13.97cm"; this.Height = "21.59cm"; break; case PaperKind.Executive: this.Width = "18.415cm"; this.Height = "26.67cm"; break; case PaperKind.A3: this.Width = "29.70cm"; this.Height = "42.00cm"; break; case PaperKind.A4: this.Width = "21.00cm"; this.Height = "29.70cm"; break; case PaperKind.A5: this.Width = "14.80cm"; this.Height = "21.00cm"; break; case PaperKind.A6: this.Width = "10.50cm"; this.Height = "14.80cm"; break; case PaperKind.B4: this.Width = "25.00cm"; this.Height = "35.30cm"; break; case PaperKind.B6Envelope: this.Width = "12.50cm"; this.height = "17.60cm"; break; case PaperKind.Standard9x11: this.Width = "22.86cm"; this.Height = "27.94cm"; break; } }
internal PaperSize(PaperKind kind, string name, int width, int height) { this.kind = kind; this.name = name; this.width = width; this.height = height; }
public PrintPaperSize() { Height = 0; Width = 0; Name = ""; Kind = PaperKind.Letter; }
private int FMarginTopPix, FMarginLeftPix, FMarginRightPix, FMarginBottomPix; // 页边距 protected void SetSize(PaperKind value) { if (FSize != value) { FSize = value; } }
void SetPaperKind(PaperKind value) { var info = AvailablePaperKinds.SingleOrDefault(x => (PaperKind)x.Id == value) ?? AvailablePaperKinds.Single(x => (PaperKind)x.Id == PaperKind.Letter); SelectedPaperKind = info; }
private void ItemClickEventHandler_Print(object sender, EventArgs e) { try { ////PrinterSettings prs = new PrinterSettings(); PrintDialog printDialog1 = new PrintDialog(); PrintDocument pd = new PrintDocument(); PaperSource ps = new PaperSource(); ////IEnumerable<PaperSize> paperSizes = prs.PaperSizes.Cast<PaperSize>(); ////PaperSize sizeLetter = paperSizes.First<PaperSize>(size => size.Kind == PaperKind.Letter); // setting paper size to A4 size PaperKind ppk = new PaperKind(); ppk = PaperKind.Letter; //ps.SourceName = "cassette 1"; pd.DefaultPageSettings.PaperSource = ps; pd.DefaultPageSettings.PaperSize.RawKind = (int)ppk; printDialog1.Document = pd; printDialog1.ShowNetwork = true; printDialog1.AllowSomePages = true; printDialog1.AllowSelection = false; printDialog1.AllowCurrentPage = false; printDialog1.PrinterSettings.Copies = 1; ////printDialog1.PrinterSettings.PrinterName = this.PrinterToPrint; DialogResult result = printDialog1.ShowDialog(); if (result == DialogResult.OK) { PrintReport(pd); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
internal PaperSize(string name, int width, int height, PaperKind kind, bool isDefault) { this.width = width; this.height = height; this.name = name; this.is_default = isDefault; }
public static SizeF GetPaperSize(PaperKind Kind, bool Rotated, ScaleModeConstants Mode) { if (Kind.ToString().EndsWith("Rotated")) { throw new Exception(string.Format("Kind:{0} has 'Rotated' value", Kind)); } PaperKind KindNew = Kind; if (Rotated) { switch (Kind) { case PaperKind.Letter: KindNew = PaperKind.LetterRotated; break; case PaperKind.B4: KindNew = PaperKind.B4JisRotated; break; case PaperKind.B5: KindNew = PaperKind.B5JisRotated; break; case PaperKind.A3: KindNew = PaperKind.A3Rotated; break; case PaperKind.A4: KindNew = PaperKind.A4Rotated; break; case PaperKind.A5: KindNew = PaperKind.A5Rotated; break; case PaperKind.A6: KindNew = PaperKind.A6Rotated; break; default: throw new Exception(string.Format("Wrong PaperKind:{0}", Kind)); } } return(GetPaperSize(KindNew, Mode)); }
/// <summary> /// Параметры страницы /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void menuFilePageSetup_Click(object sender, EventArgs e) { try { pageSetupDialog1.PageSettings = printDocument1.DefaultPageSettings; if (pageSetupDialog1.ShowDialog() == DialogResult.OK) { m_PrintInfo.Margins = pageSetupDialog1.PageSettings.Margins; int n = 4; //A4 PrinterSettings.PaperSizeCollection psCol = pageSetupDialog1.PageSettings.PrinterSettings.PaperSizes; PaperKind pk = pageSetupDialog1.PageSettings.PaperSize.Kind; for (int i = 0; i < psCol.Count; i++) { if (psCol[i].Kind == pk) { n = i; break; } } m_PrintInfo.PaperNumber = n; m_PrintInfo.Landscape = pageSetupDialog1.PageSettings.Landscape; m_ActClass.SaveParameter(m_PrintInfo); } MainForm_InputLanguageChanged(null, null); } catch (Exception exc) { MessageBox.Show("Произошла ошибка: \r\n" + exc.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
public static void GetPaperKindAndRotated(PaperKind Kind, out PaperKind KindNotRotatedIs, out bool RotatedIs) { RotatedIs = Kind.ToString().EndsWith("Rotated"); if (!RotatedIs) { KindNotRotatedIs = Kind; } else { switch (Kind) { case PaperKind.LetterRotated: KindNotRotatedIs = PaperKind.Letter; break; case PaperKind.B4JisRotated: KindNotRotatedIs = PaperKind.B4; break; case PaperKind.B5JisRotated: KindNotRotatedIs = PaperKind.B5; break; case PaperKind.A3Rotated: KindNotRotatedIs = PaperKind.A3; break; case PaperKind.A4Rotated: KindNotRotatedIs = PaperKind.A4; break; case PaperKind.A5Rotated: KindNotRotatedIs = PaperKind.A5; break; case PaperKind.A6Rotated: KindNotRotatedIs = PaperKind.A6; break; default: throw new Exception(string.Format("Wrong PaperKind:{0}", Kind)); } } }
private void PreparePrintDocument(Print_content content) { dlgPrint = new PrintDialog(); PrintDocument print_document = new PrintDocument(); print_document.DefaultPageSettings.Margins.Top = 20; //mil=inch/100 print_document.DefaultPageSettings.Margins.Bottom = 20; //mil=inch/100 print_document.DefaultPageSettings.Margins.Left = 20; //mil=inch/100 print_document.DefaultPageSettings.Margins.Right = 20; //mil=inch/100 //print_document.DefaultPageSettings.PaperSize = print_document.PrinterSettings.PaperSizes[14]; PaperKind a = print_document.DefaultPageSettings.PaperSize.Kind; //print_document.DefaultPageSettings.PaperSize.PaperName = "Custom"; //print_document.DefaultPageSettings.PaperSize.Width = 1000; print_document.DefaultPageSettings.Landscape = true; prn_NumOfPage = 0; //// Select Case Content ////ORIGINAL LINE: Case Print_content.Print_Graph_and_Summary if (content == Print_content.Print_Graph_and_Summary) { print_document.PrintPage += Create_PrintPage_Graph_and_Summary; //Case Print_content.Print_general_information // AddHandler print_document.PrintPage, AddressOf Create_PrintPage_information } prn_Document = print_document; }
/// <summary> /// Initializes a new instance of the <see cref='System.Drawing.Printing.PaperSize'/> class. /// </summary> public PaperSize(string name, int width, int height) { _kind = PaperKind.Custom; _name = name; _width = width; _height = height; }
internal PaperSize(PaperKind kind, string name, int width, int height) { _kind = kind; _name = name; _width = width; _height = height; }
/// <include file='doc\PaperSize.uex' path='docs/doc[@for="PaperSize.PaperSize"]/*' /> /// <devdoc> /// <para> /// Initializes a new instance of the <see cref='System.Drawing.Printing.PaperSize'/> class. /// </para> /// </devdoc> public PaperSize(string name, int width, int height) { this.kind = PaperKind.Custom; this.name = name; this.width = width; this.height = height; }
public PaperSize(string name, int width, int height) { this.kind = PaperKind.Custom; this.name = name; this.width = width; this.height = height; }
public PrintPaperSize(string name, double height, double width, PaperKind kind) { Height = height; Width = width; Name = name; Kind = kind; }
/// <summary> /// Loads a printer's paper sizes. Returns the default PaperSize, and fills a list of paper_names for use in dialogues /// </summary> /// <param name="ppd_handle">PPD printer file handle</param> /// <param name="settings">PrinterSettings object to fill</param> /// <param name="def_size">Default paper size, from the global options of the printer</param> /// <param name="paper_names">List of available paper sizes that gets filled</param> private static PaperSize LoadPrinterPaperSizes(IntPtr ppd_handle, PrinterSettings settings, string?def_size, NameValueCollection paper_names) { IntPtr ptr; string real_name; PPD_FILE ppd; PPD_SIZE size; PaperSize ps; PaperSize defsize = new PaperSize(GetPaperKind(827, 1169), "A4", 827, 1169); ppd = (PPD_FILE)Marshal.PtrToStructure(ppd_handle, typeof(PPD_FILE)) !; ptr = ppd.sizes; float w, h; for (int i = 0; i < ppd.num_sizes; i++) { size = (PPD_SIZE)Marshal.PtrToStructure(ptr, typeof(PPD_SIZE)) !; real_name = paper_names[size.name] !; w = size.width * 100 / 72; h = size.length * 100 / 72; PaperKind kind = GetPaperKind((int)w, (int)h); ps = new PaperSize(kind, real_name, (int)w, (int)h); ps.RawKind = (int)kind; if (def_size == ps.Kind.ToString()) { defsize = ps; } settings.paper_sizes !.Add(ps); ptr = (IntPtr)((long)ptr + Marshal.SizeOf(size)); } return(defsize); }
private void RefreshView() { if (myPageSettings != null) { for (int iCount = 0; iCount < cboPage.Items.Count; iCount++) { PaperKind kind = (PaperKind)Enum.Parse(typeof(PaperKind), (string)cboPage.Items[iCount]); if (myPageSettings.PaperKind == kind) { cboPage.SelectedIndex = iCount; break; } } this.txtLeftMargin.Value = Convert.ToDecimal(MeasureConvert.HundredthsInchToMillimeter(myPageSettings.LeftMargin)); this.txtTopMargin.Value = Convert.ToDecimal(MeasureConvert.HundredthsInchToMillimeter(myPageSettings.TopMargin)); this.txtRightMargin.Value = Convert.ToDecimal(MeasureConvert.HundredthsInchToMillimeter(myPageSettings.RightMargin)); this.txtBottomMargin.Value = Convert.ToDecimal(MeasureConvert.HundredthsInchToMillimeter(myPageSettings.BottomMargin)); this.rdoLandscape.Checked = !myPageSettings.Landscape; this.rdoLandscape2.Checked = myPageSettings.Landscape; } if (cboPage.SelectedIndex >= 0) { setPagerSize((PaperKind)Enum.Parse(typeof(PaperKind), cboPage.Text)); } }
public void RawKind_ReturnsExpected(int rawKind, PaperKind expectedKind) { PaperSize ps = new PaperSize(); ps.RawKind = rawKind; Assert.Equal(expectedKind, ps.Kind); Assert.Equal(rawKind, ps.RawKind); }
/// <summary> /// The page size for reports defaults to A4 at the moment /// </summary> /// <param name="APaperKind"></param> /// <param name="AMargins"></param> /// <param name="AWidthInPoint"></param> /// <param name="AHeightInPoint"></param> /// <returns></returns> public override bool GetPageSize(out PaperKind APaperKind, out Margins AMargins, out float AWidthInPoint, out float AHeightInPoint) { APaperKind = PaperKind.A4; AMargins = new Margins(20, 20, 20, 39); AWidthInPoint = 827; AHeightInPoint = 1169; return(false); }
public RPT_XtraReport(DataSet ip_ds, DevExpress.XtraGrid.Views.Grid.GridView ip_grv, ArrayList ip_arr_parameter, PaperKind ip_paper_kind, bool ip_land_scape) { InitializeComponent(); ReportFormat(true, PaperKind.A4); ReportFillParameter(ip_arr_parameter); ReportData(ip_ds); ReportGroupBand(ip_grv); InitTables(ip_grv); }
public void Set(PaperPageSize pp) { Width = pp.Width; Height = pp.Height; Landscape = pp.mLandscape; Kind = pp.mPaperKind; }
//--------------------------------------------------------------------------------- #region ** paper sizes static void CreateDocumentPaperSizes(C1WordDocument word) { // landscape for first page bool landscape = true; word.Landscape = landscape; // add title Font titleFont = new Font("Tahoma", 24, RtfFontStyle.Bold); Rect rc = WordUtils.PageRectangle(word); word.AddParagraph(word.Info.Title, titleFont); var paragraph = (RtfParagraph)word.Current; paragraph.BottomBorderColor = Colors.Purple; paragraph.BottomBorderStyle = RtfBorderStyle.Dotted; paragraph.BottomBorderWidth = 3.0f; // create constant font and StringFormat objects Font font = new Font("Tahoma", 18); StringFormat sf = new StringFormat(); sf.Alignment = HorizontalAlignment.Center; sf.LineAlignment = VerticalAlignment.Center; word.AddParagraph("By default used Landscape A4", font); word.AddParagraph(string.Empty, font); // create one page with each paper size foreach (var fi in typeof(PaperKind).GetFields(BindingFlags.Static | BindingFlags.Public)) { // Silverlight/Phone doesn't have Enum.GetValues PaperKind pk = (PaperKind)fi.GetValue(null); // skip custom size if (pk == PaperKind.Custom) { continue; } // add new page for every page after the first one word.PageBreak(); // set paper kind and orientation var section = new RtfSection(pk); word.Add(section); landscape = !landscape; word.Landscape = landscape; // add some content on the page string text = string.Format("PaperKind: [{0}];\r\nLandscape: [{1}];\r\nFont: [Tahoma 18pt]", pk, word.Landscape); word.AddParagraph(text); paragraph = (RtfParagraph)word.Current; paragraph.SetRectBorder(RtfBorderStyle.DashSmall, Colors.Aqua, 2.0f); word.AddParagraph(string.Empty); } }
private static PaperSize GetPaperSize(PaperKind paperKind) { PrinterSettings printerSettings = new PrinterSettings(); IQueryable <PaperSize> paperSizes = printerSettings.PaperSizes.Cast <PaperSize>().AsQueryable(); PaperSize result = paperSizes.Where(paperSize => paperSize.Kind == paperKind).FirstOrDefault(); return(result); }
public void Print() { //データテーブルにデータがない場合 if (dt.Rows.Count == 0) { MessageBox.Show("印刷するデータがありません。"); return; } pageCount = 0; PrintDocument pd = new PrintDocument(); pd.PrinterSettings.PrinterName = printerName; //ポップアップを表示させない pd.PrintController = new StandardPrintController(); //プリンタが設定されてない場合はXPSファイルとして出力する if (pd.PrinterSettings.PrinterName == "") { pd.PrinterSettings.PrinterName = "Microsoft XPS Document Writer"; pd.PrinterSettings.PrintFileName = "test.xps"; pd.DefaultPageSettings.PrinterSettings.PrintToFile = true; Process.Start(Application.StartupPath); } #region サイズ用紙設定 PaperKind pk = new PaperKind(); switch (paperSize) { case "A4": pk = PaperKind.A4; break; case "B4": pk = PaperKind.B4; break; case "B5": pk = PaperKind.B5; break; case "A5": pk = PaperKind.A5; break; } foreach (PaperSize ps in pd.PrinterSettings.PaperSizes) { if (ps.Kind == pk) { pd.DefaultPageSettings.PaperSize = ps; } } #endregion pd.PrintPage += new PrintPageEventHandler(this.PdPrintPage); pd.Print(); }
private PaperSize GetPaperSize(PrinterSettings ps, PaperKind kind) { foreach (PaperSize p in ps.PaperSizes) { if (p.Kind == kind) { return(p); } } return(null); }
public void Easy_Print(String printName, PaperKind paperKind, Boolean isHorizon, Boolean isShowPrintDlg) { PrinterSettings printerSettings = new PrinterSettings(); PageSettings pageSetting; if (printName != null && printName.Equals("") == false) { printerSettings.PrinterName = printName; pageSetting = new PageSettings(printerSettings); } else { pageSetting = new PageSettings(); } PaperSize paperSize = new PaperSize(); paperSize.PaperName = paperKind.ToString(); paperSize.RawKind = (int)paperKind; pageSetting.PaperSize = paperSize; pageSetting.Landscape = isHorizon; if (isShowPrintDlg) { /* * SetPageSettings(pageSetting); * if (printName != null && printName.Equals("") == false) PrintDialog(PrinterSettings); * else */ _rv.PrintDialog(); } else { try { _reportPrintDoc = new ReportPrintDocument(_rv.LocalReport); _reportPrintDoc.DefaultPageSettings = pageSetting; _reportPrintDoc.Print(); } catch { try { _rv.PrintDialog(); } catch (Exception e) { MessageBox.Show("프린트시 에러발생.." + e.ToString()); } } } }
protected internal void UpdatePageSize(PaperKind PageKind, ref Size Size) { if ((this.updateCount == 0) && (this.printerSettings != null)) { foreach (PaperSize size1 in this.printerSettings.PaperSizes) { if (size1.Kind == PageKind) { Size = new Size(size1.Width, size1.Height); return; } } } }
//--------------------------------------------------------------------------------- #region ** paper sizes static void CreateDocumentPaperSizes(C1PdfDocument pdf) { // add title Font titleFont = new Font("Tahoma", 24, PdfFontStyle.Bold); Rect rc = PdfUtils.PageRectangle(pdf); PdfUtils.RenderParagraph(pdf, pdf.DocumentInfo.Title, titleFont, rc, rc, false); // create constant font and StringFormat objects Font font = new Font("Tahoma", 18); StringFormat sf = new StringFormat(); sf.Alignment = HorizontalAlignment.Center; sf.LineAlignment = VerticalAlignment.Center; // create one page with each paper size bool firstPage = true; foreach (var fi in typeof(PaperKind).GetFields(BindingFlags.Static | BindingFlags.Public)) { // Silverlight/Phone doesn't have Enum.GetValues PaperKind pk = (PaperKind)fi.GetValue(null); // skip custom size if (pk == PaperKind.Custom) { continue; } // add new page for every page after the first one if (!firstPage) { pdf.NewPage(); } firstPage = false; // set paper kind and orientation pdf.PaperKind = pk; pdf.Landscape = !pdf.Landscape; // draw some content on the page rc = PdfUtils.PageRectangle(pdf); rc = PdfUtils.Inflate(rc, -6, -6); string text = string.Format("PaperKind: [{0}];\r\nLandscape: [{1}];\r\nFont: [Tahoma 18pt]", pdf.PaperKind, pdf.Landscape); pdf.DrawString(text, font, Colors.Black, rc, sf); pdf.DrawRectangle(Colors.Black, rc); } }
private PaperSize GetPageSize(PrinterSettings ps, PaperKind pk) { PaperSize p = null; foreach (PaperSize size in ps.PaperSizes) { if (size.Kind == pk) { p = size; break; } } return(p); }
public void RawKind_Set_GetReturnsExpected(int value, PaperKind expectedKind) { var size = new PaperSize { RawKind = value }; Assert.Equal(value, size.RawKind); Assert.Equal(expectedKind, size.Kind); // Set same. size.RawKind = value; Assert.Equal(value, size.RawKind); Assert.Equal(expectedKind, size.Kind); }
public GlobalConfig SetPaperSize(PaperKind kind) { // don't work //return SetPaperSize(Enum.GetName(typeof(PaperKind), kind)); if (PechkinStatic.PaperSizes.ContainsKey(kind)) { PechkinStatic.StrPaperSize ps = PechkinStatic.PaperSizes[kind]; return SetPaperSize(ps.Width, ps.Height); } Tracer.Warn("T:" + Thread.CurrentThread.Name + " Unknown PaperKind specified in SetPaperSize (" + ((int)kind) + ")"); return this; }
public GlobalConfig SetPaperSize(PaperKind kind) { // don't work //return SetPaperSize(Enum.GetName(typeof(PaperKind), kind)); if (PechkinStatic.PaperSizes.ContainsKey(kind)) { PechkinStatic.StrPaperSize ps = PechkinStatic.PaperSizes[kind]; return(SetPaperSize(ps.Width, ps.Height)); } LogManager.GetLogger <GlobalConfig>().Warn("T:" + Thread.CurrentThread.Name + " Unknown PaperKind specified in SetPaperSize (" + ((int)kind) + ")"); return(this); }
public static PageMediaSize GetPageMediaSize(PaperKind paperKind) { PaperSize pageSize = GetPaperSize(paperKind); if (pageSize == null) { throw new ApplicationException($"Paper kind {paperKind} not supported."); } double pageWidth = ConvertPaperSizeToPx(pageSize.Width); double pageHeight = ConvertPaperSizeToPx(pageSize.Height); PageMediaSize result = new PageMediaSize(ConvertPaperKindToPageMediaSize(paperKind), pageWidth, pageHeight); return(result); }
internal PaperSize(PaperKind kind) { this.kind = kind; this.name = kind.ToString(); // TODO: need to add all of the rest of the paper sizes. switch(kind) { case PaperKind.Letter: { this.width = 850; this.height = 1100; } break; case PaperKind.A4: { this.width = 857; this.height = 1212; } break; case PaperKind.Executive: { this.width = 725; this.height = 1050; } break; case PaperKind.Legal: { this.width = 850; this.height = 1400; } break; default: { // Unknown paper size, so switch to "Letter". this.kind = PaperKind.Letter; this.width = 850; this.height = 1100; } break; } }
public ReportCenter(IPrintable Printable, PaperKind paperKind) { printSystem = new PrintingSystem(); mReportName = ""; mCondition = ""; PrintableComponentLink pcl = new PrintableComponentLink(); pcl.CreateMarginalHeaderArea += new DevExpress.XtraPrinting.CreateAreaEventHandler(link_CreateMarginalHeaderArea); pcl.CreateMarginalFooterArea += new DevExpress.XtraPrinting.CreateAreaEventHandler(link_CreateMarginalFooterArea); pcl.Component = Printable; printSystem.Links.Add(pcl); pcl.CreateDocument(); PrinterSettingsUsing pst = new PrinterSettingsUsing(); pst.UseMargins = false; pst.UsePaperKind = false; printSystem.PageSettings.PaperKind = paperKind; printSystem.PageSettings.PaperName = "A4"; printSystem.PageSettings.LeftMargin = 2; printSystem.PageSettings.RightMargin = 2; printSystem.PageSettings.AssignDefaultPrinterSettings(pst); }
/// <summary> /// get the size of the page, eg. from the HTML body tag /// </summary> public abstract bool GetPageSize(out PaperKind APaperKind, out Margins AMargins, out float AWidthInPoint, out float AHeightInPoint);
/// <summary> /// The page size for reports defaults to A4 at the moment /// </summary> /// <param name="APaperKind"></param> /// <param name="AMargins"></param> /// <param name="AWidthInPoint"></param> /// <param name="AHeightInPoint"></param> /// <returns></returns> public override bool GetPageSize(out PaperKind APaperKind, out Margins AMargins, out float AWidthInPoint, out float AHeightInPoint) { APaperKind = PaperKind.A4; AMargins = new Margins(20, 20, 20, 39); AWidthInPoint = 827; AHeightInPoint = 1169; return false; }
/// <include file='doc\PaperSize.uex' path='docs/doc[@for="PaperSize.PaperSize2"]/*' /> /// <devdoc> /// <para> /// Initializes a new instance of the <see cref='System.Drawing.Printing.PaperSize'/> class with default properties. /// This constructor is required for the serialization of the <see cref='System.Drawing.Printing.PaperSize'/> class. /// </para> /// </devdoc> public PaperSize() { this.kind = PaperKind.Custom; this.name = String.Empty; this.createdByDefaultConstructor = true; }
private void ReportFormat(bool ip_land_scape, PaperKind ip_paper_kind) { this.Landscape = ip_land_scape; this.PaperKind = ip_paper_kind; }
/// <summary> /// get the page size defined in the css styles of body /// </summary> /// <param name="APaperKind"></param> /// <param name="AMargins"></param> /// <param name="AWidthInPoint"></param> /// <param name="AHeightInPoint"></param> /// <returns></returns> public override bool GetPageSize(out PaperKind APaperKind, out Margins AMargins, out float AWidthInPoint, out float AHeightInPoint) { bool Result = false; XmlNode BodyNode = TXMLParser.FindNodeRecursive(FHtmlDoc.DocumentElement, "body"); APaperKind = PaperKind.A4; AMargins = new Margins(20, 20, 20, 39); AWidthInPoint = -1; AHeightInPoint = -1; if (TXMLParser.HasAttribute(BodyNode, "style")) { Dictionary <string, string>Styles = TFormLettersTools.GetStyles(BodyNode); foreach (string StyleName in Styles.Keys) { if (StyleName == "margin") { Result = true; // TODO support more than just 0px if (Styles[StyleName] == "0px") { AMargins = new Margins(0, 0, 0, 0); } } else if (StyleName == "size") { // http://www.w3.org/TR/css3-page/#page-size // currently support: either a name of PaperKind enum, or width and height in inches or cm // eg size: 8.5in 11in; // eg size: A4; Result = true; PaperKind FoundPaperKind = PaperKind.Custom; foreach (PaperKind MyPaperKind in Enum.GetValues(typeof(PaperKind))) { if (MyPaperKind.ToString() == Styles[StyleName]) { FoundPaperKind = MyPaperKind; break; } } if (FoundPaperKind != PaperKind.Custom) { APaperKind = FoundPaperKind; } else { string[] dimensions = Styles[StyleName].Trim().Split(' '); if (dimensions.Length != 2) { TLogging.Log("body styles must contain 2 numbers for page size: " + Styles[StyleName]); TLogging.Log(Styles[StyleName]); return false; } dimensions[0] = dimensions[0].Trim().ToLower(); dimensions[1] = dimensions[1].Trim().ToLower(); CultureInfo OrigCulture = Catalog.SetCulture(CultureInfo.InvariantCulture); AWidthInPoint = ToPoint(dimensions[0], eResolution.eHorizontal); AHeightInPoint = ToPoint(dimensions[1], eResolution.eVertical); Catalog.SetCulture(OrigCulture); } } } } return Result; }
// Get a standard paper size object. public static PaperSize GetStandardPaperSize(PaperKind kind) { return new PaperSize(kind); }
/// <summary> /// Initializes a new instance of the <see cref="XtraPrintService"/> class. /// </summary> /// <param name="printable">The printable.</param> /// <param name="reportTitle">The report title.</param> /// <param name="paperKind">Kind of the paper.</param> public XtraPrintService(IPrintable printable, string reportTitle, PaperKind paperKind) : this(printable, reportTitle) { printSystem.PageSettings.PaperKind = paperKind; }
/// <summary> /// store a pdf to a file. will call PrintPage automatically /// </summary> public void SavePDF(string AFilename, PaperKind APaperKind, Margins AMargins, float AWidthInPoint, float AHeightInPoint) { if (Directory.Exists("/usr/share/fonts/")) { PdfSharp.Internal.NativeMethods.FontDirectory = "/usr/share/fonts/"; } if (RegionInfo.CurrentRegion == null) { // https://bugzilla.novell.com/show_bug.cgi?id=588708 // RegionInfo.CurrentRegion is null throw new Exception("Mono bug: CurrentRegion is still null, invariant culture. Please set LANG environment variable"); } FPdfDocument = new PdfDocument(); do { PdfPage page = FPdfDocument.AddPage(); if (APaperKind != PaperKind.Custom) { // see if we can match PaperKind to PageSize by name foreach (PageSize MyPageSize in Enum.GetValues(typeof(PageSize))) { if (MyPageSize.ToString() == APaperKind.ToString()) { page.Size = MyPageSize; break; } } } if ((AWidthInPoint != -1) && (AHeightInPoint != -1)) { // to get the points, eg. inch * 72 page.Width = AWidthInPoint; page.Height = AHeightInPoint; } FXGraphics = XGraphics.FromPdfPage(page, XGraphicsUnit.Inch); FXGraphics.MFEH = PdfFontEmbedding.Always; // it seems for Linux we better reset the FEv, otherwise the positions are only correct on the first page, but wrong on the following pages // was: if (FEv == null) if (true) { PrinterSettings myPrinterSettings = new PrinterSettings(); PageSettings myPageSettings = new PageSettings(myPrinterSettings); myPageSettings.Color = true; myPageSettings.Landscape = false; myPageSettings.Margins = AMargins; myPageSettings.PaperSize = new PaperSize(page.Size.ToString(), Convert.ToInt32(page.Width.Point / 72.0f * 100.0f), Convert.ToInt32(page.Height.Point / 72.0f * 100.0f)); try { myPageSettings.PrinterResolution.X = DEFAULTPRINTERRESOLUTION; myPageSettings.PrinterResolution.Y = DEFAULTPRINTERRESOLUTION; } catch (Exception) { // if no printer is installed we get an exception, but it should work anyway } FEv = new PrintPageEventArgs(FXGraphics.Graphics, new Rectangle(20, 20, 787, 1110), new Rectangle(0, 0, 827, 1169), myPageSettings); FEv.HasMorePages = true; FEv.Graphics.PageUnit = GraphicsUnit.Inch; FEv.Graphics.TranslateTransform(0, 0); InitFontsAndPens(); } PrintPage(null, FEv); } while (HasMorePages()); // should we catch an exception if document cannot be written? FPdfDocument.Save(AFilename); FPdfDocument.Close(); }
internal void SetKind (PaperKind k) {kind = k;}