itextsharp

opening PDF document from memory

不问归期 提交于 2019-12-05 12:09:28
It is possible to create a PDF document in memory with iTextSharp that gives the user a choice to "open" or "save"?, and if it opens then it opens in a browser window. At the moment the only I have save it to disk. EDIT: ok I've got it sussed. I did end up having to write the file to a folder, but it is only temporary as gets overwritten every time. Here is the solution for what it's worth: private void GeneratePDF() { var doc1 = new Document(); string path = Server.MapPath("~/pdfs/"); string filepath = path + "Doc1.pdf"; PdfWriter.GetInstance(doc1, new FileStream(filepath, FileMode.Create));

Using itextsharp to split a pdf into smaller pdf's based on size

放肆的年华 提交于 2019-12-05 11:49:30
So we have some really inefficient code that splits a pdf into smaller chunks based on a maximum size allowed. Aka. if the max size is 10megs, an 8 meg file would be skipped, while a 16 meg file would be split based on the number of pages. This is code that I inherited and feel like there has got to be a more efficient way to do this that requiring only one method and less instantiation of objects. We use the following code to call the methods: List<int> splitPoints = null; List<byte[]> documents = null; splitPoints = this.GetPDFSplitPoints(currentDocument, maxSize); documents = this.SplitPDF

Unable to use iTextSharp with ASP.NET 5 Core

人盡茶涼 提交于 2019-12-05 11:15:57
I'm trying to use iTextSharp with ASP.NET 5 Core. However I get these errors when I'm trying to build the ASP.NET application with iTextSharp 5.5.5 Code: using Microsoft.AspNet.Mvc; using System.IO; using System; using iTextSharp; using iTextSharp.text; using iTextSharp.text.pdf; // For more information on enabling MVC for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860 namespace MyNamespace { public class GenerateFileController : Controller { // GET: /<controller>/ public string Index() { PdfReader reader = new PdfReader("template.pdf"); return "SomeText"; } } } Errors:

iTextSharp ShowTextAligned Anchor Point

孤街浪徒 提交于 2019-12-05 09:30:55
I'm currently successfully adding text to a PDF using iTextSharp's ShowTextAligned method. The method looks like this (C#): public void ShowTextAligned( int alignment, string text, float x, float y, float rotation ) However, it is unclear where the anchor point is for the text we're making. We provide x and y , but does these correspond to the upper left corner of the text rectangle, the lower left corner, or something else? Also is this impacted by line spacing? I looked at the documentation at this website , but it isn't very explanatory. See PdfContentByte Class / PdfContentByte Methods /

How can I add two rows in a single pdf cell?

…衆ロ難τιáo~ 提交于 2019-12-05 09:03:21
I am generatng barcode. Now I want to insert the student code under the barcode label. How can I do this?My code is foreach (GridViewRow row in grdBarcode.Rows) { DataList dl = (DataList)row.FindControl("datalistBarcode"); PdfContentByte cb = new PdfContentByte(writer); PdfPTable BarCodeTable = new PdfPTable(6); BarCodeTable.SetTotalWidth(new float[] { 100,10,100,10,100,10 }); BarCodeTable.DefaultCell.Border = PdfPCell.NO_BORDER; Barcode128 code128 = new Barcode128(); code128.CodeType = Barcode.CODE128_UCC; foreach (DataListItem dli in dl.Items) { String barcodename= ((Label)dli.FindControl(

how to implement smallcaps in itextsharp

不想你离开。 提交于 2019-12-05 06:49:07
问题 In one PDf i got small caps text the font size is 0.0. i have extracted font using:------ iTextSharp.text.Rectangle rect = new iTextSharp.text.Rectangle(curBaseline[Vector.I1], curBaseline[Vector.I2], topRight[Vector.I1], topRight[Vector.I2]); Single curFontSize = rect.Height; int this code curfontsize i got 0.0. but i was able to extract font family.but not able to extract fontsize. so the text was not displaying.can anyone provide solution for this . Is there anyother method.? thankyou 回答1:

Reorder pages in a pdf file using itextsharp

我的未来我决定 提交于 2019-12-05 06:16:26
问题 I'm trying to reorder several pages in a PDF file. I found some code in a blog but couldn't get it to work. I have a two page pdf, and I want to get the last page to appear as first. I always get an exception saying that page number has to match with order. When I checked the document object, it shows 0 pages. But the PDF passed into has two pages. public void reOrder(string inputFile) { Document document = new Document(); FileStream fs = new FileStream(inputFile, FileMode.Open); PdfWriter

How to Merge two memory streams containing PDF file's data into one

核能气质少年 提交于 2019-12-05 05:56:13
I am trying to read two PDF files into two memory streams and then return a stream that will have both stream's data. But I don't seem to understand what's wrong with my code. Sample Code: string file1Path = "Sampl1.pdf"; string file2Path = "Sample2.pdf"; MemoryStream stream1 = new MemoryStream(File.ReadAllBytes(file1Path)); MemoryStream stream2 = new MemoryStream(File.ReadAllBytes(file2Path)); stream1.Position = 0; stream1.Copyto(stream2); return stream2; /*supposed to be containing data of both stream1 and stream2 but contains data of stream1 only*/ ArslanIqbal It appears in case of PDF

How do I add a border to a page using iTextSharp?

我只是一个虾纸丫 提交于 2019-12-05 05:26:07
Is it possible to add a border to a page in a PDF document using iTextSharp ? I'm generating the PDF file from scratch, so I don't need to add borders to an already existing document. Here's my code for example: Document pdfDocument = new Document(PageSize.LETTER); Font headerFont = new Font(baseFont, 13); Font font = new Font(baseFont, 10); PdfWriter writer = PdfWriter.GetInstance(pdfDocument, new FileStream(fileName, FileMode.Create)); pdfDocument.Open(); //I add IElements here. pdfDocument.Close(); Here is an answer (adapted from Mark Storer) in C#. This example uses the margins of the page

Centering an pdfimportedpage in iTextSharp

假装没事ソ 提交于 2019-12-05 05:12:33
问题 I am appending PDFs together using the function below via iTextSharp. Its working fine. The only problem is that PDFs that are larger than the set size of the document (A4), ends up being scaled and placed at the bottom left corner of the document. I would like to centre it. Can anyone point me in the right direction to achieving this? Cheers. private void appendPDF(appendDoc doc) { PdfContentByte pdfContentByte = pdfWriter.DirectContent; PdfReader pdfReader = null; if (doc.MemoryStream !=