itextsharp

Create PDF in memory instead of physical file

穿精又带淫゛_ 提交于 2019-11-26 07:29:17
问题 How do one create PDF in memorystream instead of physical file using itextsharp. The code below is creating actual pdf file. Instead how can I create a byte[] and store it in the byte[] so that I can return it through a function using iTextSharp.text; using iTextSharp.text.pdf; Document doc = new Document(iTextSharp.text.PageSize.LETTER, 10, 10, 42, 35); PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream(\"c:\\\\Test11.pdf\", FileMode.Create)); doc.Open();//Open Document to write

iTextSharp - Sending in-memory pdf in an email attachment

心已入冬 提交于 2019-11-26 07:24:51
问题 I\'ve asked a couple of questions here but am still having issues. I\'d appreciate if you could tell me what I am doing wrong in my code. I run the code above from a ASP.Net page and get \"Cannot Access a Closed Stream\". var doc = new Document(); MemoryStream memoryStream = new MemoryStream(); PdfWriter.GetInstance(doc, memoryStream); doc.Open(); doc.Add(new Paragraph(\"First Paragraph\")); doc.Add(new Paragraph(\"Second Paragraph\")); doc.Close(); //if I remove this line the email

Reading PDF content with itextsharp dll in VB.NET or C#

╄→尐↘猪︶ㄣ 提交于 2019-11-26 06:54:59
How can I read PDF content with the itextsharp with the Pdfreader class. My PDF may include Plain text or Images of the text. ShravankumarKumar using iTextSharp.text.pdf; using iTextSharp.text.pdf.parser; using System.IO; public string ReadPdfFile(string fileName) { 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(pdfReader, page, strategy);

Right aligning text in PdfPCell

流过昼夜 提交于 2019-11-26 06:48:04
问题 I have a C# application that generates a PDF invoice. In this invoice is a table of items and prices. This is generated using a PdfPTable and PdfPCell s. I want to be able to right-align the price column but I cannot seem to be able to - the text always comes out left-aligned in the cell. Here is my code for creating the table: PdfPTable table = new PdfPTable(2); table.TotalWidth = invoice.PageSize.Width; float[] widths = { invoice.PageSize.Width - 70f, 70f }; table.SetWidths(widths); table

Read PDF using itextsharp where PDF language is non-English

拈花ヽ惹草 提交于 2019-11-26 06:46:35
问题 I am trying to read this PDF using itextsharp in C# which will convert this pdf into word file. also it needs to maintain table formating and fonts in word when i try with English pdf it will work perfectly but using some of the Indian languages like Hindi, Marathi it is not working. public string ReadPdfFile(string Filename) { string strText = string.Empty; StringBuilder text = new StringBuilder(); try { PdfReader reader = new PdfReader((string)Filename); if (File.Exists(Filename)) {

Add Header and Footer for PDF using iTextsharp

岁酱吖の 提交于 2019-11-26 06:33:47
问题 How can I add header and footer for each page in the pdf. Headed will contain just a text Footer will contain a text and pagination for pdf (Page : 1 of 4) How is this possible ? I tried to add the below line, but header does not show up in pdf. document.AddHeader(\"Header\", \"Header Text\"); This the code I am using for generation PDF : protected void GeneratePDF_Click(object sender, EventArgs e) { DataTable dt = getData(); Response.ContentType = \"application/pdf\"; Response.AddHeader(\

Page X of Y issue

走远了吗. 提交于 2019-11-26 05:54:42
问题 I tried 3 different ways of displaying Page numbers, OnCloseDocument content is not displaying in the page, none of them worked. My Intention is displaying Page numbers like this 1 of 10 2 0f 10 .............. ............ 10 of 10 on each page I know how to display 1 2 3 4 .... 10 but don`t know how to display total page number I`m using OnCloseDocument to display No.of pages count,but the content in it is not displaying. public class MyPdfPageEventHelpPageNo : iTextSharp.text.pdf

Using LocationTextExtractionStrategy in itextSharp for text coordinate

主宰稳场 提交于 2019-11-26 04:56:39
问题 My goal is to retrieve data from PDF which may be in table structure to an excel file. using LocationTextExtractionStrategy with iTextSharp we can get the string data in plain text with page content in left to right manner. How can I move forward such that during PdfTextExtractor.GetTextFromPage(reader, i, new LocationTextExtractionStrategy()) I could make the text retain its coordinate in the resulting string. As for instance if the first line in the pdf has text aligned to right, then the

Removing Watermark from PDF iTextSharp

谁都会走 提交于 2019-11-26 04:56:11
问题 I have gone through the solution suggested here but my problem is a little different. In the solution provided at the above link, one can remove the watermark only if iTextSharp is used to add the watermark as well. In my case, I am adding a watermark in some cases using Microsoft Word. When I use the following code, the watermark does disappear from the PDF but when I convert the PDF to Word, it watermark appears again as an image. As per my understanding, what the code below does is that it

How can I insert an image with iTextSharp in an existing PDF?

梦想与她 提交于 2019-11-26 04:41:10
问题 I have an existing PDF and I can use FdFWriter to input to text boxes. It works well. Now I have an image. I have read the documentation and looked at many examples but they all create new documents and insert an image. I want to take an existing PDF and insert an image into either an image field or as the icon image of a button. I have tried but it corrupts the document. I need to be able to take an existing document and put an image on it. I do not want to open, read, replace, and delete