我已经将 iText 用于一些各种实用程序,例如我们成功合并和编辑 pdf 文件。现在我需要重叠 2 个 pdf 页面:
例如:输入:PDF#1(1页)PDF#2(1页)
输出:PDF#3(1 页:这是 2 个输入页重叠的结果)
我不知道 iText 最新版本是否可以做到这一点。我还考虑使用 2 个输入 PDF 文件之一作为 PDF 输出文件的背景。
先感谢您。
当我使用 itextsharp 提取文本时,我将获得文本的 x 和 y 坐标。通过使用这两个坐标,如果我根据 xy 位置将文本从 pdf 转换为 html 文本位置 chnages 。得到我使用的 x ,y 坐标
矢量 curBaseline = renderInfo.GetBaseline().GetStartPoint();
float x=curBaseline[Vector.I1];
浮动 y= curBaseline[Vector.I2];
例如:当我使用上述方法提取文本时,说 x=42 和 y=659;
我有一个签名的 PDF 文件。使用这个使用 iTextSharp 库的函数,我找到了证书 p7m 签名:
private void GetSignature(string FileName)
{
AcroFields acroFields = new PdfReader(FileName).AcroFields;
List<string> names = acroFields.GetSignatureNames();
foreach (var name in names)
{
PdfDictionary dict = acroFields.GetSignatureDictionary(name);
PdfString contents = (PdfString)PdfReader.GetPdfObject(dict.Get(PdfName.CONTENTS));
byte[] PKCS7 = contents.GetOriginalBytes();
ByteArrayToFile(@"c:\signature\" + name + ".p7m", PKCS7);
}
}
Run Code Online (Sandbox Code Playgroud)
现在...如何提取与签名关联的图像(位图)?是否可以?谢谢,路易吉
在iText 5.4.4的发行说明中,它说:
从现在开始,您可以在PdfCopy中使用addDocument()方法时合并表单并保留标记的PDF结构.与此同时,我们已经弃用了PdfCopyFields.*
我尝试将多个pdf文档合并为一个pdf文档.如果其中一个文档是带有acroFields的pdf表单,那么这些字段在输出文档中将不可见.当我在PdfCopy中使用addDocument()方法时就是这种情况.当我在PdfCopyFields中使用addDocument()方法时,它工作正常.在iTextSharp中弃用PdfCopyFields,但PdfCopy是否正常工作?还有另一个原因是不使用PdfCopyFields(来自"iText in Action":
不要使用PdfCopyFields连接没有表单字段的PDF文档.与使用PdfCopy连接文档相反,Pdf-CopyFields需要将所有文档保留在内存中以更新组合形式.如果您尝试连接大型文档,这可能会成为问题.
这是我使用的代码:
public static void MergePdfs4()
{
var f1 = @"C:\Users\paulusj\Downloads\OoPdfFormExampleFilled.pdf";
var f2 = @"c:\GEODAN\work\EV_Original.pdf";
using (
Stream outputPdfStream = new FileStream("combined4.pdf ", FileMode.Create, FileAccess.Write,
FileShare.None))
{
var document = new Document();
var copy = new PdfCopy(document, outputPdfStream);
document.Open();
copy.AddDocument(new PdfReader(f1));
copy.AddDocument(new PdfReader(f2));
copy.Close();
}
}
Run Code Online (Sandbox Code Playgroud)
奇怪的是,当我使用Adobe Reader"另存为"复制EV_Original.pdf时,副本(几乎)正确合并.所以在输出pdf中我可以看到表单字段.
当我使用这段代码时:
public static void MergePdfs3()
{
var f1 = @"C:\Users\paulusj\Downloads\OoPdfFormExampleFilled.pdf";
var f2 = @"c:\GEODAN\work\EV_Original.pdf";
using (Stream outputPdfStream = new FileStream("combined3.pdf ", FileMode.Create, FileAccess.Write,
FileShare.None))
{
var …Run Code Online (Sandbox Code Playgroud) 当我尝试从HTML生成PDF时,PDF ?Ü??ÖÇ ?ü??öç中缺少一些土耳其字符,我看到一个空格代替这些字符,但我想打印该字符.
我的代码是:
public virtual void print pdf(string html, int id)
{
String htmlText = html.ToString();
Document document = new Document();
string filePath = HostingEnvironment.MapPath("~/Content/Pdf/");
PdfWriter.GetInstance(document, new FileStream(filePath + "\\pdf-"+id+".pdf",
FileMode.Create));
document.Open();
iTextSharp.text.html.simpleparser.HTMLWorker hw =
new iTextSharp.text.html.simpleparser.HTMLWorker(document);
hw.Parse(new StringReader(htmlText));
document.Close();
}
Run Code Online (Sandbox Code Playgroud)
请回复我需要建议......问候
我正在阅读 pdf 并使用 itextsharp 注入一些内容。结果byte[]与压缩级别一起传递给下面的方法。
public static byte[] method(byte[] pdf,int compressionlevel)
{
using (MemoryStream outputPdfStream1 = new MemoryStream())
{
//PdfReader reader1 = new PdfReader(pdf);
//PdfStamper stamper1 = new PdfStamper(reader1, outputPdfStream1);
//int level = (int)compressionlevel;
//if (level <= 9)
// stamper1.Writer.CompressionLevel = (int)compressionlevel;
//else
// stamper1.Writer.SetFullCompression();
//stamper1.SetFullCompression();
//stamper1.Close();
//byte[] newfile = outputPdfStream1.ToArray();
//return newfile;
PdfReader reader = new PdfReader(pdf);
PdfStamper stamper = new PdfStamper(reader, outputPdfStream1,PdfWriter.VERSION_1_5);
int level = (int)compressionlevel;
if (level <= 9)
{
stamper.Writer.CompressionLevel = level;
}
else …Run Code Online (Sandbox Code Playgroud) 以下代码确实生成表和嵌套表.但是,嵌套表始终在中间对齐.我不知道如何正确实现水平对齐.
以下方法只是循环遍历列表.当这是一个简单的问题时,我将添加一个TextField.如果这是一个包含多个答案的问题,我将注入一个带有复选框和值的嵌套表.
private PdfPTable CreateQuestionTable(RLQuestionRecordList questions)
{
PdfPCell cell;
PdfPTable table = new PdfPTable(2);
//table.SetWidths(new int[]{ 50, 50 });
table.WidthPercentage = 100;
table.SpacingBefore = 20;
table.SpacingAfter = 20;
table.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
foreach (RCQuestionRecord q in questions)
{
//add question to the table
cell = new PdfPCell(new Phrase(q.ssSTQuestion.ssName, _Normal));
cell.Border = Rectangle.NO_BORDER;
cell.Padding = 5.0f;
table.AddCell(cell);
//add answer to the table.
//add generate time we don;t know where the table will be,
//hence textfields will be generated after the pdf has …Run Code Online (Sandbox Code Playgroud) 我通过添加可容纳多页的单个 PdfPTable 来生成 PDF。现在我想为所有这些页面添加页眉和页脚,但它只显示在第一页上。边距也无法正常工作。
我正在覆盖 PdfPageEventHelper 类的 OnStartPage/OnEndPage 事件。
请建议合并页眉和页脚的最佳方式。
谢谢
我正在使用iTextSharp生成一个大文档.在本文档中,我想要一些特定的页面.其余的都是肖像.有谁知道我怎么做到这一点?无法启动新文档.
谢谢!
我的应用程序是使用itext#生成PDF文档.文件打开正常并在Foxit Reader中正确显示,但在Adobe Acrobat中它出错:
There was an error processing page. There was a problem reading this document (109).
Run Code Online (Sandbox Code Playgroud)
为什么文件在一个文件中打开而另一个文件不打开?