itextsharp

Highlighting text ( colors ) of existing PDF using iTextsharp using C#

社会主义新天地 提交于 2019-11-27 03:05:40
问题 I would like know whether we can highlight text (colors) of already created PDF using itextsharp ? I see examples like creating a new PDF, while doing so we can apply colors. I am looking for where I can get chunks of text from PDF and apply colors and save it. Here is the thing I am trying to accomplish, read a PDF file, parse text and highlight text based on business rules. Any third party dll suggestion also works, as a first step I am looking in to opensource iTextsharp library . 回答1: Yes

Need help with creating PDF from HTML using itextsharp

蓝咒 提交于 2019-11-27 02:56:10
问题 I'm trying to crate a PDF out of a HTML page. The CMS I'm using is EPiServer. This is my code so far: protected void Button1_Click(object sender, EventArgs e) { naaflib.pdfDocument(CurrentPage); } public static void pdfDocument(PageData pd) { //Extract data from Page (pd). string intro = pd["MainIntro"].ToString(); // Attribute string mainBody = pd["MainBody"].ToString(); // Attribute // makae ready HttpContext HttpContext.Current.Response.Clear(); HttpContext.Current.Response.ContentType =

How can I add an image to all pages of my PDF?

a 夏天 提交于 2019-11-27 02:24:43
I have been trying to add an image to all pages using itextsharp. The image needs to be OVER all content of every page. I have used the following code below all the other doc.add() Document doc = new Document(iTextSharp.text.PageSize.A4, 10, 10, 30, 1); PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(Server.MapPath("~/pdf/" + fname), FileMode.Create)); doc.Open(); Image image = Image.GetInstance(Server.MapPath("~/images/draft.png")); image.SetAbsolutePosition(12, 300); writer.DirectContent.AddImage(image, false); doc.Close(); The above code only inserts an image in the last page.

How can I extract subscript / superscript properly from a PDF using iTextSharp?

折月煮酒 提交于 2019-11-27 02:22:00
iTextSharp works well extracting plain text from PDF documents, but I'm having trouble with subscript/superscript text, common in technical documents. TextChunk.SameLine() requires two chunks to have identical vertical positioning to be "on" the same line, which isn't the case for superscript or subscript text. For example, on page 11 of this document, under "COMBUSTION EFFICIENCY": http://www.mass.gov/courts/docs/lawlib/300-399cmr/310cmr7.pdf Expected text: monoxide (CO) in flue gas in accordance with the following formula: C.E. = [CO2 /(CO + CO2)] Result text: monoxide (CO) in flue gas in

How to reduce memory consumption of PdfPTable with many cells

北战南征 提交于 2019-11-27 02:12:28
I'm creating a PDF using ITextSharp which is composed of a single PdfTable. Unfortunately for a particular data set, I'm getting an Out of memory Exception due to the large number PdfPCells that are created (I've profiled the memory usage - I've got nearly 1/2 a million cells !) Is there any way to reduce the memory usage in such a case? I've tried flushing at various points (after each row) and full compression The PdfWriter is based on a FileStream Code looks a pretty much like this: Document document = Document(); FileStream stream = new FileStream(fileName,FileMode.Create); pdfWriter =

How can I repeat the headers of an iTextSharp PdfPTable on each page?

人盡茶涼 提交于 2019-11-27 01:54:19
问题 How can I get iTextSharp to repeat the headers of a PdfPTable on each page of the generated PDF? 回答1: You just need to set the PdfPTable.HeaderRows property to the number of rows in your PdfPTable 's header like this: table.HeaderRows = 1; 来源: https://stackoverflow.com/questions/2062983/how-can-i-repeat-the-headers-of-an-itextsharp-pdfptable-on-each-page

put page number when create PDF with iTextSharp

随声附和 提交于 2019-11-27 01:48:10
I'm working with ASP MVC and i use iTextSharp to generate PDF's in my application. But now i have a problem: I printing lists and when exist more than one page, i want to show the page number (ex.: Page 1 to 4 ). I found some examples, but i think it is more complexes than i need to do (like exameple ). EDIT: I found this example 2 . I can count number of pages, but i cant print the number in pages. What i did: public ActionResult downloadListaISCC(DateTime? DataFimFiltro) { //Code to generate list to PDF //My document Document doc1 = new Document(); doc1.SetPageSize(iTextSharp.text.PageSize

iTextSharp set document landscape (horizontal) A4

假装没事ソ 提交于 2019-11-27 01:44:14
问题 How can I set an A4 document in landscape (horizontal) format in iTextSharp? 回答1: You can set the page size to a rotated A4. E.g. (assuming PDF, but should apply regardless): iTextSharp.text.Document doc; // ...initialize 'doc'... // Set the page size doc.SetPageSize(iTextSharp.text.PageSize.A4.Rotate()); I've done this with PDF without trouble, haven't tried it with other doc types. 回答2: You can initialize a new document like that: Document doc = new Document(iTextSharp.text.PageSize.A4

iTextSharp - How to get the position of word on a page

半城伤御伤魂 提交于 2019-11-27 01:37:29
I am using iTextSharp and the reader.GetPageContent method to pull the text out of a PDF. I need to find the rectangle/position for each word found in the document. Is there any way to get the rectangle/position of a word in a PDF using iTextSharp? Yes there is. Check out the text.pdf.parser package, specifically LocationTextExtractionStrategy . Actually, that might not do the trick either. You'll probably want to write your own TextExtractionStrategy to feed into PdfTextExtractor: MyTexExStrat strat = new MyTexExStrat(); PdfTextExtractor.getTextFromPage(reader, pageNum, strat); // get the

Rotating PDF in C# using iTextSharp

徘徊边缘 提交于 2019-11-27 01:27:36
问题 I am using the below function to split the pdf into two. Though it is spliting the pdf, the content is appearing upside down. How do I rotate it by 180 degrees. Please help. below is the code for the same private static void ExtractPages(string inputFile, string outputFile, int start, int end) { // get input document PdfReader inputPdf = new PdfReader(inputFile); // retrieve the total number of pages int pageCount = inputPdf.NumberOfPages; if (end < start || end > pageCount) { end = pageCount