itextsharp

Set Metadata in iTextSharp

你说的曾经没有我的故事 提交于 2019-11-29 07:15:13
I am developing an application and i use the iTextSharp library. I am also reading the iText in action from Manning so i can get references. In Chapter 12 it has the following code to change the metadata in Java. PdfReader reader = new PdfReader(src); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest)); HashMap<String, String> info = reader.getInfo(); info.put("Title", "Hello World stamped"); info.put("Subject", "Hello World with changed metadata"); info.put("Keywords", "iText in Action, PdfStamper"); info.put("Creator", "Silly standalone example"); info.put("Author", "Also

itextsharp: how do i add a new page and write to it?

不打扰是莪最后的温柔 提交于 2019-11-29 07:09:25
in vb.net i filled up the first page of a pdf document, how do i start from the second page? Document document = new Document(PageSize.A4, 0, 0, 50, 50); System.IO.MemoryStream msReport = new System.IO.MemoryStream(); try { // creation of the different writers PdfWriter writer = PdfWriter.GetInstance(document, msReport); // we add some meta information to the document document.AddTitle("My Title"); document.AddAuthor("Me"); document.Open(); for (int i = 1; i <= 5; i++) { document.NewPage(); iTextSharp.text.Table datatable = new iTextSharp.text.Table(3); datatable.Padding = 2; datatable.Spacing

itextsharp trimming pdf document's pages

断了今生、忘了曾经 提交于 2019-11-29 06:38:06
I have a pdf document that has form fields that I'm filling out programatically with c#. Depending on three conditions, I need to trim (delete) some of the pages from that document. Is that possible to do? for condition 1: I need to keep pages 1-4 but delete pages 5 and 6 for condition 2: I need to keep pages 1-4 but delete 5 and keep 6 for condition 3: I need to keep pages 1-5 but delete 6 Instead of deleting pages in a document what you actually do is create a new document and only import the pages that you want to keep. Below is a full working WinForms app that does that (targetting

Hiding table border in iTextSharp

一笑奈何 提交于 2019-11-29 05:59:04
问题 How can i hide the table border using iTextSharp. I am using following code to generate a file: var document = new Document(PageSize.A4, 50, 50, 25, 25); // Create a new PdfWriter object, specifying the output stream var output = new MemoryStream(); var writer = PdfWriter.GetInstance(document, output); document.Open(); PdfPTable table = new PdfPTable(3); var bodyFont = FontFactory.GetFont("Arial", 10, Font.NORMAL); PdfPCell cell = new PdfPCell(new Phrase("Header spanning 3 columns")); cell

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

社会主义新天地 提交于 2019-11-29 04:35:41
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 PdfReader(filePath); using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite,

How to calculate the correct image size in out pdf using itextsharp?

混江龙づ霸主 提交于 2019-11-29 03:52:58
I' am trying to add an image to a pdf using itextsharp, regardless of the image size it always appears to be mapped to a different greater size inside the pdf ? The image I add is 624x500 pixel (DPI:72): alt text http://www.freeimagehosting.net/uploads/727711dc70.png And here is a screen of the output pdf: alt text http://www.freeimagehosting.net/uploads/313d49044d.png And here is how I created the document: Document document = new Document(); System.IO.MemoryStream stream = new MemoryStream(); PdfWriter writer = PdfWriter.GetInstance(document, stream); document.Open(); System.Drawing.Image

Using Fonts in System with iTextSharp

会有一股神秘感。 提交于 2019-11-29 03:48:25
I want to use iTextSharp to write some text. I'm using this method: var font = BaseFont.CreateFont(BaseFont.TIMES_BOLD, BaseFont.WINANSI, BaseFont.EMBEDDED); My question is: does iTextSharp support all fonts in the system fonts directory? Say I have a font called 'mycoolfont' selected by the user in the font chooser dialog. Can I create a new iTextSharp font like this? var font = BaseFont.CreateFont("mycoolfont", BaseFont.WINANSI, BaseFont.EMBEDDED); overContent.SetFontAndSize(font, fontSize); UPDATE: I tried var font = BaseFont.CreateFont("Verdana", BaseFont.WINANSI, BaseFont.EMBEDDED); but

Split PDF into multiple PDFs using iTextsharp

徘徊边缘 提交于 2019-11-29 03:33:40
public int SplitAndSave(string inputPath, string outputPath) { FileInfo file = new FileInfo(inputPath); string name = file.Name.Substring(0, file.Name.LastIndexOf(".")); using (PdfReader reader = new PdfReader(inputPath)) { for (int pagenumber = 1; pagenumber <= reader.NumberOfPages; pagenumber++) { string filename = pagenumber.ToString() + ".pdf"; Document document = new Document(); PdfCopy copy = new PdfCopy(document, new FileStream(outputPath + "\\" + filename, FileMode.Create)); document.Open(); copy.AddPage(copy.GetImportedPage(reader, pagenumber)); document.Close(); } return reader

itextsharp: what is the height of a regular PDF page in pixels?

淺唱寂寞╮ 提交于 2019-11-29 02:30:36
问题 What is the height of a regular PDF page in pixels? I heard it was something like this: Dim pgSize As New iTextSharp.text.Rectangle(595, 792) but I am adding an image that takes up maybe half the height, and even though pgSize looks like a full page and the image takes up only half of it, I am getting a height of like 619 for the image? I do not know if it is in the same units? 回答1: Your page size depends on what you set it when you create the document, probably using the PageSize object (eg.

creating a pdf from a template in itextsharp and outputting as content disposition.

ⅰ亾dé卋堺 提交于 2019-11-29 02:17:06
I would like to open an existing pdf, add some text and then output as content disposition using itext sharp. I have the following code. Where it falls down it is that i want to output as memory stream but need to filestream to open the original file. Here's what i have. Obviously defining PdfWriter twice won't work. public static void Create(string path) { var Response = HttpContext.Current.Response; Response.Clear(); Response.ContentType = "application/pdf"; System.IO.MemoryStream m = new System.IO.MemoryStream(); Document document = new Document(); PdfWriter wri = PdfWriter.GetInstance