private void InsertWatermarkImages() { // remove all existing watermarks RemoveWatermarkImages(textControl1); foreach (TXTextControl.Page page in textControl1.GetPages()) { // create a new watermark image Bitmap bmp = CreateDraftImage(); // create a new TXTextControl.Image object and mark // as watermark TXTextControl.Image img = new TXTextControl.Image(bmp); img.Name = "Watermark"; img.Sizeable = false; img.Moveable = false; // calculate the location to center the image Point pImageLocation = new Point( (page.Bounds.Width / 2) - (PixelToTwips(bmp.Size.Width)) / 2, (page.Bounds.Height / 2) - (PixelToTwips(bmp.Size.Height)) / 2); // add the image to the page textControl1.Images.Add( img, page.Number, pImageLocation, TXTextControl.ImageInsertionMode.BelowTheText); } }
/*************************************************************** * InsertTIFF method * description: Insert a new section for each page and inserts * the images * * param: image - the image path * startAtNewPage - specifies whether the first * image is inserted on a new page or not ***************************************************************/ private void InsertTIFF(string image, bool startAtNewPage) { // make sure the page unit is twips textControl1.PageUnit = TXTextControl.MeasuringUnit.Twips; bool bFirstPage = false; // retrieve the images List<Image> images = SplitMultipageTIFF(image); foreach (Image img in images) { // create a new TXTextControl.Image from each image TXTextControl.Image TXImg = new TXTextControl.Image(img); if (bFirstPage == false && startAtNewPage == true) { // insert a new section textControl1.Sections.Add( TXTextControl.SectionBreakKind.BeginAtNewPage); bFirstPage = true; } // add the image and adjust the page size and margins according // to the image textControl1.Images.Add(TXImg, textControl1.InputPosition.Page, new Point(0, 0), TXTextControl.ImageInsertionMode.FixedOnPage); textControl1.Sections.GetItem().Format.PageMargins = new TXTextControl.PageMargins(0, 0, 0, 0); textControl1.Sections.GetItem().Format.PageSize = new TXTextControl.PageSize(TXImg.Size.Width, TXImg.Size.Height); } }
public void PrintPreview(DataRow drKetQuaSieuAm) { bool is2Page = Convert.ToBoolean(drKetQuaSieuAm["InTrang2"]); if (is2Page) { _reportTemplate = string.Format("{0}\\Templates\\SieuAmTemplate2.rtf", Application.StartupPath); } else { _reportTemplate = string.Format("{0}\\Templates\\SieuAmTemplate.rtf", Application.StartupPath); } Utility.CopyTemplates(_reportTemplate); Cursor.Current = Cursors.WaitCursor; _textControl.Load(_reportTemplate, TXTextControl.StreamType.RichTextFormat); _textControl.Tables.GridLines = false; string label = "Mã bệnh nhân: "; int index = _textControl.Find(label, 0, TXTextControl.FindOptions.NoMessageBox); if (index > -1) { _textControl.Selection.Start = index; _textControl.Selection.Text = label + _patientRow["FileNum"].ToString(); } label = "Tuổi: "; index = _textControl.Find(label, 0, TXTextControl.FindOptions.NoMessageBox); if (index > -1) { _textControl.Selection.Start = index; _textControl.Selection.Text = label + _patientRow["DobStr"].ToString(); } label = "Họ - Tên: "; index = _textControl.Find(label, 0, TXTextControl.FindOptions.NoMessageBox); if (index > -1) { _textControl.Selection.Start = index; _textControl.Selection.Text = label + _patientRow["FullName"].ToString(); } label = "Giới tính: "; index = _textControl.Find(label, 0, TXTextControl.FindOptions.NoMessageBox); if (index > -1) { _textControl.Selection.Start = index; _textControl.Selection.Text = label + _patientRow["GenderAsStr"].ToString(); } label = "Địa chỉ: "; index = _textControl.Find(label, 0, TXTextControl.FindOptions.NoMessageBox); if (index > -1) { _textControl.Selection.Start = index; _textControl.Selection.Text = label + _patientRow["Address"].ToString(); } label = "Lâm sàng: "; index = _textControl.Find(label, 0, TXTextControl.FindOptions.NoMessageBox); if (index > -1) { _textControl.Selection.Start = index; _textControl.Selection.Text = label + drKetQuaSieuAm["LamSang"].ToString(); } if (drKetQuaSieuAm["BacSiChiDinhGUID"] != null && drKetQuaSieuAm["BacSiChiDinhGUID"] != DBNull.Value) { label = "BS. Chỉ định: "; index = _textControl.Find(label, 0, TXTextControl.FindOptions.NoMessageBox); if (index > -1) { _textControl.Selection.Start = index; _textControl.Selection.Text = label + drKetQuaSieuAm["BacSiChiDinh"].ToString(); } } if (!is2Page) { label = "Result"; index = _textControl.Find(label, 0, TXTextControl.FindOptions.NoMessageBox); if (index > -1) { _textControl.Selection.Start = index; byte[] buff = (byte[])drKetQuaSieuAm["KetQuaSieuAm"]; _textControl.Selection.Load(buff, TXTextControl.BinaryStreamType.MSWord); } } else { _textControl.Selection.Start = 9999; byte[] buff = (byte[])drKetQuaSieuAm["KetQuaSieuAm"]; _textControl.Selection.Load(buff, TXTextControl.BinaryStreamType.MSWord); } label = "Hình 1"; index = _textControl.Find(label, 0, TXTextControl.FindOptions.NoMessageBox); TXTextControl.Image img = null; if (index > -1) { _textControl.Selection.Start = index; _textControl.Selection.Text = string.Empty; Image bmp = null; if (drKetQuaSieuAm["Hinh1"] != null && drKetQuaSieuAm["Hinh1"] != DBNull.Value) { bmp = Utility.ParseImage((byte[])drKetQuaSieuAm["Hinh1"], 300, 200); } else { bmp = Properties.Resources.WhiteImage; } img = new TXTextControl.Image(bmp); _textControl.Images.Add(img, TXTextControl.HorizontalAlignment.Center, index, TXTextControl.ImageInsertionMode.MoveWithText); } label = "Hình 2"; index = _textControl.Find(label, 0, TXTextControl.FindOptions.NoMessageBox); if (index > -1) { _textControl.Selection.Start = index; _textControl.Selection.Text = string.Empty; Image bmp = null; if (drKetQuaSieuAm["Hinh2"] != null && drKetQuaSieuAm["Hinh2"] != DBNull.Value) { bmp = Utility.ParseImage((byte[])drKetQuaSieuAm["Hinh2"], 300, 200); } else { bmp = Properties.Resources.WhiteImage; } img = new TXTextControl.Image(bmp); _textControl.Images.Add(img, TXTextControl.HorizontalAlignment.Center, index, TXTextControl.ImageInsertionMode.MoveWithText); } label = "Ngày"; index = _textControl.Find(label, 0, TXTextControl.FindOptions.NoMessageBox); if (index > -1) { DateTime ngaySieuAm = Convert.ToDateTime(drKetQuaSieuAm["NgaySieuAm"]); _textControl.Selection.Start = index; _textControl.Selection.Text = string.Format("{0} {1} Tháng {2} Năm {3}", label, ngaySieuAm.Day, ngaySieuAm.Month, ngaySieuAm.Year); } label = "Ths.BS"; index = _textControl.Find(label, 0, TXTextControl.FindOptions.NoMessageBox); if (index > -1) { _textControl.Selection.Start = index; _textControl.Selection.Text = drKetQuaSieuAm["BacSiSieuAm"].ToString(); } }