itextsharp

iTextSharp for PDF - how add file attachments?

青春壹個敷衍的年華 提交于 2019-11-28 04:05:47
问题 I am using iTextSharp to create a PDF document in C#. I would like to attach another file to the PDF. I'm having just loads of trouble trying to do so. The examples here show some annotations, which apparently attachments are. This is what I've tried: writer.AddAnnotation(its.pdf.PdfAnnotation.CreateFileAttachment(writer, new iTextSharp.text.Rectangle(100,100,100,100), "File Attachment", its.pdf.PdfFileSpecification.FileExtern(writer, "C:\\test.xml"))); Well, what happens is it does add an

Header, footer and large tables with iTextSharp

和自甴很熟 提交于 2019-11-28 03:51:40
问题 I've added an header and a footer on my document by PdfPageEventHelper. The document has several "large" tables populated at runtime. I've tried to add those tables simply by "documen.Add(table)", but my header and my footer results overwritten. I've already tried both methods to add the tables (WriteSelectedRows and document.Add(myPdfPtable). Here is the code of the PageEventHelper: private class MyPageEventHandler : PdfPageEventHelper { public iTextSharp.text.Image ImageHeader { get; set; }

Rotating PDF 90 degrees using iTextSharp in C#

こ雲淡風輕ζ 提交于 2019-11-28 03:45:10
问题 I am trying to use a PDF for stamping and need to rotate it 90 degrees to lay it on correctly? Anyone know how to do this? Can't seem to find it online. 回答1: The Rotate90Degrees example uses PdfReader to get an instance of the document then changes the /Rotate value in every page dictionary. If there is no such entry, a /Rotate entry with value 90 is added: final PdfReader reader = new PdfReader(source); final int pagesCount = reader.getNumberOfPages(); for (int n = 1; n <= pagesCount; n++) {

ITextSharp PdfCopy use examples

偶尔善良 提交于 2019-11-28 03:26:39
问题 I am trying to use PdfSmartCopy from ItextSharp but I cannot find any relevant examples in c#. The ideea is that I have a pdf containing form fields and the fields add 700kb to the size of the pdf document. The original document without form fields was 100kb . Any other sugestions are welcome, especially o reduce the pdf size consistently. (I optimised the generated PDF with adobe acrobat, and it reduced it to 44kb . So there must be a glitch somewhere.) Is there any way to reduce the PDF

What are the ways of checking if piece of text in PDF documernt is bold using iTextSharp

强颜欢笑 提交于 2019-11-28 02:16:37
I have an application, that extracts headings out of pdf files. The documents, that the application is supposed to work with, all have more or less coherent structure and formatting, in fact, telling if a text chunk is bold or not, is very important. Recently I came across a bunch of files, where some chunks visually appear bold, but do not have "bold" piece in string representation of font. The following SO thread how can i get text formatting with iTextSharp helped me to understand, that there is one more way of making text appear bold. However in my case calling GetTextRenderMode() does not

Could not load type 'iTextSharp.text.html.HtmlParser' from assembly 'itextsharp, Version=5.5.5.0, Culture=neutral, PublicKeyToken=8354ae6d2174ddca'

£可爱£侵袭症+ 提交于 2019-11-28 02:16:31
问题 see this link converting html to pdf I got this version error in webconfig let some genius find and solve the qustion. My Model public class Customer { public int CustomerID { get; set; } public string FirstName { get; set; } public string LastName { get; set; } } My Controller this is normal code public ActionResult Index() { List<Customer> customers = new List<Customer>(); for (int i = 1; i <= 10; i++) { Customer customer = new Customer { CustomerID = i, FirstName = string.Format("FirstName

Get ONLY word count from PDF document

时光毁灭记忆、已成空白 提交于 2019-11-28 02:07:28
问题 I was hoping to get just the word count from a pdf document programmatically. I've looked at PDFSharp, but it's awefully bulky for what I want to do. I don't have access to the server, so I can't install acrobat to get to their api's or anything. I'd be willing to do it in iTextSharp or another tool. 回答1: iTextSharp has a wonderful PdfTextExtractor object that will get you all of the text (assumming as @Rob A pointed out that its actually stored as text and not images or pure vector). Once

AcroForm values missing after flattening

自作多情 提交于 2019-11-28 02:07:22
I'm using LibreOffice 4.1.3.2 to produce a fillable PDF: Created a Writer document Set some text and test fields Exported to PDF Opening pdf file with Acrobar Reader shows a correct fillable pdf. Next I use iTextSharp 5.4.5 to fill fields and save flattened document: var pdf = new PdfReader(srcFilename); using (var fw = new FileStream(dstFilename, FileMode.Create)) { var stamper = new PdfStamper(pdf, fw); var f = stamper.AcroFields; f.SetField("field1", "John Doe"); f.SetField("field2", "12/04/2013"); stamper.FormFlattening = true; stamper.Close(); } pdf.Close(); Problem is that filled fields

How to add text in PdfContentByte rectangle using itextsharp?

为君一笑 提交于 2019-11-28 01:59:35
I have created rectangle using PdfContentByte. Now I want to adda text inside this rectangle. How can I do this. If anybody have idea please share with me.My rectangle code is Document doc = new Document(new Rectangle(570, 924f)); PdfWriter writer = PdfWriter.GetInstance(doc,Response.OutputStream); PdfContentByte cb = writer.DirectContent; cb.Rectangle(doc.PageSize.Width -90f, 830f, 50f,50f); cb.Stroke(); You are drawing a rectangle like this: PdfContentByte cb = writer.DirectContent; cb.Rectangle(doc.PageSize.Width -90f, 830f, 50f,50f); cb.Stroke(); This corresponds with this Rectangle :

How to Set Height of PdfPTable in iTextSharp

时光总嘲笑我的痴心妄想 提交于 2019-11-28 01:53:18
i downloaded the last version of iTextSharp dll. I generated a PdfPTable object and i have to set it's height. Despite to set width of PdfPTable, im not able to set height of it. Some authors suggest to use 'setFixedHeight' method. But the last version of iTextSharp.dll has not method as 'setFixedHeight'. It's version is 5.5.2. How can i do it? Setting a table's height doesn't make sense once you start thinking about it. Or, it makes sense but leaves many questions unanswered or unanswerable. For instance, if you set a two row table to a height of 500, does that mean that each cell get's 250