itextsharp

ITextSharp 4.1.6 - Remove existing line from PDF Template

不羁的心 提交于 2019-11-29 16:30:51
I have a PDF template created in LibreOffice and I'm filling it in using AcroFields. In some rare cases I'd like to hide a particular field, thus I remove it using RemoveField method. It's border however stays in there. From what I've googled it seems it's probably the way LibreOffice creates the forms. What I've came up with so far was to get the rectangle of the field and cover it with white image. Problem however is, customer plans creating templates using background image and/or other background color than white making my current solution almost unusable The question therefore is - is

How do I insert a hyperlink to another page with iTextSharp in an existing PDF?

限于喜欢 提交于 2019-11-29 16:21:52
I would like to add a link to an existing pdf that jumps to a coordinate on another page. I am able to add a rectangle using this code: PdfContentByte overContent = stamper.GetOverContent(1); iTextSharp.text.Rectangle rectangle = new Rectangle(10,10,100,100,0); rectangle.BackgroundColor = BaseColor.BLUE; overContent.Rectangle(rectangle); stamper.Close(); How can I do similar to create a link that is clickable? Thanks. This is explained in chapter 7 of the book "iText in Action - Second Edition" . You can find an example here: http://itextpdf.com/examples/iia.php?id=150 If you need the C#

iTextSharp Image Extraction with Transparency

匆匆过客 提交于 2019-11-29 16:10:18
I am using iTextSharp and trying to extract images with transparency from a PDF. When I extract the image the transparency becomes solid black and is lost. I have found multiple examples of image extraction but all of them seem to have the same issue. The code that I am using is below Another example is from itextpdf.com/examples/iia.php?id=284. This example includes images in the "results" section at the top. If you click Img7.png you will see the black border in the image, however at the bottom of the page there is a link to the original image info.png that shows the transparency the way it

How do you underline text with dashedline in ITEXT PDF

与世无争的帅哥 提交于 2019-11-29 15:42:07
I have underlined "Some text" by var par = new Paragraph(); par.Add(new Chunk("Some text", CreateFont(12, Font.UNDERLINE))); document.Add(par); It is possible underline just "Some text" with dashed line (not the paragraph)? Thanks Chris Haas This answer tells you how to do it but unfortunately doesn't provide any code so I've provided it below. To the best on my knowledge there isn't a direct way to achieve this in iTextSharp by just setting a simple property. Instead, you need to use a PageEvent and manually draw the line yourself. First you need to subclass PdfPageEventHelper : private class

PdfWriter.GetInstance throws System.NullReferenceException

≯℡__Kan透↙ 提交于 2019-11-29 15:39:50
I'm trying to create a pdf document using iTextSharp 5.3.4 using the following Document document = new Document(); FileStream stm = new FileStream(filename, FileMode.Create); PdfWriter writer = PdfWriter.GetInstance(document, stm); I'm getting a System.NullReferenceException with the following stack trace: System.NullReferenceException occurred HResult=-2147467261 Message=La référence d'objet n'est pas définie à une instance d'un objet. Source=itextsharp StackTrace: à iTextSharp.text.Version.GetInstance() InnerException: I've verified that neither document nor stm are null, and if I select

Get text occurrences contained in a specified area with iTextSharp

…衆ロ難τιáo~ 提交于 2019-11-29 15:12:03
问题 Is it possible, using iTextSharp , get all text occurrences contained in a specified area of ​​a pdf document? Thanks. 回答1: First you need the actual coordinates of the rectangle you marked in Red. On sight, I'd say the x value 144 (2 inches) is probably about right, but it would surprise me if the y value is 76, so you'll have to double check. Once you have the exact coordinates of the rectangle, you can use iText's text extraction functionality using a LocationTextExtractionStrategy as is

iTextSharp is producing a corrupt PDF with Response

烂漫一生 提交于 2019-11-29 14:51:12
i tryed both, but still not working iTextSharp + FileStream = Corrupt PDF file iTextSharp is producing a corrupt PDF using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream()) { //abre o documento para poder editar document.Open(); //Adiciona os campos de assinatura document.Add(Assinatura()); //fecha o documento ao finalizar a edição document.Close(); //Prepara o download byte[] bytes = memoryStream.ToArray(); memoryStream.Close(); Response.Clear(); Response.ContentType = "image/pdf"; //Response.ContentType = "application/pdf"; Response.AddHeader("Content-Disposition",

Edit DirectContent of iTextSharp PdfSmartCopy class

风流意气都作罢 提交于 2019-11-29 14:42:42
At my work sometimes I have to merge from few to few hundreds pdf files. All the time I've been using Writer and ImportedPages classes. But when I have merged all files into one, file size becomes enormous, sum of all merged files sizes, because fonts being attached to every page, and not reused (fonts are embedded to every page, not whole document). Not very long time ago I found out about PdfSmartCopy class, which reuses embedded fonts and images. And here the problem kicks in. Very often, before merging files together, I have to add additional content to them (images, text). For this

How to get a list of the fields in an XFA form?

时光总嘲笑我的痴心妄想 提交于 2019-11-29 14:04:25
I am trying to get a simple list of all the fields in my XFA form. I am using this code: private void ListFieldNames() { string pdfTemplate = @"C:\Projects\iTextSharp\SReport.pdf"; MemoryStream m = new MemoryStream(); // title the form this.Text += " - " + pdfTemplate; // create a new PDF reader based on the PDF template document PdfReader pdfReader = new PdfReader(pdfTemplate); PdfStamper pdfStamper = new PdfStamper(pdfReader, m); AcroFields formFields = pdfStamper.AcroFields; AcroFields form = pdfReader.AcroFields; XfaForm xfa = form.Xfa; StringBuilder sb = new StringBuilder(); sb.Append(xfa

How do I Combine/Merge PDFs with Fillable Form Fields using iTextSharp?

ぃ、小莉子 提交于 2019-11-29 13:53:19
Using iTextSharp , how can I merge multiple PDFs into one PDF without losing the Form Fields and their properties in each individual PDF? (I would prefer an example using streams from a database but file system is ok as well) I found this code that works but it flattens out my PDFs so I can't use it. UPDATE @Mark Storer - This is the code I am using now based on your feedback (see below) but it gives me a corrupt document after the save. I tested each of the code parts separately and it seems to be failing in the MergePdfForms function shown below. I obviously don't want to use the