使用itextsharp,我试图将表单的文本字段的字体大小设置为auto.
我现在正在做这样的事情:
Object d = 0.0;
PdfReader reader = new PdfReader(path);
byte [] pdf;
using (var ms = new MemoryStream())
{
PdfStamper stamper = new PdfStamper(reader, ms);
AcroFields fields = stamper.AcroFields;
foreach (var f in fields.Fields.Keys)
{
fields.SetFieldProperty(f, "textsize", d, null);
}
}
Run Code Online (Sandbox Code Playgroud)
但是我收到以下错误:
System.InvalidCastException: Specified cast is not valid.
at iTextSharp.text.pdf.AcroFields.SetFieldProperty(String field, String name, Object value, Int32[] inst)
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题?
我正在尝试添加一个可填写的表单(以便最终用户可以使用acrobat reader将信息插入到它中,然后保存)到我使用Apache FOP生成的PDF.如果有可能,我似乎无法找到有关如何完成此操作的任何信息.
谷歌没有提供太多相关信息,主要是因为它不可能,但大多数信息可以追溯到2000年代早期.
有没有办法使用FOP添加acrofield?
我创建了带有3个标签的简单PDF文档:名字,姓氏和照片。然后,我使用Adobe Acrobat PRO DC在AcroForm图层中添加了2个“文本字段”和一个“图像字段”。
因此,如果我要填写表格,可以在常规的Acrobat Reader中打开此PDF文件,并通过键入名字,姓氏进行填写,并插入照片,然后单击图像占位符并在打开的对话框窗口中选择照片。
但是我该如何以编程方式做同样的事情?创建了使用Apache PDFBox库(版本2.0.7)查找表单字段并插入值的简单Java应用程序。
我可以轻松填充“文本编辑”字段,但无法弄清楚如何插入图像:
public class AcroFormPopulator {
public static void main(String[] args) {
AcroFormPopulator abd = new AcroFormPopulator();
try {
abd.populateAndCopy("test.pdf", "generated.pdf");
} catch (IOException e) {
e.printStackTrace();
}
}
private void populateAndCopy(String originalPdf, String targetPdf) throws IOException {
File file = new File(originalPdf);
PDDocument document = PDDocument.load(file);
PDAcroForm acroForm = document.getDocumentCatalog().getAcroForm();
Map<String, String> data = new HashMap<>();
data.put("firstName", "Mike");
data.put("lastName", "Taylor");
data.put("photo_af_image", "photo.jpeg");
for (Map.Entry<String, String> item : data.entrySet()) {
PDField field = …Run Code Online (Sandbox Code Playgroud) 使用 iText7,我喜欢通过表单字段获取 pdf 页码,但我找不到获取页码的方法或属性。
IDictionary<String, PdfFormField> fields = form.GetFormFields();
PdfFormField field = fields["fieldName"];
field.page <-- there is no property
Run Code Online (Sandbox Code Playgroud)
我找到了这个:
PdfPage page = field.GetWidgets().First().GetPage();
Run Code Online (Sandbox Code Playgroud)
但我不知道如何从 PdfPage 获取页码。
看起来 iText5 有这个(在 Java 中):
int page = form.getFieldPositions(name).get(0).page;
Run Code Online (Sandbox Code Playgroud)
我怎么能用 C# 中的 iText 7 做到这一点
acrofields ×4
pdf ×2
.net ×1
apache-fop ×1
c# ×1
itext ×1
itext7 ×1
itextsharp ×1
java ×1
pdfbox ×1