itextsharp

iTextSharp Html to Pdf image src

杀马特。学长 韩版系。学妹 提交于 2019-12-03 07:54:32
Convert a html to pdf using iTextSharp public static MemoryStream CreatePdfFromHtml( string html, List<Attachment> attachments) { MemoryStream msOutput = new MemoryStream(); using (TextReader reader = new StringReader(html)) using (Document document = new Document()) { PdfWriter writer = PdfWriter.GetInstance(document, msOutput); document.Open(); foreach (var a in attachments) { var image = iTextSharp.text.Image.GetInstance(a.File); document.Add(image); } XMLWorkerHelper.GetInstance().ParseXHtml(writer, document, reader); writer.CloseStream = false; document.Close(); msOutput.Position = 0;

Using itextsharp xmlworker to convert html to pdf and write text vertically

余生长醉 提交于 2019-12-03 07:19:50
Is there possible to achieve writing text direction bottom-up in xmlworker? I would like to use it in table. My code is <table border=1> <tr> <td style="padding-right:18px"> <p style="writing-mode:sideways-lr;text-align:center">First</p</td> <td style="padding-right:18px"> <p style="writing-mode:sideways-lr;text-align:center">Second</p></td></tr> <tr><td><p style="text-align:center">1</p> </td> <td><p style="text-align:center">2</p></td> </tr> </table> But it it doesn't work after conversion from html to pdf. Text FIRST and SECOND are not in direction bottom-to-up. This was a pretty

How do I insert a background image on all pages of a pdf-document? [closed]

淺唱寂寞╮ 提交于 2019-12-03 06:58:53
I need sample code in C# to insert the background image on all pages of the finished pdf-document. I'm using iTextSharp library. Soner Gönül You can try this; void makePDF() { Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", "attachment;filename=test.pdf"); Response.Cache.SetCacheability(HttpCacheability.NoCache); string imageFilePath = Server.MapPath(".") + "/images/test.jpg"; iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(imageFilePath); // Page site and margin left, right, top, bottom is defined Document pdfDoc = new Document(PageSize.A4,

How to set PDF paragraph or font line-height with iTextSharp?

允我心安 提交于 2019-12-03 05:09:13
How can I change the line-height of a PDF font or paragraph using iTextSharp? Line spacing in terms of typography is called leading. If you can use line spacing, you can use Paragraph.Leading or Paragraph.LeadingMultiplier. See http://itextsharp.sourceforge.net/tutorial/ch02.html#phrase paragraph.SetLeading(X, Y) where X - is fixed leading and Y is leading multiplayer. Leading is space between two text baselines. Final leading value is calculated like: X+Y*max font size in row. Not sure in what context your text is in, but I have mine in a PdfCell and I used MinimumHeight and PaddingTop: cAddr

iTextSharp read from specific position

◇◆丶佛笑我妖孽 提交于 2019-12-03 03:50:01
I have a problem using iTextSharp when reading data from PDF File. What I want to achieve is to read only specific part of PDF page (I want to only retrieve Address Information, which is located at constant position). I have seen usage of iTextSharp when reading all pages such as following: StringBuilder text = new StringBuilder(); if (File.Exists(fileName)) { PdfReader pdfReader = new PdfReader(fileName); for (int page = 1; page <= pdfReader.NumberOfPages; page++) { ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy(); string currentText = PdfTextExtractor.GetTextFromPage

Is there a straight forward way to append one PDF doc to another using iTextSharp?

老子叫甜甜 提交于 2019-12-03 03:24:59
I've scoured the Web looking for examples on how to do this. I've found a few that seem to be a little more involved then they need to be. So my question is, using iTextSharp, is there a fairly concise way to append one PDF document to another one? Optimally this would NOT involve a third file. Just open the first PDF doc, append the second PDF doc to the first and then close them both. I really may be missing something, but I did something much simpler. I concede this solution probably won't update bookmarks (as in the best answer here so far), but it works flawlessly for me. Since I was

Extract image from PDF using itextsharp

匿名 (未验证) 提交于 2019-12-03 02:11:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to extract all the images from a pdf using itextsharp but can't seem to overcome this one hurdle. The error occures on the line System.Drawing.Image ImgPDF = System.Drawing.Image.FromStream(MS); giving an error of "Parameter is not valid". I think it works when the image is a bitmap but not of any other format. I have this following code - sorry for the length; private void Form1_Load(object sender, EventArgs e) { FileStream fs = File.OpenRead(@"reader.pdf"); byte[] data = new byte[fs.Length]; fs.Read(data, 0, (int)fs.Length);

Set PDF Version using iTextSharp

匿名 (未验证) 提交于 2019-12-03 01:58:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Anyone know how to save a PDF as a lower PDF version programmatically using iTextSharp so that you can use certain iTextSharp features that require the PDF to be version 5 or lower? I'm trying to merge two PDF version 7 documents together and it insists that they be version 5 or lower. 回答1: How odd. PDF versions are mostly a suggestion. PDFs must start with something like: %PDF-1.x Where the X is 0,1,2,... This is just a clue to the app reading the PDF. The only clue. Most "I need version X" requests I see from various customers are bogus.

ITextSharp: Set table cell border color

匿名 (未验证) 提交于 2019-12-03 01:45:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How do I set the border color of a table cell. here is the code i have: // create and define table var table = new PdfPTable(8); table.HorizontalAlignment = Element.ALIGN_CENTER; //table.HeaderRows = 1; // the cell object PdfPCell cell; var f = FontFactory.GetFont("Tahoma", 11, Font.BOLD); cell = new PdfPCell(new Phrase("Source Review", f)); cell.BorderColorLeft = new BaseColor(255, 255, 255); cell.BorderColorRight = new iTextSharp.text.BaseColor(255, 255, 255); table.AddCell(cell); As you can see i am setting the color two different ways

itextsharp - Cant Set Checkbox when PdfStamper in Append Mode

匿名 (未验证) 提交于 2019-12-03 01:40:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to set some fields in a pdf but leave them open to be modified after they have been populated. My issue is that when I edit the pdf in append mode the checkboxes aren't getting set. The text fields work fine. string pdfTemplate = @"c:\test\fw4.pdf"; string newFile = @"c:\test\completed_fw4.pdf"; PdfReader pdfReader = new PdfReader(pdfTemplate); //PdfStamper pdfStamper = new PdfStamper(pdfReader, new System.IO.FileStream(newFile, System.IO.FileMode.Create), '\0', true); //doesn't set field - leaves editable PdfStamper pdfStamper = new