itextsharp

Sign PDF with iTextSharp 5.3.3 and USB token

萝らか妹 提交于 2019-11-27 12:57:05
I'm new to iTextSharp (and StackOverFlow). I'm trying to sign a PDF in C# using external USB token. I try using the follow code I've digged from the internet. Org.BouncyCastle.X509.X509CertificateParser cp = new Org.BouncyCastle.X509.X509CertificateParser(); //Get Sertifiacte X509Certificate2 certClient = null; X509Store st = new X509Store(StoreName.My, StoreLocation.CurrentUser); st.Open(OpenFlags.MaxAllowed); X509Certificate2Collection collection = X509Certificate2UI.SelectFromCollection(st.Certificates, "Please choose certificate:", "", X509SelectionFlag.SingleSelection); if (collection

How to parse multiple HTML files into a single PDF?

删除回忆录丶 提交于 2019-11-27 09:46:39
I want to use iText to convert a series of html file to PDF. For instance: if have these files: page1.html page2.html page3.html ... Now I want to create a single PDF file, where page1.html is the first page, page2.html is the second page, and so on... I know how to convert a single HTML file to a PDF, but I don't know how to combine these different PDFs resulting from this operation into a single PDF. Before we start: I am not a C# developer, so I can not give you an example in C#. All the iText examples I write, are written in Java. Fortunately, iText and iTextSharp are always kept in sync.

Invalidpdfexception pdf header signature not found

安稳与你 提交于 2019-11-27 09:19:29
I have some code that reads pdf files. The code fails at the line : iTextSharp.text.pdf.PRTokeniser.CheckPdfHeader() at iTextSharp.text.pdf.PdfReader.ReadPdf() I know from other entries that this issue is coming from some invalid formatting in the pdf. However I'm not in a position to tell my users to redo their pdfs. Is there some other way around this issue, that can allow reading of the pdf despite this problem? If a file doesn't start with %PDF- then there's nothing to fix: the file isn't a PDF file. However, there may be another problem: maybe you're trying to access a file that has zero

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

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-27 09:18:57
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); // Initialize Stamper (ms is a MemoryStream object) PdfStamper pdfStamper = new PdfStamper(pdfReader, ms); //

How do I enumerate all the fields in a PDF file in ITextSharp

无人久伴 提交于 2019-11-27 09:16:57
Let's say I've loaded a PDF file using iTextSharp: PdfStamper p = GetDocument(); AcroFields af = ps.AcroFields; How do I get a list of all field names on the document from af ? AcroFields af = ps.AcroFields; foreach (var field in af.Fields) { Console.WriteLine("{0}, {1}", field.Key, field.Value); } Bhavin Shah PdfReader pdfReader = new PdfReader("c:\\ABC.pdf"); string TempFilename = Path.GetTempFileName(); AcroFields pdfFormFields = pdfReader.AcroFields; foreach (KeyValuePair<string, AcroFields.Item> kvp in pdfFormFields.Fields) { string fieldName = kvp.Key.ToString(); string fieldValue =

How to align two paragraphs to the left and right on the same line?

痴心易碎 提交于 2019-11-27 08:58:34
I want to display two pieces of content (it may a paragraph or text) to the left and right side on a single line. My output should be like Name:ABC date:2015-03-02 How can I do this? Bruno Lowagie Please take a look at the LeftRight example. It offers two different solutions for your problem: Solution 1: Use glue By glue, I mean a special Chunk that acts like a separator that separates two (or more) other Chunk objects: Chunk glue = new Chunk(new VerticalPositionMark()); Paragraph p = new Paragraph("Text to the left"); p.add(new Chunk(glue)); p.add("Text to the right"); document.add(p); This

iTextSharp generated PDF: How to send the pdf to the client and add a prompt?

谁说胖子不能爱 提交于 2019-11-27 08:58:33
I have generated a pdf using iTextSharp, when its created it saves automatically in the location provided in my code on the server not on the client side and of course without telling anything to the user. I need to send it to the client and I need to prompt a dialogue box to ask the user where he wants to save his pdf.. how can i do this please? this is my pdf code: using (MemoryStream myMemoryStream = new MemoryStream()) { Document document = new Document(); PdfWriter PDFWriter = PdfWriter.GetInstance(document, myMemoryStream); document.AddHeader("header1", "HEADER1"); document.Open(); //...

How do I make an iTextSharp signature appear on every page of a document?

六眼飞鱼酱① 提交于 2019-11-27 08:56:18
问题 when I sign a document the signature only appears on the first page. Is there anything I can do to make it appear on every page? This is the method I'm using right now to sign the PDF, hope it helps find a solution: public static PdfStamper SignHashedUser(string Target, SysX509.X509Certificate2 Certificate, string Reason, string Location, bool AddVisibleSign, PdfReader objReader, int pags) { X509CertificateParser objCP = new X509CertificateParser(); X509Certificate[] objChain = new

Saving Panel to PDF not working nor getting errors

半城伤御伤魂 提交于 2019-11-27 08:51:00
问题 I am trying to save a panel to pdf using ITextSharp . When I set a breakpoint and debug, the code stops on this line of code, however it does not give an error and just stops. if (IsPostBack) { Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", "attachment;filename=Quote.pdf"); Response.Cache.SetCacheability(HttpCacheability.NoCache); StringWriter sw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw); **Panel1.RenderControl(hw);** StringReader sr

How to set the page size to Envelope size with Landscape orientation?

佐手、 提交于 2019-11-27 08:49:02
问题 I have problem on creating .pdf file with the Page settings as Envelope ,landscape format. Here is my Code to convert the asp page into pdf in Itextsharp Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", "attachment;filename=Receipt.pdf"); Response.Cache.SetCacheability(HttpCacheability.NoCache); StringWriter sw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw); bind_Data(); this.Page.RenderControl(hw); StringReader sr = new StringReader(sw