Tag: itextsharp

itextsharp将点数转换为cm

我正在使用iTextsharp – 一个java pdf lib – 动态生成pdfs。 据我所知,测量以点数表示。 我知道在哪里放置厘米的地方。 所以我需要转换:点 cm

ITextSharp解析带有图像的HTML:它正确解析但不会显示图像

我正在尝试使用库ITextSharp从html生成.pdf。 我能够创建pdf与html文本转换为pdf文本/段落 我的问题: pdf没有显示我的图像(我的img元素来自html)。 我的html中的所有img html元素都不会显示在pdf中? ITextSharp是否可以解析HTML和显示图像。 我真的希望如此,否则我被塞满了:( 我链接到图像所在的正确目录(使用IMG_BASURL),但它们只是没有显示 我的代码: // mainContents variable is a string containing my HTML var document = new Document(PageSize.A4, 50, 50, 80, 100); var output = new MemoryStream(); var writer = PdfWriter.GetInstance(document, output); document.open(); Hashtable providers = new Hashtable(); providers.Add(“img_baseurl”,”C:/users/xx/VisualStudio/Projects/myproject/”); var parsedHtmlElements = HTMLWorker.ParseToList(new StringReader(mainContents), null, providers); foreach (var htmlElement […]

使用itextsharp检查pdf是否受密码保护

我想检查pdf文件是否受密码保护或不查看。 那就是我想知道pdf文件是否有用户密码。 我在一些论坛上找到了一些关于它使用isencrypted函数的帮助,但它没有给出正确的答案。 是否可以检查pdf是否受密码保护?

使用iTextSharp将页面添加到PDF文档

我想在包含简单文本的现有PDF文档中添加一个页面。 我尝试过在互联网上找到的以下代码,但到目前为止我还没有工作: PdfReader reader = new PdfReader(“1.pdf”); Document document = new Document(reader.GetPageSize(1)); PdfCopy copier = new PdfCopy(doc, new FileStream(“2.pdf”, FileMode.Create)); for (int pageCounter = 1; pageCounter < reader.NumberOfPages + 1; pageCounter++) { //byte[] page = reader.GetPageContent(pageCounter); copier.AddPage(copier.GetImportedPage(reader, pageCounter)); } copier.NewPage(); copier.Add(new Paragraph("This is added text")); document.Close(); reader.Close(); 请让我知道如何做到这一点?

iTextsharp景观文件

我正在尝试使用iTextSharp创建Landscape PDF,但它仍然显示肖像。 我正在使用以下代码旋转: Document document = new Document(PageSize.A4, 0, 0, 150, 20); FileStream msReport = new FileStream(Server.MapPath(“~/PDFS/”) + “Sample1.pdf”, FileMode.Create); try { // creation of the different writers PdfWriter writer = PdfWriter.GetInstance(document, msReport); document.Open(); PdfPTable PdfTable = new PdfPTable(1); PdfTable.SpacingBefore = 30f; PdfPCell PdfPCell = null; Font fontCategoryheader = new Font(Font.HELVETICA, 10f, Font.BOLD, Color.BLACK); for […]

使用Itextsharp搜索PDF格式的特定单词

这是我在StackOverflow中的第一篇文章。 我的系统驱动器中有一个PDF文件…我想在C#中编写一个程序,使用Itextsharp.dll引用来搜索该PDF中的特定单词…说我要搜索“StackOverFlow”…如果PDF包含Word“StackOverFlow”,它应该返回true。 否则它应该返回false。 我已经看了很多文章,但直到现在才得到解决方案.. 🙁 我到现在为止尝试的是: public string ReadPdfFile(string fileName) { StringBuilder text = new StringBuilder(); if (File.Exists(fileName)) { PdfReader pdfReader = new PdfReader(fileName); for (int page = 1; page <= pdfReader.NumberOfPages; page++) { ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy(); string currentText = "2154/MUM/2012 A";// PdfTextExtractor.GetTextFromPage(pdfReader, page, strategy); currentText = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(currentText))); text.Append(currentText); } pdfReader.Close(); […]

来自预定义模板的多页PDF文档

我需要使用一些预定义的公司模板生成PDF格式的发票报告。 我可以使用iTextSharp创建/生成SINGLE PAGE PDF报告。 问题:当发票声明跨越多个页面时出现问题。 我无法将报告(发票声明)扩展到下一页(第二页)。 如果所有数据都不能容纳在一个页面上,则应该在第二页上写入,同时仍然使用公司模板。 模板位于以下路径: HostingEnvironment.MapPath(“~/Content/InvoiceTemplate/invoiceTemplate.pdf”) 我正在使用iTextSharp库来创建文档。 以下是用于生成PDF的代码: public class pdfStatementController : Controller { Models.DYNAMICS_EXTEntities _db = new Models.DYNAMICS_EXTEntities(); // // GET: /pdfStatement/ public ActionResult SendPdfStatement(string InvoiceNumber) { try { InvoiceNumber = InvoiceNumber.Trim(); ObjectParameter[] parameters = new ObjectParameter[1]; parameters[0] = new ObjectParameter(“InvoiceNumber”, InvoiceNumber); List statementList = new List(); statementList = _db.ExecuteFunction(“uspInvoiceStatement”, parameters).ToList(); […]

什么是PdfPTable.DefaultCell属性用于?

什么是DefaultCell属性用于? PdfPTable.getDefaultCell()的Java文档读取: 获取默认的PdfPCell ,它将用作除addCell(PdfPCell)之外的所有addCell方法的引用。 我不明白。 缺少.NET库的文档。 Java仍然有文件certificate,但不是那么好。 我通常从Java中查找,因为这两个API是对称的。 但我仍然不明白这个属性的含义。

itextsharp中的阿拉伯语编码

当我尝试使用C#在阿拉伯语中创建此代码时,生成的PDF文件包含离散字符。 任何帮助,所以我不能得到连续的字符? //Create our document object Document Doc = new Document(PageSize.LETTER); //Create our file stream using (FileStream fs = new FileStream(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), “Test.pdf”), FileMode.Create, FileAccess.Write, FileShare.Read)) { //Bind PDF writer to document and stream PdfWriter writer = PdfWriter.GetInstance(Doc, fs); //Open document for writing Doc.Open(); //Add a page Doc.NewPage(); //Full path to the Unicode Arial file string […]

将PdfPCell添加到段落中

我正在尝试使用iTextSharp在段落句子的中间添加TextField(acrofield)。 一个例子是“生效日期是[月]的[日]日,[年]这将开始。” 我尝试过的事情: Paragraph para1 = new Paragraph(); para1.Add(New Phrase(“The Effective Date is”,fontBold)); //The next line is where it breaks, “Insertion of illegal Element: 30” para1.Add(CreateTextField(“Day”,1,0)); //this function returns a PdfPCell. PdfPCell tempCell = new PdfPCell(); tempCell.AddElement(new Phrase(“The Effective Date is”,fontBold)); //the next line breaks as well, “Element not allowed.” tempCell.AddElement(CreateTextField(“Day”,1,0)); Paragraph para1 = new […]