Tag: itextsharp

如何通过使用c#提供文件的密码作为参数来解密pdf文件?

我使用以下代码生成了一个带密码保护的pdf文件: using (Stream input = new FileStream(InputFile, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (Stream output = new FileStream(OutputFile, FileMode.Create, FileAccess.Write, FileShare.None)) { PdfReader reader = new PdfReader(input); PdfEncryptor.Encrypt(reader, output, true, strDob, “secret”, PdfWriter.ALLOW_SCREENREADERS); } } 我想根据我的某些条件通过代码删除使用上述代码生成的PDF文件的密码。

PdfPTable单元格宽度

我正在使用iTextSharp在我的应用程序中创建PDF。 但是我必须重新创建一个表,我必须为一个非常小的列设置大小。 下面是显示我想要设置列的大小的图片: 当表创建的其余部分都很好时, 我无法设置此宽度 。 码: PdfPTable table = new PdfPTable(2); table.WidthPercentage = 82.0f; PdfPCell cell = new PdfPCell(new Phrase(“Com a assinatura autógrafa, o signatário desta Auto-declaração garante ter cumprido estas condições:”, fontetexto)); cell.PaddingBottom = 10f; cell.PaddingTop = 10f; cell.Colspan = 2; cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right table.AddCell(cell); table.AddCell(“1. “); table.AddCell(“Os óleos e […]

iTextSharp – 如何打开/读取/提取文件附件?

我有一些PDF都带有两个带有静态名称的附加文件。 我想使用iTextSharp将这些文件解压缩到临时目录,以便我可以进一步使用它们。 我尝试按照本教程进行操作,但是当iTextSharp.text.pdf.PdfReader没有getCatalog()方法时,我遇到了问题,如下面的示例所示。 关于如何提取附件的任何建议? 让我们简单地说PDF文档位于“C:\ test.pdf”,两个附件存储为“attach1.xml”和“attach2.xml”。

在c#中将office文档转换为pdf

我想务实地将office文档转换为pdf.i不想使用microsoft office service ddl。 这是我用的代码, using System; using System.IO; using Microsoft.Office.Interop.Word; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.IO.Compression; using Document = Microsoft.Office.Interop.Word.Document; namespace pdfconversion { public class PdfMerge { static void Main() { var wordApplication = new Microsoft.Office.Interop.Word.Application(); Document wordDocument = null; object paramSourceDocPath = @”C:\testfile.doc”; object paramMissing = Type.Missing; […]

在itextsharp表中更改字体大小

我试图使用iTextSharp查看PDF文件中的表格。 我已经想出了如何添加表格,并通过单击按钮打开PDF文件,但表格字体太大,并且文字被包装使它们难以阅读。 我已输入此代码,但表格字体没有任何反应。 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlServerCe; using System.IO; using iTextSharp.text; using iTextSharp.text.pdf; namespace Lewis_Warby_Airbrushing { public partial class selectedorderForm : Form { public selectedorderForm(string strValue) { InitializeComponent(); textBox1.Text = strValue; } DataTable dt; private void selectedorderForm_Load(object sender, EventArgs e) { […]

无法以pdf格式打印复选框

我们正在使用WkHtmlToPdf从html转换为pdf。 现在我也可以根据要求编辑所有表单字段。 由于WkHtmlToPdf在将Html转换为Pdf时存在错误,因此将所有表单字段的属性设置为Visible Not Printable。 为了解决这个问题,我们使用ITextSharp来读取由WkHtmlToPdf生成的现有pdf,并为每个表单字段将该属性设置为Visible。 这就是我这样做的方式 var pdfReader = new PdfReader(inputFilename); using (var outputStream = new FileStream(outputFilename, FileMode.OpenOrCreate)) { var stamper = new PdfStamper(pdfReader, outputStream); // Regenarating all the fileds using itextSharp. // Since wkHtmltoPdf has differnt default settings for pdf form fields (Visible and not Printable) var formFields = stamper.AcroFields; var filedNames = […]

iTextSharp改变结果质量/压缩,如PDF24Creator

我想知道我是否可以使用iTextSharp和C#压缩/更改我输出的pdf文件的质量,就像我可以使用Adobe Acrobat Pro或PDF24Creator一样。 使用PDF24Creator我可以打开pdf,再次保存文件并将“PDF质量”设置为“低质量”,我的文件大小从88,6MB减少到12.5MB,而质量仍然足够好。 我已经在使用了 writer = new PdfCopy(doc, fs); writer.SetPdfVersion(PdfCopy.PDF_VERSION_1_7); writer.CompressionLevel = PdfStream.BEST_COMPRESSION; writer.SetFullCompression(); 这将文件大小从大约92MB减少到88MB。 或者:我可以使用命令行参数或启动参数通过我的C#代码运行pdf24程序吗? 像这样的东西: pdf24Creator.exe -save -Quality:low -inputfile -outputfile 谢谢你的帮助(布鲁诺)!

在PDF上添加签名图像,而无需使用iTextSharp对其进行数字签名

我正在使用iTextSharp来处理PDF。 我想在签名字段中添加签名图像,而不对文档进行数字签名(不需要任何证书参与)。 可能吗? 我可以使用数字签名但我也想在签名字段上添加签名图像而不使用任何证书。 更新: 现在写我有以下代码。 // Set PDF Reader and PDF Stamper PdfReader reader = new PdfReader(sourceDocument); // File stream where PDF will write FileStream fout = new FileStream(destinationPath, FileMode.Create, FileAccess.ReadWrite); PdfStamper stamper = PdfStamper.CreateSignature(reader, fout, ‘\0’, null, true); // Set PDF Appearance PdfSignatureAppearance appearance = stamper.SignatureAppearance; iTextSharp.text.Image signatureFieldImage = iTextSharp.text.Image.GetInstance(image, System.Drawing.Imaging.ImageFormat.Png); appearance.SignatureGraphic = […]

当Check Type Style为Check Mark时,iTextSharp 5.5.6输入一个十字符号

之前曾问过这个问题( iTextSharp 5.5.6.0 Bug?复选框勾选标记更改 )但是没有提供答案,我无法发表评论,因为我是新用户。 我有完全相同的问题。 我有一个现有的PDF,我正在以编程方式填写(C#)。 表格上有复选框。 在构建4.4.x中,它们在选中时呈现复选标记。 在构建5.5.5.0和5.5.6.0中,它们现在是十字符号。 不要认为设置属性会产生任何影响,因为已经在pdf中设置了这个。 我怎样才能得到一个复选标记而不是十字标记。 我正在使用NuGet提供的最新版本。 如果无法解决此问题,可能必须返回到早期版本。

在pdf c#中将图像水印添加到另一个图像上

所有, 我正在尝试使用itextsharp在pdf中添加图像水印。 水印按预期显示在所有页面上,但是已经有图像的页面。 我希望我的水印图像能够显示在pdf上的现有图像之上。 我正在使用以下代码添加图像 using (Stream output = new FileStream(outputFile, FileMode.Create, FileAccess.Write, FileShare.None)) { using (PdfStamper pdfStamper = new PdfStamper(pdfReader, output)) { for (int pageIndex = 1; pageIndex <= pdfReader.NumberOfPages; pageIndex++) { pdfStamper.FormFlattening = false; iTextSharp.text.Rectangle pageRectangle = pdfReader.GetPageSizeWithRotation(pageIndex); PdfContentByte pdfData = pdfStamper.GetUnderContent(pageIndex); pdfData.SetFontAndSize(BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED), 10); PdfGState graphicsState = new PdfGState(); graphicsState.FillOpacity = […]