itextsharp

Merging PDFs with ITextSharp

冷暖自知 提交于 2019-11-26 20:37:02
问题 What is the optimum way to merge 2 PDF files with ITextSharp in C#? I'm using ASP.NET/.NET3.5. 回答1: public static void Merge(List<String> InFiles, String OutFile) { using (FileStream stream = new FileStream(OutFile, FileMode.Create)) using (Document doc = new Document()) using (PdfCopy pdf = new PdfCopy(doc, stream)) { doc.Open(); PdfReader reader = null; PdfImportedPage page = null; //fixed typo InFiles.ForEach(file => { reader = new PdfReader(file); for (int i = 0; i < reader.NumberOfPages;

Extract text and text rectangle coordinates from a Pdf file using itextsharp

断了今生、忘了曾经 提交于 2019-11-26 20:29:16
问题 I'm trying to get all words and their location coordinates from a PDF file. I've succeeded using the Acrobat API on .NET . Now, I'm trying to get the same result using a free API, such as iTextSharp (the .NET version). I can get the text (line by line) with PRTokeniser , but I have no idea of how to get the coordinates of the line, let alone of each word. 回答1: My account is too new reply to Mark Storer's answer. I wasn't able to directly use the LocationTextExtracationStrategy (I think I must

Create PDF in memory instead of physical file

时光总嘲笑我的痴心妄想 提交于 2019-11-26 20:06:51
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 Paragraph paragraph = new Paragraph("This is my first line using Paragraph."); Phrase pharse = new Phrase("This

Add Header and Footer for PDF using iTextsharp

ぐ巨炮叔叔 提交于 2019-11-26 20:03:04
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("content-disposition", "attachment;filename=Locations.pdf"); Response.Cache.SetCacheability(HttpCacheability

Right aligning text in PdfPCell

和自甴很熟 提交于 2019-11-26 19:06:18
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.AddCell(new Phrase("Item Name", tableHeadFont)); table.AddCell(new Phrase("Price", tableHeadFont));

itextsharp: How to generate a report with dynamic header in PDF using itextsharp?

徘徊边缘 提交于 2019-11-26 18:39:52
问题 I'm generating a PDF report with itextsharp, the header of the report has the information of the Customer, In the body of the report contains a list of customer transactions. My doubt is: How to generate a header dynamically for each client? I need an example to generate a header dynamically to the report. Every new page Header need to have the data that client when changing client header should contain information on the new client. 回答1: Your question risks down-voting or at least comments

PDF Reading highlighed text (highlight annotations) using C#

北城余情 提交于 2019-11-26 18:24:55
问题 I have written an extraction tool using iTextSharp that extracts annotation information from PDF documents. For the highlight annotation, I only get a rectangle for the area on the page which is highlighted. I am aiming for extracting the text that has been highlighted. For that I use `PdfTextExtractor'. Rectangle rect = new Rectangle( pdfArray.GetAsNumber(0).FloatValue, pdfArray.GetAsNumber(1).FloatValue, pdfArray.GetAsNumber(2).FloatValue, pdfArray.GetAsNumber(3).FloatValue); RenderFilter[]

Changing text line spacing

我怕爱的太早我们不能终老 提交于 2019-11-26 18:22:53
问题 I'm creating a PDF document consisting of text only, where all the text is the same point size and font family but each character could potentially be a different color. Everything seems to work fine using the code snippet below, but the default space between the lines is slightly greater than I consider ideal. Is there a way to control this? (FYI, type "ColoredText" in the code below merely contains a string and its color. Also, the reason I am treating the newline character separately is

iTextSharp-generated PDFs now cause Save dialog in Adobe Reader X

杀马特。学长 韩版系。学妹 提交于 2019-11-26 17:58:42
I have been using iTextSharp to generate PDF documents for over a year. Unfortunately, with the release of Adobe Reader X, my PDFs now cause a "Do you want to Save?" dialog to appear when closing the PDF document. This does not happen with PDFs that are not generated with iTextSharp. It's really annoying for my users who are opening and closing PDF documents all day long. Are there any properties in iTextSharp that I can set to prevent this from happening? If it helps, I am using a PdfReader to read data from an existing PDF document (this original document does not cause the Save dialog to

Set different parts of a form field to have different fonts using iTextSharp

社会主义新天地 提交于 2019-11-26 17:49:44
问题 I'm not sure that this is possible but I figured it would be worth asking. I have figured out how to set the font of a formfield using the pdfstamper and acrofields methods but I would really like to be able to set the font of different parts of the text in the same field. Here's how I'm setting the font of the form fields currently: // Use iTextSharp PDF Reader, to get the fields and send to the //Stamper to set the fields in the document PdfReader pdfReader = new PdfReader(fileName); //