Skip to main content
Interwork Corporation
IDR Solutions Product Support Portal
モードの切替 ダーク/ライト/自動 モードの切替 ダーク/ライト/自動 モードの切替 ダーク/ライト/自動

JPedalでPDFフォームデータにアクセスする

PDFフォームデータ

JPedal PDFソフトウェアは、内部的にすべてのPDFフォームをPDF FormObjectに変換し、フォームデータを表現します。この情報には、PdfFormUtilities クラスを使用して直接アクセスできます。

APIを示すコード例

PdfFormUtilitiesクラスを使用すると、PDFファイルに存在する場合、Formオブジェクト、GUIオブジェクト、およびFormNamesのリストにアクセスできます。以下のコード例では、これを行うためのいくつかの異なる方法を詳しく示しています。

final PdfFormUtilities formUtils = new PdfFormUtilities("inputFile.pdf");
try {
    if (formUtils.openPDFFile()) {

        Object[] returnValues;

        //all forms in document (either of the following)
        returnValues = formUtils.getFormComponentsFromDocument(null, ReturnValues.FORMOBJECTS_FROM_REF);
        returnValues = formUtils.getFormComponentsFromDocument(null, ReturnValues.FORMOBJECTS_FROM_NAME);

        //all forms on page 5 (either of the following)
        returnValues = formUtils.getFormComponentsFromPage(null, ReturnValues.FORMOBJECTS_FROM_REF, 5);
        returnValues = formUtils.getFormComponentsFromPage(null, ReturnValues.FORMOBJECTS_FROM_NAME, 5);

        //all formNames
        returnValues = formUtils.getFormComponentsFromDocument(null, ReturnValues.FORM_NAMES);

        //all FormNames of Forms on page 12
        returnValues = formUtils.getFormComponentsFromPage(null, ReturnValues.FORM_NAMES, 12);

        //all forms in document called Mabel
        returnValues = formUtils.getFormComponentsFromDocument("Mabel", ReturnValues.FORMOBJECTS_FROM_NAME);

        //all forms on page 5 called Mabel
        returnValues = formUtils.getFormComponentsFromPage("Mabel", ReturnValues.FORMOBJECTS_FROM_NAME, 5);

        //form with PDF Reference
        returnValues = formUtils.getFormComponentsFromDocument("25 0 R", ReturnValues.FORMOBJECTS_FROM_REF);

        //form with PDF Reference on page 5
        returnValues = formUtils.getFormComponentsFromPage("25 0 R", ReturnValues.FORMOBJECTS_FROM_REF, 5);

        //if you need direct access to the GUI components, you can use
        //(this will also trigger resolving these objects if Swing so we recommend you work
        //with FormObjects unless you explicitly need this)
        returnValues = formUtils.getFormComponentsFromDocument(null, ReturnValues.GUI_FORMS_FROM_NAME);
        returnValues = formUtils.getFormComponentsFromPage(null, ReturnValues.GUI_FORMS_FROM_NAME, 5);
    }
} catch (PdfException e) {
    e.printStackTrace();
} finally {
    formUtils.closePDFfile();
}

XFA XMLデータ

PdfFormUtilitiesを使用すると、PDFから生のXFAデータを抽出することもできます。

final PdfFormUtilities formUtils = new PdfFormUtilities("inputFile.pdf");
try {
    if (formUtils.openPDFFile()) {
        final byte[] xfaConfig = formUtils.getRawXFAData(PdfDictionary.XFA_CONFIG);
        final byte[] xfaDataSet = formUtils.getRawXFAData(PdfDictionary.XFA_DATASET);
        final byte[] xfaTemplate = formUtils.getRawXFAData(PdfDictionary.XFA_TEMPLATE);
    }
} catch (PdfException e) {
    e.printStackTrace();
} finally {
    formUtils.closePDFfile();
}