/// <summary> /// Generates a new Area inside the base one specifing the width difference. /// </summary> /// <param name="Difference">the Width difference of the inner Area</param> /// <returns></returns> public PdfArea InnerArea(double Difference) { this.PdfDocument = PdfDocument; if (Difference < 0) { throw new Exception("Difference must be non negative."); } PdfArea pa = this.MemberwiseClone() as PdfArea; pa.width -= (double)Difference; pa.Height -= (double)Difference; pa.posx += (double)Difference / 2; pa.posy += (double)Difference / 2; return(pa); }
/// <summary> /// Generates a new Area outside the base one specifing the width difference. /// </summary> /// <param name="WidthDifference">the Width difference of the inner Area</param> /// <param name="HeightDifference">the Height difference of the inner Area</param> /// <returns></returns> public PdfArea OuterArea(double WidthDifference, double HeightDifference) { if (WidthDifference < 0) { throw new Exception("WidthDifference must be non negative."); } if (HeightDifference < 0) { throw new Exception("HeightDifference must be non negative."); } PdfArea pa = this.MemberwiseClone() as PdfArea; pa.width += (double)WidthDifference; pa.Height += (double)HeightDifference; pa.posx -= (double)WidthDifference / 2; pa.posy -= (double)HeightDifference / 2; return(pa); }
public System.IO.FileStream GeneraBustaPdf(DataTable dtProfile, string userId) { System.IO.FileStream fsout = null; try { PdfDocument myPdfDocument = new PdfDocument(PdfDocumentFormat.InCentimeters(22.9, 16.2)); foreach (DataRow row in dtProfile.Rows) { //Creo la una tabella di 3 righe, 1 colonnA e 5 ppunti di Padding. PdfTable myPdfTable = myPdfDocument.NewTable(new Font("Times New Roman", 10), 3, 1, 5); myPdfTable.ImportDataTable(Table(row)); myPdfTable.SetColors(Color.Black, Color.White); myPdfTable.SetBorders(Color.Black, 1, BorderType.None); myPdfTable.SetColumnsWidth(new int[] { 100 }); myPdfTable.VisibleHeaders = false; myPdfTable.SetContentAlignment(ContentAlignment.MiddleRight); while (!myPdfTable.AllTablePagesCreated) { PdfPage newPdfPage = myPdfDocument.NewPage(); PdfArea newPdfArea = new PdfArea(myPdfDocument, 240.0, 230.0, 350.0, 200.0); PdfTablePage newPdfTablePage = myPdfTable.CreateTablePage(newPdfArea); PdfTextArea pta = new PdfTextArea(new Font("Times New Roman", 10, FontStyle.Regular), Color.Black, new PdfArea(myPdfDocument, 55, 145, 250, 80), ContentAlignment.TopCenter, row["VAR_DESC_REGISTRO"].ToString().Trim()); // PdfTextArea pta=new PdfTextArea(new Font("Times New Roman",10,FontStyle.Regular),Color.Black,new PdfArea(myPdfDocument,55,145,250,80),ContentAlignment.TopCenter,"dasd sd asf af fdf f sadf asd fas fds fas dfsad fdsa fads fds f dsf dsaf dsa fsad fsa f sadf sad fsda fd fdsa fewsafrew fre gfre gf re erw gewr er rebre br be beb reb ber be b erb re bre ber be rb erbv vf ff f ff f ff fffvgvg"); newPdfPage.Add(newPdfTablePage); newPdfPage.Add(pta); newPdfPage.SaveToDocument(); } } string path = System.Configuration.ConfigurationManager.AppSettings["REPORTS_PATH"]; //path = path.Replace("%DATA", "StampaB_" + userId + DateTime.Now.ToString("yyyyMMdd")); path = path.Replace("%DATA", "StampaBuste"); try { if (!System.IO.Directory.Exists(path)) { System.IO.Directory.CreateDirectory(path); } } catch (Exception ex) { throw ex; } string nomeFile = userId + DateTime.Now.ToString("yyyyMMdd") + ".pdf"; path = path + @"\" + nomeFile; System.IO.FileInfo nfile = new FileInfo(path); try { if (nfile.Exists) { nfile.Delete(); } } catch (Exception ex) { throw ex; } myPdfDocument.SaveToFileStream(path); fsout = new FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read); } catch (Exception ex) { if (fsout != null) { fsout.Close(); } throw ex; } return(fsout); }