itextsharp

Adding Image watermark to Pdf while Creating it using iTextSharp

∥☆過路亽.° 提交于 2019-12-01 04:24:56
Wonder if this possible. Saw many posts on adding watermark after the pdf is created and saved in disk. But during creation of document how do i add a image watermark. I know how to add a image to document. But how do i position it such that it comes at the end of page. This is essentially identical to adding a header or footer. You need to create a class that implements PdfPageEvent , and in the OnPageEnd , grab the page's PdfContentByte, and draw your image there. Use an absolute position. Note: You probably want to derive from PdfPageEventHelper, it has empty implementations of all the page

Adding Image watermark to Pdf while Creating it using iTextSharp

怎甘沉沦 提交于 2019-12-01 03:17:43
问题 Wonder if this possible. Saw many posts on adding watermark after the pdf is created and saved in disk. But during creation of document how do i add a image watermark. I know how to add a image to document. But how do i position it such that it comes at the end of page. 回答1: This is essentially identical to adding a header or footer. You need to create a class that implements PdfPageEvent , and in the OnPageEnd , grab the page's PdfContentByte, and draw your image there. Use an absolute

Itextsharp set font for IElement

廉价感情. 提交于 2019-12-01 03:04:16
问题 var htmlarraylist = HTMLWorker.ParseToList(new StringReader(htmlText), styles); document.Open(); BaseFont Vn_Helvetica = BaseFont.CreateFont(@"C:\Windows\Fonts\arial.ttf", "Identity-H", BaseFont.EMBEDDED); Font fontNormal = new Font(Vn_Helvetica, 12, Font.NORMAL); foreach (var t in htmlarraylist) { document.Add((IElement)t); //how set FontNormal if element is Paragraph? } document.Close(); Can someone help me please 回答1: You can use a font in iTextSharp using FontFactory.RegisterDirectories()

How to set the cell width in itextsharp pdf creation

南楼画角 提交于 2019-12-01 02:49:30
How can I set cell width and height in itextsharp pdf cell ceration using c#. I just use cell.width = 200f; But it should display the error message. width can not be set. What should I do?.. Neha http://indaravind.blogspot.in/2009/02/itextsharp-table-column-width.html VB: Dim intTblWidth() As Integer = {12, 10, 26, 10} C#: int[] intTblWidth = { 12, 10, 26, 10 }; You don't set the width of a cell. you should set the width of the columns. And you can do that by applying them on the table object: float[] widths = new float[] { 1f, 2f }; table.SetWidths(widths); The answer from Neha is to set the

How do I remove link annotations from a PDF using iText?

拈花ヽ惹草 提交于 2019-12-01 01:27:47
Here i want to remove Annotation(Link, Text, ..) from PDF permanently using iTextSharp. Already i have tried AnnotationDictionary.Remove(PdfName.LINK); But that Link annotations exist in that PDF. Note: I want remove particular selected Annotations(Link, Text, ..), For Example i want remove Link Annotation with the URI as www.google.com, remaining Link Annotations i want to be retain as per exist. I got the answer for my question. Sample Code: //Get the current page PageDictionary = R.GetPageN(i); //Get all of the annotations for the current page Annots = PageDictionary.GetAsArray(PdfName

Replace multiple different images on one PDF template page with itext (itextsharp)

耗尽温柔 提交于 2019-12-01 00:23:54
We have an ASP.NET application that users use to generate certain reports. So far we had one PDF template that had one image on it, and we would just replace that image with our programatically generated one (graph). We have used code from this site for that:http://blog.rubypdf.com/2007/12/12/how-to-replace-images-in-a-pdf/ Problem now is that we have two different images on one PDF page, and the code from link above selects both images on one page and replaces them all at once with our generated image. Does anyone have any idea how to replace multiple different images on one page with itext?

itextsharp how to add a full line break

萝らか妹 提交于 2019-12-01 00:09:46
I use itextsharp and i need to draw a dotted linebreak from left to right of the page(100% width) but don't know how. The doc always has a margin left right. Please help var pageSize = PageSize.A4; if (_pdfSettings.LetterPageSizeEnabled) { pageSize = PageSize.LETTER; } var doc = new Document(pageSize); PdfWriter.GetInstance(doc, stream); doc.Open(); //fonts var titleFont = GetFont(); titleFont.SetStyle(Font.BOLD); titleFont.Color = BaseColor.BLACK; titleFont.Size = 16; var largeFont = GetFont(); largeFont.SetStyle(Font.BOLD); largeFont.Color = BaseColor.BLACK; largeFont.Size = 18; int ordCount

Set AcroField Text Size to Auto

ε祈祈猫儿з 提交于 2019-11-30 23:46:30
Using itextsharp , I'm attempting to set the font size of my form's text fields to auto . I'm currently doing something like this: Object d = 0.0; PdfReader reader = new PdfReader(path); byte [] pdf; using (var ms = new MemoryStream()) { PdfStamper stamper = new PdfStamper(reader, ms); AcroFields fields = stamper.AcroFields; foreach (var f in fields.Fields.Keys) { fields.SetFieldProperty(f, "textsize", d, null); } } But I'm getting the following error: System.InvalidCastException: Specified cast is not valid. at iTextSharp.text.pdf.AcroFields.SetFieldProperty(String field, String name, Object

iTextSharp - Crop PDF File (C#)

两盒软妹~` 提交于 2019-11-30 23:45:09
I want to crop PDF File using iTextSharp and rectangle (0,1000,600,155). Everything is fine and when you open created *.pdf file you can see only that cropped content, BUT! If you parse that pdf, there are still information and text from not visible part of document, I can't accept that. How can I remove that data completly? Here is my code sample: static void cropiTxtSharp(){ string file ="C:\\testpdf.pdf"; string oldchar = "testpdf.pdf"; string repChar = "test.pdf"; PdfReader reader = new PdfReader(file); PdfDictionary pageDict; PdfRectangle rect = new PdfRectangle(0, 1000, 600, 115);

iTextSharp: table in landscape

微笑、不失礼 提交于 2019-11-30 23:25:09
I'm using iTextSharp to generate a large document. In this document I want some specific pages in landscape. All the rest is portrait. Does anyone know how I can do this? Starting a new document is not an option. Thanks! You can set the document size and it will affect the next pages. Some snippets: Set up your document somewhere (you know that already): var document = new Document(); PdfWriter pdfWriter = PdfWriter.GetInstance( document, new FileStream(destinationFile, FileMode.Create) ); pdfWriter.SetFullCompression(); pdfWriter.StrictImageSequence = true; pdfWriter.SetLinearPageMode(); Now