itextsharp

PdfPTable as a header in iTextSharp

落爺英雄遲暮 提交于 2019-11-28 12:28:33
I need a table with about 12 cells to display as a header. The following code fails to do this. I am aware table2 does not have 12 cells. On the second page, only "testing" is displayed. What am I missing? Thanks in advance! Document document = new Document(); try { PdfWriter.GetInstance(document, new FileStream("TableTest.pdf", FileMode.Create)); document.Open(); PdfPTable table = new PdfPTable(1); table.WidthPercentage = 100; PdfPTable table2 = new PdfPTable(2); //logo PdfPCell cell2 = new PdfPCell(Image.GetInstance(@"C:\path\to\file.gif")); cell2.Colspan = 2; table2.AddCell(cell2); //title

dataGridView to pdf with itextsharp

久未见 提交于 2019-11-28 12:24:19
问题 I have a problem while trying to get values of specific columns in dataGridView and add them to the PdtPtable. But the values added in the table is repeated, for example row one is added twice.I tried to go through each row and in every row through each column. PdfPTable pdfTable= new PdfPTable(5); foreach(DataGridViewRow row in dataGridView1.Rows) { foreach (DataGridViewCell celli in row.Cells) { try { pdfTable.AddCell(celli.Value.ToString()); } catch { } } doc.Add(pdfTable); } 回答1: I have

How do I sign a PDF document using a certificate from the Windows Cert Store?

╄→гoц情女王★ 提交于 2019-11-28 12:18:11
I need to sign a PDF document using a certificate that exists in the Windows Certificate Store. I have been digging around all day trying to figure it out, and I am so close yet so far away . All that is missing is this: How do I get an IExternalSignature object to sign the PDF file with? Rahul Singla has written a beautiful example of how to sign a PDF document using the new iText 5.3.0 API - as long as you can access a .pfx file sitting around on your PC somewhere. There is a previous question on signing using a certificate from the Windows Cert Store, except it was using a version of the

itextSharp - html to pdf some turkish characters are missing

余生颓废 提交于 2019-11-28 11:49:00
When I am trying to generate PDF from HTML, some Turkish characters like ĞÜŞİÖÇ ğüşıöç are missing in PDF, I see a space in place of these characters but i want to print that character. My code is: public virtual void print pdf(string html, int id) { String htmlText = html.ToString(); Document document = new Document(); string filePath = HostingEnvironment.MapPath("~/Content/Pdf/"); PdfWriter.GetInstance(document, new FileStream(filePath + "\\pdf-"+id+".pdf", FileMode.Create)); document.Open(); iTextSharp.text.html.simpleparser.HTMLWorker hw = new iTextSharp.text.html.simpleparser.HTMLWorker

iTextSharp Can not Convert All HTML to PDF

百般思念 提交于 2019-11-28 11:48:39
问题 Using the sample codes from here I come up with these codes - var my_html = this.GetmyReportHtml(); var my_css = this.GetmyReportHtmlCss(); Byte[] bytes; using (var ms = new MemoryStream()) { using (var doc = new iTextSharp.text.Document(PageSize.LETTER)) { using (var writer = PdfWriter.GetInstance(doc, ms)) { doc.Open(); try { using (var msCss = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(my_css))) { using (var msHtml = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(my_html))) {

PDF Convert to Black And White PNGs

百般思念 提交于 2019-11-28 11:45:51
I'm trying to compress PDFs using iTextSharp. There are a lot of pages with color images stored as JPEGs (DCTDECODE)...so I'm converting them to black and white PNGs and replacing them in the document (the PNG is much smaller than a JPG for black and white format) I have the following methods: private static bool TryCompressPdfImages(PdfReader reader) { try { int n = reader.XrefSize; for (int i = 0; i < n; i++) { PdfObject obj = reader.GetPdfObject(i); if (obj == null || !obj.IsStream()) { continue; } var dict = (PdfDictionary)PdfReader.GetPdfObject(obj); var subType = (PdfName)PdfReader

iTextSharp Re-use Font Embedded In Acrofield

与世无争的帅哥 提交于 2019-11-28 11:36:16
There are tips in "iText In Action" that cover setting fonts, as well as the "FontFactory.RegisterDirectories" method (which is, as the book says...an expensive call). However, in my case, the font that I want to use for new fields is already embedded in the document (in an existing Acrofield). With no guarantee that the same font will exist on the user's machine (or on a web server)....is there a way that I can register that already-embedded font, so that I can re-use it for other objects? In the code below, Acrofield "TheFieldIWantTheFontFrom" has the font that I want to re-use for a field

Find location last object on PDF page using iTextSharp

蹲街弑〆低调 提交于 2019-11-28 11:32:52
问题 How can I find the location and the height of the last object on a PDF page? There is no footer. I'm wanting to stamp a template below the last item. Not in the footer but directly below the last line of text. The amount of text may vary so I need to calculate if there is enough room at the bottom of the page to insert my template. Thanks for any help, Aaron 回答1: To determine where text and (bitmap) images on a given page end, have a look at the iText in Action, 2nd edition example

Difference between iTextSharp 4.1.6 and 5.x versions

巧了我就是萌 提交于 2019-11-28 11:28:16
We are developing a Pdf parser to be used along with our system. The requirement is such that, we store all the information on any pdf documents and should be able to reproduce the document as such (with minimal changes from original document). We did some googling and found iTextSharp be the best mate for our purpose. We are developing our project using .net. You might have guessed as i mentioned in my title requiring comparisons for specific versions of iTextSharp (4.1.6 vs 5.x). We know that 4.1.6 is the last version of iTextSharp with the LGPL/MPL license . The 5.x versions are AGPL. We

ITextSharp PDFTemplate FormFlattening removes filled data

浪尽此生 提交于 2019-11-28 11:24:40
I am porting an existing app from Java to C#. The original app used the IText library to fill PDF form templates and save them as new PDF's. My C# code (example) below: string templateFilename = @"C:\Templates\test.pdf"; string outputFilename = @"C:\Output\demo.pdf"; using (var existingFileStream = new FileStream(templateFilename, FileMode.Open)) { using (var newFileStream = new FileStream(outputFilename, FileMode.Create)) { var pdfReader = new PdfReader(existingFileStream); var stamper = new PdfStamper(pdfReader, newFileStream); var form = stamper.AcroFields; var fieldKeys = form.Fields.Keys;