itextsharp

iTextSharp - Create new document as Byte[]

两盒软妹~` 提交于 2019-11-30 09:40:07
问题 Have a little method which goes to the database and retrieves a pdf document from a varbinary column and then adds data to it. I would like to add code so that if this document (company stationery ) is not found then a new blank document is created and returned. The method could either return a Byte[] or a Stream. Problem is that the variable "bytes" in the else clause is null. Any ideas what's wrong? private Byte[] GetBasePDF(Int32 AttachmentID) { Byte[] bytes = null; DataTable dt =

Display ASP.NET generated pdf byte[] to web page without saving the file

…衆ロ難τιáo~ 提交于 2019-11-30 09:21:22
I'm using iTextSharp for generating a pdf. I can save the PDF file from the PDF byte[]. byte[] outputPDF = cnt.CreateBreakPDF(); File.WriteAllBytes(pdfOutPutPath, outputPDF); What is the best way to display the output byte[] to a web page? I want to show the PDF inside a div in my page. Not the PDF as a full response. I've seen answers for MVC, but I'm using ASP.NET Web Application. Is there a better way than using HTTP handlers to do so? I don't want to send all the details for creating PDF as query string. I tried this in jsFiddle , and it works well in Chrome & FF, need to check on other

problem in drawing a line in a pdf file using itextsharp

爱⌒轻易说出口 提交于 2019-11-30 08:51:21
I am generating a pdf file in asp.net c# using itextsharp. i am not able to draw a horizontal line/verticle line/dotted line. i tried to draw a line using the following code,i am getting no errors but the line is also not getting displayed in the pdf file PdfContentByte cb = wri.DirectContent; cb.SetLineWidth(2.0f); // Make a bit thicker than 1.0 default cb.MoveTo(20, pdfDocument.Top - 40f); cb.LineTo(400, pdfDocument.Top - 40f); cb.Stroke(); What is the problem in the code.Is it because of the position of x y co-ordinates? I had used rough points to know approximate position in pdf,but the

iTextSharp Replace Text in existing PDF without loosing formation [duplicate]

不羁岁月 提交于 2019-11-30 08:33:44
问题 This question already has an answer here : Replace text in PDF file using iTextSharp(not AcroFields) [closed] (1 answer) Closed 2 years ago . I' ve been searching the Internet for 2 Weeks and found some interesting solutions for my Problem, but nothing seems to give me the answer. My goal is to do the folowing: I want to find a Text in a static PDF-File and replace this text with another text. I would like to keep the design of the content. Is it really that hard? I found a way but I lost the

iText – HTML to PDF - Image is not displayed in PDF

不打扰是莪最后的温柔 提交于 2019-11-30 08:15:18
I have a html page with text, image and I am parsing the HTML content to iText to generate the PDF. In the generated PDF,Included images are not getting displayed and , only the text is getting displayed. If I pass the absolute path like D:/Deiva/CRs/HTMLPage/article-101-horz.jpg then the image will get printed. But if I try to print the image from the server like http://localhost:8085/content/dam/article-101-h1.jpg or http://www.google.co.in/intl/en_ALL/images/logos/images_logo_lg.gif then it is not getting printed in the PDF. NOTE: I am using itextpdf-5.2.1.jar to generate the PDF. My HTML

How to read table from PDF using itextsharp?

女生的网名这么多〃 提交于 2019-11-30 07:39:47
问题 I am having an problem with reading a table from pdf file. It's a very simple pdf file with some text and a table. The tool i am using is itextsharp. I know there is no table concept in PDF. After some googling, someone said it might be possible to achieve that using itextsharp + custom ITextExtractionStrategy. But I have no idea how to start it. Can someone please give me some hints? or a small piece of sample code? Cheers 回答1: This code is for reading a table content. all the values are

Get text occurrences contained in a specified area with iTextSharp

你离开我真会死。 提交于 2019-11-30 07:34:22
Is it possible, using iTextSharp , get all text occurrences contained in a specified area of ​​a pdf document? Thanks. Bruno Lowagie 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 done in the ExtractPageContentArea example. For the iTextSharp version of this example, see the

Cannot access the file because it is being used by another process

冷暖自知 提交于 2019-11-30 07:31:59
问题 My web method creates a pdf file in my %temp% folder and that works. I then want to add some custom fields (meta) to that file using the code below. The class PdfStamper generates an IOException , whether I use its .Close() method or the using block just ends. The process that is still holding on to the file handle is the webdev web server itself (I'm debugging in VS2010 SP1). private string AddCustomMetaData(string guid, int companyID, string filePath) { try { PdfReader reader = new

checking if pdf is password protected using itextsharp

你离开我真会死。 提交于 2019-11-30 07:01:24
问题 I want to check if a pdf file is password protected or not to view. That is i want to know if the pdf file has user password or not. I found some help in some forum about it to use isencrypted function but it does not give correct answer. Is it possible to check if a pdf is password protected? 回答1: The problem with using the PdfReader.IsEncrypted method is that if you attempt to instantiate a PdfReader on a PDF that requires a password - and you don't supply that password - you'll get a

Add a page to PDF document using iTextSharp

我怕爱的太早我们不能终老 提交于 2019-11-30 07:00:23
I would like to add a page to an existing PDF document containing simple text. I have tried the following code that I found on the internet, but so far I haven't got it to work: PdfReader reader = new PdfReader("1.pdf"); Document document = new Document(reader.GetPageSize(1)); PdfCopy copier = new PdfCopy(doc, new FileStream("2.pdf", FileMode.Create)); for (int pageCounter = 1; pageCounter < reader.NumberOfPages + 1; pageCounter++) { //byte[] page = reader.GetPageContent(pageCounter); copier.AddPage(copier.GetImportedPage(reader, pageCounter)); } copier.NewPage(); copier.Add(new Paragraph(