- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何将 PDF 表单元素添加到 PDFsharp PdfPage
目的?
我知道 AcroForm 是可填写表单的 PDF 元素的最佳格式,但 PDFsharp 库似乎不允许您创建 AcroForm 对象的实例。
我已经能够使用 PDFsharp 生成简单的文档,如下所示:
static void Main(string[] args) {
PdfDocument document = new PdfDocument();
document.Info.Title = "Created with PDFsharp";
// Create an empty page
PdfPage page = document.AddPage();
// Draw Text
XGraphics gfx = XGraphics.FromPdfPage(page);
XFont font = new XFont("Verdana", 20, XFontStyle.BoldItalic);
gfx.DrawString("Hello, World!", font, XBrushes.Black,
new XRect(0, 0, page.Width, page.Height), XStringFormats.Center);
// Save document
const string filename = "HelloWorld.pdf";
document.Save(filename);
}
page.Elements.Add(string key, PdfItem item)
方法,但是如何制作 AcroForm
PdfItem
? (像
PdfTextField
这样的类似乎没有公共(public)构造函数)
"Hello World"
上面的文本到文本字段?
最佳答案
PdfSharp 中的大多数类构造函数都是密封的,这使得创建新的 pdf 对象有点困难。但是,您可以使用它的类创建对象来添加低级 pdf 元素。
下面是创建文本字段的示例。
关于关键元素的定义,请参阅从第 432 页开始的 pdf 技术规范
https://www.adobe.com/content/dam/acom/en/devnet/pdf/pdfs/PDF32000_2008.pdf
public static void AddTextBox()
{
using (PdfDocument pdf = new PdfDocument())
{
PdfPage page1 = pdf.AddPage();
double left = 50;
double right = 200;
double bottom = 750;
double top = 725;
PdfArray rect = new PdfArray(pdf);
rect.Elements.Add(new PdfReal(left));
rect.Elements.Add(new PdfReal(bottom));
rect.Elements.Add(new PdfReal(right));
rect.Elements.Add(new PdfReal(top));
pdf.Internals.AddObject(rect);
PdfDictionary form = new PdfDictionary(pdf);
form.Elements.Add("/Filter", new PdfName("/FlateDecode"));
form.Elements.Add("/Length", new PdfInteger(20));
form.Elements.Add("/Subtype", new PdfName("/Form"));
form.Elements.Add("/Type", new PdfName("/XObject"));
pdf.Internals.AddObject(form);
PdfDictionary appearanceStream = new PdfDictionary(pdf);
appearanceStream.Elements.Add("/N", form);
pdf.Internals.AddObject(appearanceStream);
PdfDictionary textfield = new PdfDictionary(pdf);
textfield.Elements.Add("/FT", new PdfName("/Tx"));
textfield.Elements.Add("/Subtype", new PdfName("/Widget"));
textfield.Elements.Add("/T", new PdfString("fldHelloWorld"));
textfield.Elements.Add("/V", new PdfString("Hello World!"));
textfield.Elements.Add("/Type", new PdfName("/Annot"));
textfield.Elements.Add("/AP", appearanceStream);
textfield.Elements.Add("/Rect", rect);
textfield.Elements.Add("/P", page1);
pdf.Internals.AddObject(textfield);
PdfArray annotsArray = new PdfArray(pdf);
annotsArray.Elements.Add(textfield);
pdf.Internals.AddObject(annotsArray);
page1.Elements.Add("/Annots", annotsArray);
// draw rectangle around text field
//XGraphics gfx = XGraphics.FromPdfPage(page1);
//gfx.DrawRectangle(new XPen(XColors.DarkOrange, 2), left, 40, right, bottom - top);
// Save document
const string filename = @"C:\Downloads\HelloWorld.pdf";
pdf.Save(filename);
pdf.Close();
Process.Start(filename);
}
}
关于C#:使用 PDFsharp 创建 PDF 表单 (AcroForm),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54486608/
我有一个获取附件文件名的脚本,如果扩展名表示 pdf 文件,它会通过以下代码运行它。但是我收到了下面的 KeyError。我找不到有关如何更正或排除故障的任何信息。我之前已经通过这个脚本成功地运行了
我使用itext7,我需要从pdfformfield中的acroform获取字体颜色。 我在 PdfFont 中没有找到此属性。 我该怎么做? 最佳答案 可以使用检索表单字段默认外观的文本颜色 Col
我正在尝试使用 iTextSharp 填写 AcroForm 的文本字段。 Acroform 文本字段也是由 iTextSharp 通过这段代码创建的: TextField Field = new T
我正在使用 LibreOffice 4.1.3.2 生成可填写的 PDF: 创建了一个 Writer 文档 设置一些文本和测试字段 导出为 PDF 使用 Acrobar Reader 打开 pdf 文
如何将带有 pdfsharp lib 的 Acroforms(或任何输入字段)添加到 pdf? 例如一个文本框 (PdfSharp::Pdf::AcroForms::PdfTextField) 我找不
我正在使用 Apache PDFBox 2.0.8并试图删除一个字段。但找不到方法来做到这一点,就像我对 iText 所做的那样:PdfStamper.getAcroFields().removeFi
我有一个带有 acroform 的 pdf。我正在使用 iText 打开此 pdf 并用一些数据填充表单字段。有时我需要生成比原始 pdf 更多的页面。为此,我创建一个页面并使用以下代码替换为现有页面
当我创建一个包含 AcroForm 格式的文本字段(PDF 词典,无 XFA)的 PDF 表单(例如使用 Acrobat)并将数据提交到服务器时,如何指定/检索将要使用的编码用过吗? 例如。当我提交中
我正在使用 iText 向现有 pdf 文件添加文本。它适用于简单的 pdf,但 pdf 与 AcroForms 有问题。 我的代码: PdfReader reader = new PdfRe
如何将 PDF 表单元素添加到 PDFsharp PdfPage目的? 我知道 AcroForm 是可填写表单的 PDF 元素的最佳格式,但 PDFsharp 库似乎不允许您创建 AcroForm 对
我想自动填写 AcroForm/XFA 双 PDF 表单。我包含了一个 XFA 数据集包,所有值都显示在 Adobe Reader 中。我将 AcroForms 条目中的 V= 键设置为新值,所有
我需要解析一个包含大量 Acroform 字段的 PDF 文件,并为每个字段提取字段名称(PDF 标记中的/T)和值(PDF 标记中的/V)。我想在 JavaScript 中做这个客户端,但我没有找到
我有一个包含很多 acroform 的 pdf,我对其进行了一些操作,从而生成了一个新的 pdf。所以我有 PDF-1(这是原始的)和 PDF-2(只是 PDF-1 的副本),现在我想合并它们。两个
我创建了带有 3 个标签的简单 PDF 文档:名字、姓氏和照片。然后我使用 Adobe Acrobat PRO DC 添加了带有 2 个“文本字段”和一个“图像字段”的 AcroForm 层。 因
我正在尝试解析 PDF 文档,结果很顺利。 PDF 在 Adobe FormCentral 中创建,包含单个表单元素(日期字段)。 头: $(document).ready
我想使用 reportLab 在 Django 中的 PDF 上创建一个 acroform。我已经安装了 reportLab 的包。但是当实现 acroform 时我得到 inAttributeErr
我试图以 pdf 形式获取所有可用字段,但在使用 PDFBox 调用 acroform.getFields() 时遇到了 NullPointerException。 示例: pdDoc = PDDoc
我有很多 2007 年的 PDF(版本:4),它们显然有表单,但 pdfbox 和 iText 5 中的 AcroForm 对象要么为空,要么为 null。 为什么我认为 PDF 包含表单?因为在元数
我需要帮助使用 PDFBox API 将西里尔文值添加到字段中.这是我到目前为止所拥有的: PDDocument document = PDDocument.load(file); PDDocumen
我正在寻找一个简单的 API 示例,它读取 PDF 文件/模板作为输入,并迭代 PDF 表单中定义的字段(我认为它称为 AcroForm) 最佳答案 好的,我找到了解决方案 public static
我是一名优秀的程序员,十分优秀!