public ScaleToFit ( float fitWidth, float fitHeight ) : void | ||
fitWidth | float | the width to fit |
fitHeight | float | the height to fit |
return | void |
// output the PDF file public void print() { string tempDir = ""; int fileCount = 0; // save the image file, get the directory tempDir = temporaryImageOutput(filePath, ref fileCount); // link the file to PDF if (tempDir == "Error") { MessageBox.Show("Duplicated file name"); return; } Document _pdfDocument = new Document(PageSize.A4, 10, 10, 25, 25); PdfWriter.GetInstance(_pdfDocument, new FileStream(filePath, FileMode.Create)); _pdfDocument.Open(); // output the PDF _pdfDocument.Add(new Paragraph(description[0])); iTextSharp.text.Image imm = iTextSharp.text.Image.GetInstance(tempDir + "\\" + 1 + ".png"); imm.ScaleToFit(PageSize.A5); _pdfDocument.Add(imm); for (int i = 2; i <= fileCount; i++) { _pdfDocument.NewPage(); _pdfDocument.Add(new Paragraph(description[i - 1])); iTextSharp.text.Image ima = iTextSharp.text.Image.GetInstance(tempDir + "\\" + i + ".png"); ima.ScaleToFit(PageSize.A5); _pdfDocument.Add(ima); } _pdfDocument.Close(); }
public override void AddImage(IImage image) { if (image != null) { itImage img = PDFRenderer.ConvertImage(image); float fitWidth = fColumnWidth * 0.5f; img.ScaleToFit(fitWidth, fitWidth); // FIXME: the moving, if the page height is insufficient for the image height //img.Alignment = Image.TEXTWRAP; img.IndentationLeft = 5f; img.SpacingBefore = 5f; img.SpacingAfter = 5f; //Paragraph imgpar = new Paragraph(new Chunk(img, 0, 0, true)); //imgpar.KeepTogether = true; if (fMulticolumns) { fColumns.AddElement(img); } else { fDocument.Add(img); } } }
//通过Url方式获取图片 private void Button_Click(object sender, RoutedEventArgs e) { Document document = new Document(); PdfWriter.GetInstance(document, new FileStream("Url获取图片.pdf", FileMode.OpenOrCreate)); document.Open(); //uri方式 //Image image = Image.GetInstance(new Uri("images/11.jpg",UriKind.Absolute)); //document.Add(image); //路径 Image image2 = Image.GetInstance("11.jpg"); //图片放在/bin/debug下 image2.ScaleToFit(document.PageSize); //缩放图片 //Chunk chunk=new Chunk(image2,); document.Add(image2); document.Close(); Title = "图片"; }
public void image() { iTextSharp.text.Image PatientSign = iTextSharp.text.Image.GetInstance(Autobuses.Properties.Resources.llavess, System.Drawing.Imaging.ImageFormat.Png); PatientSign.Alignment = Element.ALIGN_LEFT; PatientSign.ScaleToFit(140f, 00f); linea.Append(PatientSign); }
protected void Button1_Click(object sender, EventArgs e) { try { string imageFilePath = Server.MapPath(".") + "/pdf/logo.jpg"; iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(imageFilePath); Document pdfDoc = new Document(PageSize.A4, 25, 10, 25, 10); jpg.Alignment = iTextSharp.text.Image.UNDERLYING; jpg.ScaleToFit(200, 200); PdfWriter pdfWriter = PdfWriter.GetInstance(pdfDoc, Response.OutputStream); pdfDoc.Open(); Paragraph Text = new Paragraph("This is test file"); pdfDoc.Add(jpg); pdfDoc.Add(Text); pdfWriter.CloseStream = false; pdfDoc.Close(); Response.Buffer = true; Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", "attachment;filename=Example.pdf"); Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Write(pdfDoc); Response.End(); } catch (Exception ex) { Response.Write(ex.Message); } }
public FileResult Export(string GridHtml) { var fpath = ""; try { using (MemoryStream stream = new System.IO.MemoryStream()) { // fpath = HttpContext.Server.MapPath("~/PDFFiles/Quotation/"); StringReader sr = new StringReader(GridHtml); Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f); PdfWriter writer = PdfWriter.GetInstance(pdfDoc, stream); pdfDoc.Open(); iTextSharp.text.Image image1 = iTextSharp.text.Image.GetInstance(HttpContext.Server.MapPath("~/NewCssAndTheme/img/ssmlogo.jpg")); image1.Alignment = iTextSharp.text.Image.ALIGN_CENTER; image1.SetAbsolutePosition(20, 780); image1.ScaleToFit(80f, 80f); pdfDoc.Add(image1); XMLWorkerHelper.GetInstance().ParseXHtml(writer, pdfDoc, sr); pdfDoc.Close(); return(File(stream.ToArray(), "application/pdf", "Quotation.pdf")); // return File(HttpContext.Server.MapPath("~/PDFFiles/Quotation/") , "application/pdf", "Grid.pdf"); } } catch (Exception ex) { ErrorHandlerClass.LogError(ex); } return(null); }
public static void MakePDF(string fileName) { FileStream fs = new FileStream(fileName, FileMode.Create); Document doc = new Document(PageSize.A4.Rotate(), 10, 10, 10, 10); PdfWriter writer = PdfWriter.GetInstance(doc, fs); doc.AddTitle("Sitzplan"); doc.Open(); // string tmpPath = System.IO.Path.GetDirectoryName(Environment.GetCommandLineArgs()[0]).Replace("\\bin\\Debug", "\\tmp\\"); string tmpPath = System.IO.Path.GetTempPath(); string picName = "Sitzplan-Block{}.png"; for (int i = 1; i < 7; i++) { doc.Add(new Paragraph("Block " + Convert.ToString(i))); string tmpPicName = picName.Replace("{}", Convert.ToString(i)); iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(tmpPath + tmpPicName); img.ScaleToFit(PageSize.A4.Rotate()); img.SetAbsolutePosition(10, 0); doc.Add(img); doc.NewPage(); } doc.Close(); writer.Close(); fs.Close(); }
public static int Imprimir(Evento S) { FileStream fs = new FileStream("ticket0" + S.Version + ".pdf", FileMode.Create, FileAccess.Write, FileShare.None); Document doc = new Document(PageSize.A7, 2f, 2f, 5f, 5f); PdfWriter writer = PdfWriter.GetInstance(doc, fs); var titleFont = FontFactory.GetFont("Arial", 42, 1, BaseColor.BLACK); var font2 = FontFactory.GetFont("Arial", 14, 0, BaseColor.BLACK); Paragraph Para = new Paragraph(S.Version, titleFont); Para.Alignment = Element.ALIGN_CENTER; Paragraph Para1 = new Paragraph("JUEGOS " + S.Nombre, font2); Para1.Alignment = Element.ALIGN_CENTER; Paragraph Para2 = new Paragraph(DateTime.Now.ToShortDateString(), font2); Para2.Alignment = Element.ALIGN_CENTER; Paragraph Para3 = new Paragraph(DateTime.Now.ToShortTimeString(), font2); Para3.Alignment = Element.ALIGN_CENTER; Paragraph Para4 = new Paragraph("Espere Su turno Gracias", font2); Para4.Alignment = Element.ALIGN_CENTER; doc.Open(); doc.Add(Para1); try { iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance("../../Hammer/HamPresentation/erpHammerClient/src/assets/0" + S.EventoId + "/logos/logo1.png"); jpg.Alignment = Element.ALIGN_CENTER; jpg.ScaleToFit(70f, 32f); doc.Add(jpg); } catch (Exception ex) { } doc.Add(Para2); doc.Add(Para3); doc.Add(new Paragraph(" Tiket Nro.")); doc.Add(Para); doc.Add(Para4); doc.Close(); //Response.ContentType = "pdf/application"; //Response.AddHeader("content-disposition", "attachment;filename=First_PDF_document.pdf"); //Response.OutputStream.Write(ms.GetBuffer(), 0, ms.GetBuffer().Length); System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.StartInfo.Verb = "Print"; proc.StartInfo.CreateNoWindow = true; proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; //proc.StartInfo.Verb = "Print"; proc.StartInfo.FileName = "ticket0" + S.Version + ".pdf"; proc.Start(); proc.WaitForExit(); proc.Close(); return(1); }
//this function is capable of taking multiple tiff images from a directory //and processing each tiff frame by frame private void AddTiff(Document pdfDocument, iTextSharp.text.Rectangle pdfPageSize, String tiffPath) { RandomAccessFileOrArray ra = new RandomAccessFileOrArray(tiffPath); int pageCount = TiffImage.GetNumberOfPages(ra); for (int i = 1; i <= pageCount; i++) { iTextSharp.text.Image img = TiffImage.GetTiffImage(ra, i); if (img.ScaledWidth > pdfPageSize.Width || img.ScaledHeight > pdfPageSize.Height) { img.SetDpi(2, 2); if (img.DpiX != 0 && img.DpiY != 0 && img.DpiX != img.DpiY) { float percentX = (pdfPageSize.Width * 100) / img.ScaledWidth; float percentY = (pdfPageSize.Height * 100) / img.ScaledHeight; img.ScalePercent(percentX, percentY); img.WidthPercentage = 0; } else { img.ScaleToFit(pdfPageSize.Width, pdfPageSize.Height); } } iTextSharp.text.Rectangle pageRect = new iTextSharp.text.Rectangle(0, 0, img.ScaledWidth, img.ScaledHeight); pdfDocument.SetPageSize(pageRect); pdfDocument.SetMargins(0, 0, 0, 0); pdfDocument.NewPage(); pdfDocument.Add(img); } }
private void SaveBitmaps(Document pdfDocument, iTextSharp.text.Rectangle pdfPageSize, List <Bitmap> bitMaps) { int pageCount = bitMaps.Count; for (int i = 0; i < pageCount; i++) { System.Drawing.Image bitImg = (System.Drawing.Image)bitMaps[i]; iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(bitImg, BaseColor.WHITE); if (img.ScaledWidth > pdfPageSize.Width || img.ScaledHeight > pdfPageSize.Height) { if (img.DpiX != 0 && img.DpiY != 0 && img.DpiX != img.DpiY) { img.ScalePercent(100f); float percentX = (pdfPageSize.Width * 100) / img.ScaledWidth; float percentY = (pdfPageSize.Height * 100) / img.ScaledHeight; img.ScalePercent(percentX, percentY); img.WidthPercentage = 0; } else { img.ScaleToFit(pdfPageSize.Width, pdfPageSize.Height); } } iTextSharp.text.Rectangle pageRect = new iTextSharp.text.Rectangle(0, 0, img.ScaledWidth, img.ScaledHeight); pdfDocument.SetPageSize(pageRect); pdfDocument.SetMargins(0, 0, 0, 0); pdfDocument.NewPage(); pdfDocument.Add(img); } }
public void build() { try { iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(AppDomain.CurrentDomain.BaseDirectory + ImageUrl); float x = image.Width; float y = image.Height; float retio = x / y; float pageHeight = Document.PageSize.Height; if (IsHeader) { //fit to screen x = Document.PageSize.Width; y = x / retio; marginBottom = (int)(pageHeight - y); } image.ScaleToFit(x, x / retio); image.SetAbsolutePosition(Left, Top); PdfContentByte cb = Writer.DirectContent; PdfTemplate tp = cb.CreateTemplate(x, x / retio); tp.AddImage(image); cb.AddTemplate(tp, 0, marginBottom); } catch (Exception e) { } }
private void backgroundSources() { Paragraph p = new Paragraph(); p.Add("Discussion sources:"); document.Add(p); foreach (Attachment at in discussion.Attachment) { BitmapSource src = MiniAttachmentManager.GetAttachmentBitmap2(at); System.Drawing.Image drawingImg = BitmapSourceToBitmap(src); iTextSharp.text.Image itextImg = iTextSharp.text.Image.GetInstance(drawingImg, BaseColor.WHITE); itextImg.ScaleToFit(150, 200); document.Add(itextImg); switch ((AttachmentFormat)at.Format) { case AttachmentFormat.Pdf: break; case AttachmentFormat.Bmp: case AttachmentFormat.Jpg: case AttachmentFormat.Png: break; case AttachmentFormat.Youtube: p = new Paragraph(); p.Add("Youtube: " + at.VideoLinkURL); document.Add(p); break; default: throw new NotSupportedException(); } } }
public void PrintImgBytesPdf(byte[] _b) { string filePath = pdfPath + "/" + pdfName; Document document = new Document(pageSize, 0, 0, 0, 0); PdfWriter.GetInstance( document, new FileStream(filePath, FileMode.Create) ); document.Open(); iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(_b); if ((image.Height > pageSize.Height) || (image.Width > pageSize.Width)) { image.ScaleToFit(pageSize.Width, pageSize.Height); } //image.ScaleAbsolute(image.Width, image.Height); // image.Alignment = Image.LEFT_BORDER; image.Alignment = Element.ALIGN_MIDDLE;//居中对齐 document.Add(image); document.Close(); //Debug.Log(" 打印完成!文件保存在:" + filePath); Invoke("PringPdf", 1f); }
void ConvertPicture2PDF() { // UnityEngine.Debug.Log(pageSize); // Document doc = new Document(PageSize.A4.Rotate());//创建一个A4文档 Document doc = new Document(pageSize, 0, 0, 0, 0); //创建一个A4文档 PdfWriter.GetInstance(doc, new FileStream(pdfPath + "/" + pdfName, FileMode.Create)); //该文档创建一个pdf文件实例 iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(new FileStream(picPath + "/" + picName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)); //创建一个Image实例 //限制图片不超出A4范围 // image.ScaleToFit(PageSize.A4.Width - 25, PageSize.A4.Height - 25); //} if ((image.Height > pageSize.Height) || (image.Width > pageSize.Width)) { image.ScaleToFit(pageSize.Width, pageSize.Height); } image.Alignment = Element.ALIGN_MIDDLE; image.Border = 0; // image.SetAbsolutePosition doc.Open(); doc.Add(image); doc.Close(); // System.Diagnostics.Process.Start("mspaint.exe", "\"/pt \"" + ttpdfpath); //System.Diagnostics.Process.Start("mspaint.exe", "\"/pt " + ttpdfpath+ "\""); // N:/ unitytproject temp / printPDF / Assets / StreamingAssets / Test.pdf Invoke("PringPdf", 1f); }
public void CartDWPdfGenerationforEmail(int cartDWID) { // Render the view html to a string. _shoppingCartSrv.UserVM = UserVM; CartDWPdfModel orderVM = _shoppingCartSrv.GetQuotePdfDetails(cartDWID); string htmlText = (this._htmlViewRenderer.RenderViewToString(this, "../TCPViews/DWCartPdfGenerationWithHTML", orderVM)); Document document = new Document(PageSize.A4, 40f, 30f, 20f, 30f); string fname = cartDWID + ".pdf"; PdfWriter.GetInstance(document, new FileStream(ConfigurationManager.AppSettings["PdfPath"] + fname, FileMode.Create)); document.Open(); iTextSharp.text.Image pdfImage = iTextSharp.text.Image.GetInstance(Server.MapPath("~/Images/PenWorthyLogo.jpg")); pdfImage.ScaleToFit(150, 70); pdfImage.Alignment = iTextSharp.text.Image.UNDERLYING; pdfImage.SetAbsolutePosition(200, 600); document.Add(pdfImage); HTMLWorker hw = new HTMLWorker(document); hw.Parse(new StringReader(htmlText)); document.Close(); Response.ClearContent(); Response.ClearHeaders(); Response.AddHeader("Content-Disposition", "inline;filename=" + fname); Response.ContentType = "application/pdf"; Response.WriteFile(ConfigurationManager.AppSettings["PdfPath"] + fname); Response.Flush(); Response.Clear(); string toEmail = UserVM != null ? UserVM.CRMModelProperties.CustEmail : string.Empty; List <string> FilePath = Directory.GetFiles(ConfigurationManager.AppSettings["PdfPath"], fname).ToList(); _emailservice.SendMail("Pdf Attachment", "Thank you for your Order", true, true, FilePath, null, null, toEmail, null, cartDWID); // _emailservice.SendTestMail("Pdf Attachment", "Thank you for your Order", true, true, null, null, null, toEmail, null, cartDWID, null, 0, null); Response.End(); }
// This keeps track of the creation time public override void OnOpenDocument(PdfWriter writer, Document document) { try { bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); cb = writer.DirectContent; //Create PdfTable object tableHeader.TotalWidth = PageSize.A4.Width - 20; tableHeader.LockedWidth = true; PdfPCell cell = new PdfPCell(new Phrase(headerText, FontFactory.GetFont(Font.HELVETICA.ToString(), 14, Font.BOLD, Color.BLACK))); cell.Colspan = 11; cell.FixedHeight = 35f; cell.PaddingTop = 10f; cell.BorderWidth = 0f; cell.HorizontalAlignment = Element.ALIGN_RIGHT; tableHeader.AddCell(cell); System.IO.Stream stream = UIImage.FromBundle("Logo 1").AsPNG().AsStream(); byte[] array = ToByteArray(stream); iTextSharp.text.Image image = Image.GetInstance(array); image.ScaleToFit(30f, 30f); image.Alignment = Element.ALIGN_RIGHT; PdfPCell cellImage = new PdfPCell(); cellImage.AddElement(new Chunk(image, 0, 0)); cellImage.PaddingLeft = 20f; cellImage.BorderWidth = 0f; cellImage.HorizontalAlignment = Element.ALIGN_RIGHT; tableHeader.AddCell(cellImage); } catch (DocumentException de) { } catch (System.IO.IOException ioe) { } }
/// <summary> /// using itextsharp : /// 1 - Create Message /// 2 - Create Lists /// 3 - Working with images /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void msgpdf_btn_Click(object sender, EventArgs e) { // 1 Document doc = new Document(PageSize.LETTER, 10, 10, 42, 35); PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream("MessagTest.pdf", FileMode.Create)); doc.Open(); Paragraph paragraph = new Paragraph("Testing Itextsharp !!"); doc.Add(paragraph); // 2 List list = new List(List.UNORDERED); list.Add(new ListItem("One")); list.Add("Two"); list.Add("Three"); list.Add("four"); doc.Add(list); // 3 iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(@"C:\Users\DELL\Desktop\stock-management-app\Learn ItextSharp\Lighthouse.jpg"); //image.ScalePercent(20f); //image.SetAbsolutePosition(doc.PageSize.Width - 36f - 72f, doc.PageSize.Height - 36f - 216.6f); image.ScaleToFit(50f, 100f); image.Border = iTextSharp.text.Rectangle.BOX; image.BorderColor = iTextSharp.text.BaseColor.YELLOW; image.BorderWidth = 5f; doc.Add(image); doc.Close(); }
static void Main(string[] args) { String Folio_val = args[0]; string path = Directory.GetCurrentDirectory(); // String Folio_val = "https://www.google.com"; // String Direccion = "http://rppccolimaevidencias.col.gob.mx:8182/evidencia/Certi2?Secuence=" + Folio_val; String Direccion = Folio_val; QrEncoder qrEncoder = new QrEncoder(ErrorCorrectionLevel.H); QrCode qrCode = new QrCode(); qrEncoder.TryEncode(Direccion, out qrCode); GraphicsRenderer render = new GraphicsRenderer(new FixedModuleSize(400, QuietZoneModules.Zero), Brushes.Black, Brushes.White); MemoryStream ms = new MemoryStream(); render.WriteToStream(qrCode.Matrix, ImageFormat.Jpeg, ms); var imagenTemporal = new Bitmap(ms); var imagen = new Bitmap(imagenTemporal, new Size(new Point(200, 200))); imagen.Save(@path + "\\codigo.jpeg", ImageFormat.Jpeg); using (Document doc = new Document(PageSize.LETTER, 30f, 20f, 50f, 40f)) { PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(@path + "\\prueba.pdf", FileMode.Create)); writer.PageEvent = new HeaderFooter(); doc.Open(); iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(@path + "\\codigo.jpeg"); iTextSharp.text.Font _standardFont = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 8, iTextSharp.text.Font.NORMAL, BaseColor.BLACK); img.SetAbsolutePosition(500, 700); img.ScaleToFit(50f, 50F); doc.Add(img); doc.Close(); writer.Close(); } Console.WriteLine(Folio_val); }
private void ExportEfficiency_To_PDF() { System.Drawing.Bitmap screenshot_bmp = PrintScreen(); iTextSharp.text.Image screenshot_pdf = iTextSharp.text.Image.GetInstance(screenshot_bmp, System.Drawing.Imaging.ImageFormat.Bmp); var save_file_dialog = new SaveFileDialog(); save_file_dialog.FileName = "Efficiency " + DateTime.Now.Date.ToString("dd'-'MM'-'yyyy"); save_file_dialog.DefaultExt = ".pdf"; save_file_dialog.Filter = "PDF(*.pdf)|*.pdf"; if (save_file_dialog.ShowDialog() == DialogResult.OK) { using (FileStream fs = new FileStream(save_file_dialog.FileName, FileMode.Create)) { Document doc = new Document(PageSize.A4); PdfWriter.GetInstance(doc, fs); float maxWidth = doc.PageSize.Width - doc.LeftMargin - doc.RightMargin; float maxHeight = doc.PageSize.Height - doc.TopMargin - doc.BottomMargin; if (screenshot_pdf.Height > maxHeight || screenshot_pdf.Width > maxWidth) { screenshot_pdf.ScaleToFit(maxWidth, maxHeight); } doc.Open(); doc.Add(screenshot_pdf); doc.Close(); fs.Close(); } save_file_dialog.Dispose(); } }
private void GenerateTitle(Document doc) { doc.NewPage(); Image img = Image.GetInstance(Path.Combine(Environment.CurrentDirectory, "mg-logo.png")); img.ScaleToFit(125f, 60F); doc.Add(img); iTextSharp.text.Font font = FontFactory.GetFont(FontFactory.COURIER_BOLD, 14); Paragraph p = new Paragraph(reportTitle, font) { SpacingBefore = -35, SpacingAfter = 0, Alignment = 1 }; doc.Add(p); doc.Add(Chunk.NEWLINE); iTextSharp.text.Font font1 = FontFactory.GetFont(FontFactory.COURIER_BOLD, 12); Paragraph p1 = new Paragraph(rolId.Equals(3) ? "Clientes externos" : "Clientes internos", font1) { SpacingBefore = -25, SpacingAfter = 3, Alignment = 1 }; doc.Add(p1); doc.Add(Chunk.NEWLINE); }
public void Save(System.Drawing.Bitmap bm, string filename, System.Drawing.RotateFlipType rotate) { Bitmap image = bm; if (rotate != RotateFlipType.RotateNoneFlipNone) { image.RotateFlip(rotate); } using (FileStream stream = new FileStream(filename, FileMode.Create)) { using (iTextSharp.text.Document pdfDocument = new iTextSharp.text.Document(PageSize.LETTER, PAGE_LEFT_MARGIN, PAGE_RIGHT_MARGIN, PAGE_TOP_MARGIN, PAGE_BOTTOM_MARGIN)) { iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(pdfDocument, stream); pdfDocument.Open(); MemoryStream ms = new MemoryStream(); image.Save(ms, System.Drawing.Imaging.ImageFormat.Tiff); iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(ms); img.ScaleToFit(PageSize.LETTER.Width - (PAGE_LEFT_MARGIN + PAGE_RIGHT_MARGIN), PageSize.LETTER.Height - (PAGE_TOP_MARGIN + PAGE_BOTTOM_MARGIN)); pdfDocument.Add(img); pdfDocument.Close(); writer.Close(); } } }
public void ExportToPdf() { Document doc = new Document(PageSize.A4, 10f, 10f, 100f, 0f); string pdfFilePath = Server.MapPath(".") + "/Bin"; PdfWriter writer = PdfAWriter.GetInstance(doc, new FileStream(pdfFilePath + "/Default.pdf", FileMode.Create)); doc.Open(); try { iTextSharp.text.Font font5 = iTextSharp.text.FontFactory.GetFont(FontFactory.HELVETICA, 30); Paragraph paragraph = new Paragraph("Getting Started ITextSharp.", font5); paragraph.Alignment = Element.ALIGN_CENTER; font5 = iTextSharp.text.FontFactory.GetFont(FontFactory.HELVETICA, 5); Paragraph parag = new Paragraph("Getting Started ITextSharp.", font5); string imageURL = Server.MapPath(".") + "/images/text1.png"; iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(imageURL); //Resize image depend upon your need jpg.ScaleToFit(500f, 500f); //Give space before image jpg.SpacingBefore = 10f; //Give some space after the image jpg.SpacingAfter = 1f; jpg.Alignment = Element.ALIGN_LEFT; doc.Add(paragraph); doc.Add(jpg); doc.Add(parag); doc.Close(); } catch (Exception i) { Response.Write(i.Message); } }
public static byte[] StampaEmailAttoITEXT(List <MailHeaderExtended> dt, string account, string cartella, string datai, string dataf, string parentFolder, string accountid) { // step 1: creation of a document-object Document document = new Document(PageSize.A4.Rotate(), 10, 10, 70, 15); MemoryStream ms = new MemoryStream(); // step 2: we create a writer that listens to the document PdfWriter writer = PdfWriter.GetInstance(document, ms); iTextSharp.text.Image imageHeader = iTextSharp.text.Image.GetInstance(ConfigurationManager.AppSettings["Logo"]); imageHeader.ScaleToFit(400, 80); MyPageEventHandler e = new MyPageEventHandler() { ImageHeader = imageHeader, Titolo = "N. righe : " + dt.Count.ToString() + " - Email: " + account + " Cartella: " + cartella + " intervallo date : " + datai + " - " + dataf }; writer.PageEvent = e; //set some header stuff document.AddTitle("Elenco Email"); document.AddSubject("Elenco Email"); document.AddCreator("Roma Capitale"); document.AddAuthor("n.r."); // step 3: we open the document document.Open(); // step 4: we add content to the document CollectionToPDFTableAtti(ref document, dt, parentFolder, accountid); // step 5: we close the document document.Close(); return(ms.ToArray()); }
public override byte[] CreatePdf(List <PdfContentParameter> contents, string[] images, int type) { var document = new Document(); float docHeight = document.PageSize.Height - heightOffset; document.SetPageSize(iTextSharp.text.PageSize.A4.Rotate()); document.SetMargins(50, 50, 10, 40); var output = new MemoryStream(); var writer = PdfWriter.GetInstance(document, output); writer.PageEvent = new HeaderFooterHandler(type); document.Open(); document.Add(contents[0].Table); for (int i = 0; i < images.Length; i++) { document.NewPage(); float subtrahend = document.PageSize.Height - heightOffset; iTextSharp.text.Image pool = iTextSharp.text.Image.GetInstance(images[i]); pool.Alignment = 3; pool.ScaleToFit(document.PageSize.Width - (document.RightMargin * 2), subtrahend); //pool.ScaleAbsolute(document.PageSize.Width - (document.RightMargin * 2), subtrahend); document.Add(pool); } document.Close(); return(output.ToArray()); }
void WriteWingDing(PdfPTable t, string level) { PdfPCell c = new PdfPCell(); if (level == "0") { t.AddCell(c); return; } c.PaddingLeft = 5; level = level.Substring(0, 1); Paragraph ph = new Paragraph(); ph.Add(new Chunk(level)); string color = "green"; if (level == "2") { color = "yellow"; } if (level == "3") { color = "red"; } iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(this.BaseUrl + @"images/" + color + ".png"); float size = 7; img.ScaleToFit(size, size); ph.Add(new Chunk(img, 0, 0)); c.AddElement(ph); c.HorizontalAlignment = PdfPCell.ALIGN_CENTER; c.VerticalAlignment = PdfPCell.ALIGN_MIDDLE; t.AddCell(c); }
private static void AddLogoToPdf(AgencyOwnerFixedPriceProposalDetailsOutput proposal, PdfPTable layoutTable) { PdfPCell orgImageCell = new PdfPCell { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_LEFT, VerticalAlignment = Element.ALIGN_TOP, MinimumHeight = 80 }; if (!string.IsNullOrEmpty(proposal.AccountManagerOrganizationImageUrl?.Trim())) { Image orgImage = Image.GetInstance(proposal.AccountManagerOrganizationImageUrl); orgImage.ScaleToFit(70, 70); orgImage.Alignment = Element.ALIGN_LEFT | Element.ALIGN_TOP; orgImageCell.AddElement(orgImage); } layoutTable.AddCell(orgImageCell); var fontHeader = GetCommonFont(22); AddCellToTable(layoutTable, fontHeader, "Proposal", Element.ALIGN_RIGHT, 1, 2); AddCellToTable(layoutTable, fontHeader, "", Element.ALIGN_RIGHT, 1, 3); }
private void PrintSlide(Slide slide, PdfPTable table, bool withSlideNumbers) { PdfPCell cell; Font font = FontFactory.GetFont(FontFactory.HELVETICA, BaseFont.CP1250, 10); if (withSlideNumbers) { int nr = slide.Nr + 1; cell = new PdfPCell(new iTextSharp.text.Paragraph(nr.ToString(), font)); cell.BorderWidth = 0; cell.VerticalAlignment = Element.ALIGN_MIDDLE; table.AddCell(cell); } if (slide.Image != null) { iTextSharp.text.Image pdfImage = iTextSharp.text.Image.GetInstance(slide.Image, System.Drawing.Imaging.ImageFormat.Bmp); pdfImage.ScaleToFit(250, 250); cell = new PdfPCell(pdfImage); } else { // PDF image is not set for this slide (PDF slides weren't imported or user decided to add additional slides) cell = new PdfPCell(); } cell.BorderWidth = 0; table.AddCell(cell); cell = new PdfPCell(new iTextSharp.text.Paragraph(slide.Text, font)); cell.BorderWidth = 0; cell.VerticalAlignment = Element.ALIGN_MIDDLE; table.AddCell(cell); }
private void exportpdf() { Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", "attachment;filename=OrderInvoice.pdf"); Response.Cache.SetCacheability(HttpCacheability.NoCache); StringWriter sw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw); Panel1.RenderControl(hw); StringReader sr = new StringReader(sw.ToString()); Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f); HTMLWorker htmlparser = new HTMLWorker(pdfDoc); PdfWriter.GetInstance(pdfDoc, Response.OutputStream); pdfDoc.Open(); byte[] file; file = System.IO.File.ReadAllBytes(Server.MapPath("~/img/logotitle.jpg")); //ImagePath iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(file); jpg.ScaleToFit(150F, 150F); //Set width and height in float pdfDoc.Add(jpg); htmlparser.Parse(sr); //Label7.Text = "" + "<img src='img/logotitle.jpg' >"; pdfDoc.Close(); Response.Write(pdfDoc); Response.End(); }
// Propuesta CRECE public void ObtenerQRDesdeCRECE() { Document doc = new Document(PageSize.A4, 10f, 10f, 100f, 0f); string pdfFilePath = "C:\\Desarrollo"; PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(pdfFilePath + "\\pdf.pdf", FileMode.Open)); doc.Open(); try { Paragraph paragraph = new Paragraph("Getsssssssting Started ITextSharp."); string imageURL = "C:\\Desarrollo\\HI16157.png"; iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance("http://192.168.2.209/creceimp/qr.php?valor=123"); //Resize image depend upon your need jpg.ScaleToFit(140f, 120f); //Give space before image jpg.SpacingBefore = 10f; //Give some space after the image jpg.SpacingAfter = 1f; jpg.Alignment = Element.ALIGN_LEFT; doc.Add(paragraph); doc.Add(jpg); } catch (Exception ex) { } finally { doc.Close(); } ManipulatePdf(); }
public String ConvertVatImageToPdf(string Name) { iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(Name); int pos = Name.LastIndexOf("\\") + 1; vatfilename = Name.Substring(pos, Name.Length - pos).Replace(" ", ""); vatfilename = vatfilename.Remove(vatfilename.LastIndexOf(".") + 1).ToLower(); vatfilename = DateTime.Now + "-" + vatfilename + "pdf"; vatfilename = vatfilename.Replace("/", "-").Replace(":", "").Replace(" ", "-"); string OutPutFile = Server.MapPath(("~/Vat/" + vatfilename)); using (FileStream fs = new FileStream(OutPutFile, FileMode.Create, FileAccess.Write, FileShare.None)) { using (Document doc = new Document(PageSize.A4, 10f, 10f, 10f, 0f)) { using (PdfWriter writer = PdfWriter.GetInstance(doc, fs)) { doc.Open(); image.ScaleToFit(doc.PageSize); image.Alignment = iTextSharp.text.Image.TEXTWRAP | iTextSharp.text.Image.ALIGN_RIGHT; image.SetAbsolutePosition((PageSize.A4.Width - image.ScaledWidth) / 2, (PageSize.A4.Height - image.ScaledHeight) / 2); writer.DirectContent.AddImage(image); doc.Close(); } } } if (File.Exists(Name)) { File.Delete(Name); } OutPutFile = "/Vat/" + vatfilename; return(OutPutFile); }
/// <summary> /// To Create header image and header title /// </summary> /// <returns>HeaderTable</returns> private static PdfPTable AddHeader(Image headerLogo) { headerLogo.ScaleToFit(125f, 100f); PdfPTable HeaderTable = GetPdfTable(2, false, 0, 100); HeaderTable.SetWidths(new float[] { 40f, 60f }); PdfPCell LogoCell = GetPdfTableCell(Rectangle.BOX, BaseColor.WHITE, 0); LogoCell.AddElement(new Chunk(headerLogo, 0, 0)); PdfPCell TitleCell = GetPdfTableCell(Rectangle.BOX, BaseColor.WHITE, 0); TitleCell.AddElement(new Paragraph(Constants.SURGERY_USAGE, FontBoldBig) { Alignment = Element.ALIGN_RIGHT }); HeaderTable.AddCell(LogoCell); HeaderTable.AddCell(TitleCell); return HeaderTable; }