本文整理汇总了Java中com.itextpdf.text.pdf.AcroFields.setField方法的典型用法代码示例。如果您正苦于以下问题:Java AcroFields.setField方法的具体用法?Java AcroFields.setField怎么用?Java AcroFields.setField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.itextpdf.text.pdf.AcroFields
的用法示例。
在下文中一共展示了AcroFields.setField方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testPd3100SetVrPr4ToNo
import com.itextpdf.text.pdf.AcroFields; //导入方法依赖的package包/类
/**
* <a href="http://stackoverflow.com/questions/42819618/itext-fill-checkbox-with-value">
* itext fill checkbox with value
* </a>
* <br/>
* <a href="https://www.poreskaupravars.org/Documents/Doc/PD3100.pdf">
* PD3100.pdf
* </a>
* <p>
* This test uses a valid name and so at least creates
* a PDF displayed with a somehow selected field.
* </p>
* @see #testPd3100SetVrPr4ToNoAppend()
*/
@Test
public void testPd3100SetVrPr4ToNo() throws IOException, DocumentException
{
try ( InputStream resource = getClass().getResourceAsStream("PD3100.pdf");
OutputStream result = new FileOutputStream(new File(RESULT_FOLDER, "PD3100-SetVrPr4ToNo.pdf")) )
{
PdfReader pdfReader = new PdfReader(resource);
PdfStamper pdfStamper = new PdfStamper(pdfReader, result, (char)0, false);
AcroFields acroFields = pdfStamper.getAcroFields();
System.out.println("Available values for VrPr4: " + Arrays.asList(acroFields.getAppearanceStates("VrPr4")));
acroFields.setField("VrPr4", "No");
pdfStamper.close();
}
}
示例2: testFillInForm
import com.itextpdf.text.pdf.AcroFields; //导入方法依赖的package包/类
/**
* <a href="http://stackoverflow.com/questions/28967737/itextsharp-setfield-for-fields-with-same-name-on-different-pages">
* iTextSharp SetField for fields with same name on different pages
* </a>
* <p>
* Reproducing the issue with iText
* </p>
*/
@Test
public void testFillInForm() throws IOException, DocumentException
{
try ( InputStream resource = getClass().getResourceAsStream("ING_bewindvoering_regelen_tcm162-49609.pdf");
OutputStream result = new FileOutputStream(new File(RESULT_FOLDER, "hybrid-form-fillin.pdf")) )
{
PdfReader reader = new PdfReader(resource);
PdfStamper stamper = new PdfStamper(reader, result);
AcroFields fields = stamper.getAcroFields();
fields.setField("topmostSubform[0].CheckBox2A[0]", "1");
// fields.setField("topmostSubform[0].Page2[0].CheckBox2A[0]", "1");
stamper.close();
}
}
示例3: setField
import com.itextpdf.text.pdf.AcroFields; //导入方法依赖的package包/类
private static void setField(AcroFields fields, String key, String value) {
try {
fields.setField(key, value);
} catch(DocumentException | IOException e) {
throw new RuntimeException("Error setting PDF field", e);
}
}
示例4: testPd3100SetVrPr4ToNoAppend
import com.itextpdf.text.pdf.AcroFields; //导入方法依赖的package包/类
/**
* <a href="http://stackoverflow.com/questions/42819618/itext-fill-checkbox-with-value">
* itext fill checkbox with value
* </a>
* <br/>
* <a href="https://www.poreskaupravars.org/Documents/Doc/PD3100.pdf">
* PD3100.pdf
* </a>
* <p>
* This test uses a valid name in append mode and so creates
* a PDF displayed in Adobe Reader with a selected field as
* desired.
* </p>
* @see #testPd3100SetVrPr4ToNoAppend()
*/
@Test
public void testPd3100SetVrPr4ToNoAppend() throws IOException, DocumentException
{
try ( InputStream resource = getClass().getResourceAsStream("PD3100.pdf");
OutputStream result = new FileOutputStream(new File(RESULT_FOLDER, "PD3100-SetVrPr4ToNoAppend.pdf")) )
{
PdfReader pdfReader = new PdfReader(resource);
PdfStamper pdfStamper = new PdfStamper(pdfReader, result, (char)0, true);
AcroFields acroFields = pdfStamper.getAcroFields();
System.out.println("Available values for VrPr4: " + Arrays.asList(acroFields.getAppearanceStates("VrPr4")));
acroFields.setField("VrPr4", "No");
pdfStamper.close();
}
}