itextsharp

itext ColumnText ignores alignment

天涯浪子 提交于 2019-11-26 22:02:04
问题 I'm trying to get some rows of text on the left side and some on the right side. For some reason iText seems to ignore the alignment entirely. Example: // create 200x100 column ct = new ColumnText(writer.DirectContent); ct.SetSimpleColumn(0, 0, 200, 100); ct.AddElement(new Paragraph("entry1")); ct.AddElement(new Paragraph("entry2")); ct.AddElement(new Paragraph("entry3")); ret = ct.Go(); ct.SetSimpleColumn(0, 0, 200, 100); ct.Alignment = Element.ALIGN_RIGHT; ct.AddElement(new Paragraph(

C# iTextSharp multi fonts in a single cell

ⅰ亾dé卋堺 提交于 2019-11-26 21:53:45
问题 First off I'm not that great with C# and it's been a while since I've worked with it.. I'm making a windows form for a friend that delivers packages. So I want to transfer his current paper form, into a .pdf with the library iTextSharp. He still needs to print the form to get the customer signature and so on. What I need: I want the table to have a little headline, "Company name" for example, the text should be a little smaller than the text input from the windows form(richTextBox1) Currently

Use External Css to parse XML

自闭症网瘾萝莉.ら 提交于 2019-11-26 21:39:43
问题 OK i am parsing HTML from a string into a PDFCEll. It works great thanks to some help from here. Here is how i am doing it. How do i use an external css file so i can use class's and not STYLE="" public class XhtmlToListHelper : IElementHandler { // Generic list of elements public List<IElement> elements = new List<IElement>(); // Add the item to the list public void Add(IWritable w) { if (w is WritableElement) { elements.AddRange(((WritableElement)w).Elements()); } } string html = "<ul class

iTextSharp - Sending in-memory pdf in an email attachment

不想你离开。 提交于 2019-11-26 21:38:08
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 attachment is sent but with 0 bytes MailMessage mm = new MailMessage("username@gmail.com", "username@gmail.com") {

Itextsharp: Adjust 2 elements on exactly one page

自作多情 提交于 2019-11-26 21:07:48
So, I'm having this problem using C# (.NET 4.0 + WinForms) and iTextSharp 5.1.2. I have some scanned images stored on a DB and need to build on the fly PDF with those images. Some files have just one page and other ones hundreds. That is working just fine using: foreach (var page in pages) { Image pageImage = Image.GetInstance(page.Image); pageImage.ScaleToFit(document.PageSize.Width,document.PageSize.Height); pageImage.Alignment = Image.ALIGN_TOP | Image.ALIGN_CENTER; document.Add(pageImage); document.NewPage(); //... } The problem is: I need to add an small table at the bottom of the last

Retrieve the respective coordinates of all words on the page with itextsharp

流过昼夜 提交于 2019-11-26 21:06:56
my aim is to retrieve the respective coordinates of all words on the page,what i have done is PdfReader reader = new PdfReader("cde.pdf"); TextWithPositionExtractionStategy S = new TextWithPositionExtractionStategy(); PdfTextExtractor.GetTextFromPage(reader,1,S); Vector curBaseline = renderInfo.GetDescentLine().GetStartPoint(); Vector topRight = renderInfo.GetAscentLine().GetEndPoint(); iTextSharp.text.Rectangle rect = new iTextSharp.text.Rectangle(curBaseline[Vector.I1], curBaseline[Vector.I2], topRight[Vector.I1], topRight[Vector.I2]); string x1 = curBaseline[Vector.I1].ToString(); string x2

Removing Watermark from PDF iTextSharp

痴心易碎 提交于 2019-11-26 21:02:29
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 changes the opacity value of the watermark to 0 and therefore it disappears. private static void

Checking off pdf checkbox with itextsharp

半城伤御伤魂 提交于 2019-11-26 20:48:44
I've tried so many different ways, but I can't get the check box to be checked! Here's what I've tried: var reader = new iTextSharp.text.pdf.PdfReader(originalFormLocation); using (var stamper = new iTextSharp.text.pdf.PdfStamper(reader,ms)) { var formFields = stamper.AcroFields; formFields.SetField("IsNo", "1"); formFields.SetField("IsNo", "true"); formFields.SetField("IsNo", "On"); } None of them work. Any ideas? You shouldn't "guess" for the possible values. You need to use a value that is stored in the PDF. Try the CheckBoxValues example to find these possible values: public String

iTextSharp + FileStream = Corrupt PDF file

你离开我真会死。 提交于 2019-11-26 20:44:09
问题 I am trying to create a pdf file with iTextSharp. My attempt writes the content of the pdf to a MemoryStream so I can write the result both into file and a database BLOB. The file gets created, has a size of about 21kB and it looks like a pdf when opend with Notepad++. But my PDF viewer says it's currupted. Here is a little code snippet (only tries to write to a file, not to a database): Document myDocument = new Document(); MemoryStream myMemoryStream = new MemoryStream(); PdfWriter

How to Add Page number in Footer in PDF by Itextsharp

為{幸葍}努か 提交于 2019-11-26 20:41:12
问题 I am using iTextSharp DLL in ASP.NET code. I am fetching a data into dataset and Add the dataset into PDF table. If my dataset have more 100 rows then 100 rows will be added into PDF table and 3 or 4 page will be created in PDF file. How can I add the footer in each page? 回答1: You need to inherit from PdfPageEventHelper class and override the methods shown in the code snippet below: Document doc = new Document(PageSize.A4.Rotate()); using (MemoryStream ms = new MemoryStream()) { PdfWriter