itextsharp

Problem with PdfTextExtractor in itext!

白昼怎懂夜的黑 提交于 2019-12-06 05:20:33
first excuse me for my bad english! I want to search in pdf document for a word like "Hello" . So I must read each page in pdf by PdfTextExtractor. I did it well. I can read all words in each page separately an save it in string buffer. but when i push this code in For loop ,(for example from page 1 to 7 for search in it) earlier page's words will remain in string buffer.I hop you understand my problem. Tanx all. this is my code : PdfReader reader2 = new PdfReader(openFileDialog1.FileName); int pagen = reader2.NumberOfPages; reader2.Close(); ITextExtractionStrategy its = new iTextSharp.text

Add image watermark over another image in pdf c#

时光毁灭记忆、已成空白 提交于 2019-12-06 04:59:11
问题 All, I am trying to add image watermark in pdf using itextsharp. Watermark is appearing on all the pages as expected but with ones that already have image. I want my watermarking image to come on top of the existing image on the pdf. I am using following code to add image using (Stream output = new FileStream(outputFile, FileMode.Create, FileAccess.Write, FileShare.None)) { using (PdfStamper pdfStamper = new PdfStamper(pdfReader, output)) { for (int pageIndex = 1; pageIndex <= pdfReader

Signing PDF with a certificate in a certificate store

馋奶兔 提交于 2019-12-06 03:55:57
I want to sign a PDF with a certificate in a certificate store. I am using iTextSharp and iSafePDF for singing PDFs, it works OK when I sign using a certificate stored as .p12 file. But I don't know how to use the library for signing with certificates obtained from a certificate store. I have an instance of System.Security.Cryptography.X509Certificate2, but the library uses a different object representation and I was not able to make it work. Can someone help? OK, here is exactly what I was trying to find, the accompanying text is in Czech, but there is not much of it and the code that works

Create local link in rotated PdfPCell in iTextSharp

淺唱寂寞╮ 提交于 2019-12-06 03:51:39
I'm trying to put a link to another page in my pdf using iTextSharp. link in rotated cell is not working. other cells work as expected: FileStream fs = new FileStream("TestPDF.pdf", FileMode.Create, FileAccess.Write, FileShare.None); Document doc = new Document(); PdfWriter writer = PdfWriter.GetInstance(doc, fs); doc.Open(); PdfPTable linkTable = new PdfPTable(2); PdfPCell linkCell = new PdfPCell(); linkCell.HorizontalAlignment = Element.ALIGN_CENTER; linkCell.Rotation = 90; linkCell.FixedHeight = 70; Anchor linkAnchor = new Anchor("Click here"); linkAnchor.Reference = "#target"; Paragraph

How do I insert a table into a PDF document with iTextSharp?

旧街凉风 提交于 2019-12-06 02:37:00
I want to insert a table into my existing PDF document. I was following a post about inserting an image into a PDF but I'm getting an null reference exception error when trying to add the table. Here is my current code public static byte[] InsertTable(byte[] pdf, DataTable dt, int pageNum, int x, int y, int columns, int rows, int[] columnWidths, float rowHeight) { using (var inputPDF = new MemoryStream(pdf)) using (var outputPDF = new MemoryStream()) { var reader = new PdfReader(inputPDF); var stamper = new PdfStamper(reader, outputPDF); var pdfContentByte = stamper.GetOverContent(pageNum);

What is the common way to check the check box field in a pdf using iTextsharp?

若如初见. 提交于 2019-12-06 00:22:38
问题 I am filling the data for a fillable pdf using iTextsharp. There are n number of checkboxes in the pdf form. I have set the value for the check boxes using "Yes" or "No". This works fine. But some of the check boxes does not work in this way; instead i need to use 1 or 0 to make it work. So can anyone help me what is the common way to check/uncheck the checkboxes in pdf using iTextSharp? Thanks in Advance, Snowwhite 回答1: Open chosen PDF and convert it. PdfReader reader = new PdfReader

BadPasswordException when filling out pdf with iTextSharp

末鹿安然 提交于 2019-12-06 00:04:29
问题 I have a third-party PDF file with some form fields, that I need to fill out programmatically. PDF file is secured. Detailed security settings: SecurityMethod: Password Security, Document Open Password: No, ... Form Field Fill-in or Signing: Allowed... When I'm trying to open and fill out the document manually, everything is ok, and I'm not asked for any password. But with the code, it fails with exception. Here's the code (I'm using iTextSharp library): var str = new MemoryStream(); var

Tables with rounded corners

℡╲_俬逩灬. 提交于 2019-12-05 23:31:39
问题 I was wondering what would be the best approach for creating tables in a pdf that have rounded corners using the iTextSharp 5.x+ library. 回答1: If you have iTextSharp source code, add the following to PdfContentByte class: /// <summary> /// Enumuration for defining corners you want rounded. /// </summary> [Flags()] public enum Corners {None = 0,All=15,Top=3,Bottom=12, TopLeft = 1, TopRight=2, BottomLeft=4, BottomRight=8}; /// <summary> /// Adds a round rectangle to the current path, with

iTextSharp does not render Custom urdu font

大兔子大兔子 提交于 2019-12-05 23:24:48
I am using custom Urdu Font Jameel Noori Nastaleeq with iTextSharp but it is not showing text at all. It shows text when I use built-in forms like times.ttf etc. Code is given below: private void button1_Click(object sender, EventArgs e) { Document document = new Document(); try { PdfWriter writer = PdfWriter.GetInstance(document, new System.IO.FileStream("C:\\iTextSharpHelloworld.pdf", System.IO.FileMode.Create)); document.Open(); string fontpath = Environment.GetEnvironmentVariable("SystemRoot") + "\\fonts\\Jameel Noori Nastaleeq.ttf"; //string fontpath = Environment.GetEnvironmentVariable(

ItextSharp - AutoFill a pdf form using C# - Issues with Checkboxes

你离开我真会死。 提交于 2019-12-05 21:21:50
问题 I am in the process of filling in a pdf form created using Acrobat pro with iTextSharp & C#, and have found myself stuck when attempting to tick a checkbox field. I have it working for radio buttons and textboxes but cannot seem to get the checkbox working. I have also confirmed the checkbox name in this case "Q7b" is correct in the acrobat document and can find it on the form using the following code private string getfieldnames(AcroFields fields) { StringBuilder sb = new StringBuilder();