itextsharp

How to find current (X, Y) position in iTextSharp?

[亡魂溺海] 提交于 2019-11-30 23:05:49
I need to create a PDF with several sections, and after each section need to add a line, but I don't know where to draw this line. I need to find the exact coordinates [x, y] where the next element in the document will be write. Like @Olaf said, use GetVerticalPosition to get the Y . The X is just the document's LeftMargin . Below is a full working WinForms app targeting iTextSharp 5.1.1.0 that hopefully does what you are looking for: using System; using System.Text; using System.Windows.Forms; using iTextSharp.text; using iTextSharp.text.pdf; using System.IO; namespace

iTextSharp PDF printing

≡放荡痞女 提交于 2019-11-30 23:05:16
I'm trying to create a method that will send a PDF file directly to my printer (causing the print dialog to appear). Below is the code I've been working on - most of it found in the forums here . It works fine if I use iTextSharp to create a new PDF document, but as soon as I try to inject some JavaScript into an existing file, I get an exception when calling the print() method saying Object doesn't support property or method 'print' <script type="text/javascript"> function load() { try { var x = document.getElementById("frame1"); x.print(); } catch (err) { } } </script> <body onload="load();"

iTextSharp - Add image to PDF from Datatable

戏子无情 提交于 2019-11-30 23:01:34
I try to create a PDF report from a datatable. One of the columns contents image. How can I extract the image from datatable and insert into PDF table? I'm using iTextShap version 5.4.2.0. Here is the code: public void Report(DataTable dt, string output) { Document doc = new Document(PageSize.LETTER, 50, 50, 80, 50); PdfWriter PDFWriter = PdfWriter.GetInstance(doc, new FileStream(output, FileMode.Create)); PDFWriter.ViewerPreferences = PdfWriter.PageModeUseOutlines; iTextSharp.text.Font hel8 = FontFactory.GetFont(BaseFont.HELVETICA, 8); doc.Open(); PdfPTable table = new PdfPTable(dt.Columns

How to set the cell width in itextsharp pdf creation

五迷三道 提交于 2019-11-30 22:38:05
问题 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?.. 回答1: 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 }; 回答2: 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

Merging Memory Streams to create a http PDF response in c#

拟墨画扇 提交于 2019-11-30 20:08:02
I am trying to merge 2 crystal reports into single pdf file and I'm using Itextsharp v5.1.1. But it says the document cannot be opened. It might be corrupted. There are no build errors. but the pdf is malformed and cant be opened. Here is the order I chose to accomplish this. Export the Crystal report to MemoryStream1 in pdf format Export the second report into MemoryStream2. Merge the Memory Streams Send the Streams to Http Output Response as PDF. Here is the Code for each step in the order. /// Get the Dataset from Stored Procedure for the CSSource Report dsCS = CSData.GetUSSourceXML(ds

iTextSharp - how to open/read/extract a file attachment?

荒凉一梦 提交于 2019-11-30 20:06:40
问题 I have some PDF's all with two attached files with static names. I would like to use iTextSharp to extract these files to a temp directory so that I can work with them further. I tried following the tutorial here but I ran into problems when the iTextSharp.text.pdf.PdfReader didn't have a getCatalog() method as shown in the bottom example. Any advice on how I can extract the attachments? Let's just say for ease that the PDF document is at "C:\test.pdf" and the two attachments are stored as

CSS styles not being applied to PDF with iTextSharp

只愿长相守 提交于 2019-11-30 19:39:56
I am attempting to convert a portion of my webpage to pdf using iTextSharp, and while the pdf generation is working correctly, none of the css styles are being applied. I've tried applying the styles one at a time, but that doesn't seem to work. This is what I've come up with so far: //Get the portion of the page to convert. StringBuilder sb = new StringBuilder(); print_div.RenderControl(new HtmlTextWriter(new StringWriter(sb))); string html = sb.ToString(); //Generate a random filename to use for the pdf Guid random_guid; random_guid = Guid.NewGuid(); string fileName = random_guid.ToString()

iTextSharp: table in landscape

匆匆过客 提交于 2019-11-30 18:05:11
问题 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! 回答1: 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)

iTextSharp - Crop PDF File (C#)

喜你入骨 提交于 2019-11-30 17:26:20
问题 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

iTextSharp PDF printing

╄→尐↘猪︶ㄣ 提交于 2019-11-30 17:22:17
问题 I'm trying to create a method that will send a PDF file directly to my printer (causing the print dialog to appear). Below is the code I've been working on - most of it found in the forums here. It works fine if I use iTextSharp to create a new PDF document, but as soon as I try to inject some JavaScript into an existing file, I get an exception when calling the print() method saying Object doesn't support property or method 'print' <script type="text/javascript"> function load() { try { var