Tag: itextsharp

ITextSharp PdfCopy使用示例

我正在尝试使用ItextSharp中的PdfSmartCopy,但我在c#中找不到任何相关的例子。 我的意思是我有一个包含表单字段的pdf,并且这些字段增加了700kb到pdf文档的大小。 没有表单字段的原始文档是100kb 。 欢迎任何其他sugestions,尤其是o一致地减少pdf大小。 (我使用adobe acrobat优化了生成的PDF,并将其减少到44kb 。因此必须在某处出现故障。)有没有办法减少PDF大小? 编辑:FormFlatenning没有帮助。 pdf模板文件仅包含文本,行和表,没有图像。 这是我的代码片段 PdfReader reader = new PdfReader(GetTemplateBytes()); pst = new PdfStamper(reader, Response.OutputStream); var acroFields = pst.AcroFields; pst.FormFlattening = true; pst.FreeTextFlattening = true; SetFieldsInternal(acroFields); pst.Close();

无法从程序集’itextsharp,Version = 5.5.5.0,Culture = neutral,PublicKeyToken = 8354ae6d2174ddca’加载类型’iTextSharp.text.html.HtmlParser’

看到这个链接将html转换为pdf我在webconfig中得到了这个版本错误让一些天才找到并解决了qustion。 我的模特 public class Customer { public int CustomerID { get; set; } public string FirstName { get; set; } public string LastName { get; set; } } 我的控制器这是正常的代码 public ActionResult Index() { List customers = new List(); for (int i = 1; i <= 10; i++) { Customer customer = new Customer { CustomerID […]

iTextSharp正在使用Response生成损坏的PDF

我试过两个,但仍然没有工作 iTextSharp + FileStream =损坏的PDF文件 iTextSharp正在生成一个损坏的PDF using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream()) { //abre o documento para poder editar document.Open(); //Adiciona os campos de assinatura document.Add(Assinatura()); //fecha o documento ao finalizar a edição document.Close(); //Prepara o download byte[] bytes = memoryStream.ToArray(); memoryStream.Close(); Response.Clear(); Response.ContentType = “image/pdf”; //Response.ContentType = “application/pdf”; Response.AddHeader(“Content-Disposition”, “attachment; filename=ControleDePonto.pdf”); Response.Buffer = true; […]

如何在文档的每个页面上显示iTextSharp签名?

当我签署文档时,签名仅出现在第一页上。 我能做些什么让它出现在每一页上吗? 这是我正在使用的方法来签署PDF,希望它有助于找到解决方案: public static PdfStamper SignHashedUser(string Target, SysX509.X509Certificate2 Certificate, string Reason, string Location, bool AddVisibleSign, PdfReader objReader, int pags) { X509CertificateParser objCP = new X509CertificateParser(); X509Certificate[] objChain = new X509Certificate[] { objCP.ReadCertificate(Certificate.RawData) }; PdfStamper objStamper = PdfStamper.CreateSignature(objReader, new FileStream(Target, FileMode.Create), ‘\0’); PdfSignatureAppearance objSA = objStamper.SignatureAppearance; int[] perms = { PdfWriter.AllowPrinting, PdfWriter.AllowFillIn }; if (AddVisibleSign) […]

无法访问该文件,因为它正由另一个进程使用

我的web方法在我的%temp%文件夹中创建一个pdf文件,该文件有效。 然后我想使用下面的代码向该文件添加一些自定义字段(meta)。 PdfStamper类生成一个IOException ,无论我使用它的.Close()方法还是using块结束。 仍然保留文件句柄的过程是webdev Web服务器本身(我在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, FileShare.ReadWrite)) { PdfStamper st = new PdfStamper(reader, fs); Dictionary info = reader.Info; info.Add(“Guid”, guid); info.Add(“CompanyID”, companyID.ToString()); st.MoreInfo = info; st.Close(); } reader.Close(); return guid; […]

使用C#中的iTextSharp将PDF旋转90度

我正在尝试使用PDF进行冲压,需要将其旋转90度才能正确铺设? 有人知道怎么做吗? 似乎无法在网上找到它。

从PDF中的特定页面提取图像

我想从PDF文件中提取图像。 我尝试使用以下代码,它从PDF中完美地提取了一个jpeg图像。 问题是如何从特定页面(例如第1页)或其他页面中提取图像。 我不想阅读整个PDF来搜索图像。 有什么建议? 提取图像的代码: private void List ExtractImages(String PDFSourcePath) { List ImgList = new List(); iTextSharp.text.pdf.RandomAccessFileOrArray RAFObj = null; iTextSharp.text.pdf.PdfReader PDFReaderObj = null; iTextSharp.text.pdf.PdfObject PDFObj = null; iTextSharp.text.pdf.PdfStream PDFStremObj = null; try { RAFObj = new iTextSharp.text.pdf.RandomAccessFileOrArray(PDFSourcePath); PDFReaderObj = new iTextSharp.text.pdf.PdfReader(RAFObj, null); for (int i = 0; i <= PDFReaderObj.XrefSize – 1; i++) […]

在iTextSharp中设置元数据

我正在开发一个应用程序,我使用iTextSharp库。 我也正在阅读Manning的iText,所以我可以获得参考资料。 在第12章中,它具有以下代码来更改Java中的元数据。 PdfReader reader = new PdfReader(src); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest)); HashMap 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 Bruno Lowagie”); stamper.setMoreInfo(info); stamper.close(); 我怎样才能在C#中做同样的事情?

如何使用iTextSharp将缩放级别设置为pdf?

我需要使用iTextSharp将缩放级别设置为75%到pdf文件。 我正在使用以下代码来设置缩放级别。 PdfReader reader = new PdfReader(“input.pdf”.ToString()); iTextSharp.text.Document doc = new iTextSharp.text.Document(reader.GetPageSize(1)); doc.OpenDocument(); PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(“Zoom.pdf”, FileMode.Create)); PdfDestination pdfDest = new PdfDestination(PdfDestination.XYZ, 0, doc.PageSize.Height, 0.75f); doc.Open(); PdfAction action = PdfAction.GotoLocalPage(1, pdfDest, writer); writer.SetOpenAction(action); doc.Close(); 但我在doc.Close();收到错误“页面1是请求但文档只有0页” doc.Close();

为什么我的内容与我的页脚重叠?

我正在使用itextsharp生成pdf …我的问题是我的内容/文本页脚…我想自动将内容分解为新页面…如果它出现在页脚… 现在我正在使用document.newpage() 但我想自动做到我的页面/内容自动分解到新页面..不应该来到页面的页眉/页脚… 我通过这个类创建页眉/页脚的信息 public class ITextEvents : PdfPageEventHelper 我用这个function public override void OnEndPage 我还附上了即时通讯的结果……请帮助我…如果你在评论中提问,我可以分享更多信息 我希望这最后一个盒子自动进入新的页面…..