まず、私はあなたの質問の一部1に取り組みます:Adobe Acrobatの通過pdfmarkの式でPostScript言語プログラムを実行することによって、そのようなPDFフォームファイルを作成します蒸留酒など。以下のサンプルプログラムを参照してください。
あなたが読んだ「PDFMARKドキュメント」はpdfmark Referenceでした。私のコピーは2006年11月の日付です。例5.11 文書カタログでAcroForm辞書を定義と5.12 このフォームのフィールド辞書であるウィジェットアノテーションを定義します。 70-75。コードを注意深く読んで、ソースファイルにコピーして蒸留し、修正してください。それは私のサンプルが基づいています。
慎重に第1章の紹介(p.9-16)を読んでください。これは、例5.11および5.12のpdfmark構文を読むのに役立ちます。 という名前のオブジェクト(p。12-16)は、例のフォントとエンコーディングがどのように参照されているかを理解するために重要です。
しかし、PDF言語仕様も読む必要があります。スペックのAdobeのコピーは、ISO規格に取って代わられているPDF 32000-1:2008 Document management — Portable document format — Part 1: PDF 1.7読むセクション12.7 インタラクティブフォームのコントロールについては、セクション12.5 注釈(頁381から414)にあなたを参照してください頻繁ます(頁430から456)、フォームフィールドの外観について
重要なことは、ほとんどのフォームフィールドは、PostScript言語の[ ... /ANN pdfmark
式で提供されるキーと値のペアによって定義されることです。キーと値のペアは、pdfmarkの仕様ではなく、PDF仕様で指定されています。しかし、PDF仕様を読んでいる間はpdfmark式を編集するのは簡単です。
次のプログラムは、フォームフィールドを持つPDFファイルに蒸留:
% Simple pdfmark form example
% by Jim DeLaHunt, jdlh.com, 3. March 2012
%
% This PostScript language code, when converted to PDF by
% Adobe Acrobat Distiller or the like, creates a PDF file with form
% fields, and a Submit button which sends the values of the fields
% via an HTTP POST request.
%
% In reply to Stack Overflow question, "How can I create a PDF form
% using PDFMARK and/or PERL cpan module PDF::API2?",
% http://stackoverflow.com/questions/9440930/
%
% Define stubs for interpreters without pdfmark support
% From pdfMark reference, Example 1.2, p.10
/pdfmark where {
% pdfmark is built-in
% define {code} ?pdfmark - : exec modal PDF code.
pop globaldict /?pdfmark /exec load put
}{
globaldict begin
/?pdfmark /pop load def% pdfmark is absent: ignore code.
/pdfmark /cleartomark load def
end
} ifelse
%%EndProlog
% This code makes the example clearer. It isn't part of the AcroForm.
<</PageSize [300 300]>> setpagedevice % smaller page (~ 10cm x 10cm)
clippath 0.9 setgray fill % light grey background, to show widgets.
/Helvetica-Bold 12 selectfont 0 setgray % for labels
/showlabel { % (text) x y showlabel -
% shows (text) top-justified at x,y, moves down one line
-12 add moveto % x y -12 add moveto -
gsave show grestore
0 -3 rmoveto % leading (space between lines)
} def
/showcomment { % (text) showcomment -
% shows (text) top-justified at current point, moves down 1 line
0 -10 rmoveto
gsave /Helvetica 10 selectfont show grestore
0 -2 rmoveto % leading (space between lines)
} def
(Simple pdfmark form example) 10 290 showlabel
% AcroForm dictionary setup. From pdfmark Reference, Example 5.11, p.70
%
% Read also PDF specification PDF32000:2008
% "Document management — Portable document format — Part 1: PDF 1.7",
% Section 12.7 "Interactive Forms", p.430
% To understand the syntax: [/_objdef {foo} /type /dict /OBJ pdfmark
% read carefully pdfMark reference, "User-defined named objects", p.13.
% Define font objects for the widgets to use
[ /_objdef {ZaDb} /type /dict /OBJ pdfmark
[ {ZaDb} <<
/Type /Font
/Subtype /Type1
/Name /ZaDb
/BaseFont /ZapfDingbats
>> /PUT pdfmark
[ /_objdef {Helv} /type /dict /OBJ pdfmark
[ {Helv} <<
/Type /Font
/Subtype /Type1
/Name /Helv
/BaseFont /Helvetica
% /Encoding {pdfDocEncoding} % for simplicity, use font's own encoding
% pdfmark Reference, Example 5.11, p.70, provides an Encoding
% array defining PDFDocEncoding
>> /PUT pdfmark
[ /_objdef {aform} /type /dict /OBJ pdfmark
% Define Fields array of Acroform dictionary. It will contain entries for
% each of the widgets defined below.
% NOTE: It is not necessary to explicitly assign the widget annotations
% to the Fields array; Acrobat does it automatically when the file is
% opened.
[ /_objdef {afields} /type /array /OBJ pdfmark
[ {aform} <<
/Fields {afields}
/DR << /Font << /ZaDb {ZaDb} /Helv {Helv} >> >>
/DA (/Helv 0 Tf 0 g)
/NeedAppearances true
% "/NeedAppearances true" tells reader 'to construct appearance
% streams and appearance dictionaries for all widget annotations
% in the document...' --PDF32000:2008 Table 218 p.431
>> /PUT pdfmark
% Put Acroform entry in catalog dictionary
[ {Catalog} << /AcroForm {aform} >> /PUT pdfmark
% Example 5.12 Define the Widget annotations
% pdfmark Reference pp. 72-75, with clarifications by Jim DeLaHunt
%
% These Widget annotations are also field dictionaries for this form.
% This is the collection of all individual widget annotations.
% It is possible to have multiple instances of these sections, such as
% for defining a single widget on each instance.
%
% See PDF32000:2008 Section 12.5.6.19 "Widget Annotations", p.408
% especially tables 188 and 189.
(/Tx text field) 10 260 showlabel
(with Javascript) showcomment (validation) showcomment
[ /Subtype /Widget
/Rect [100 223 245 260]
/F 4
/T (SL Text)
/FT /Tx
/DA (/Helv 14 Tf 0 0 1 rg)
/V (5)
/AA <<
/K <<
/S /JavaScript
/JS (AFNumber_Keystroke\(2, 0, 0, 0, "$", true\);)
>>
/F <<
/S /JavaScript
/JS (AFNumber_Format\(2, 0, 0, 0, "$", true\);)
% pdfmark Reference p.72 seems to omit closing ")" above. Oops.
>>
>>
/ANN pdfmark
(/Btn field) 10 208 showlabel
(Check Box) showcomment
[ /Subtype /Widget
/Rect [100 172 136 208]
/F 4
/T (Check Box)
/FT /Btn
/DA (/ZaDb 0 Tf 0 g)
/AS /Off
/MK << /CA (4)>>
/AP << /N << /Oui /null >> >>
/ANN pdfmark
(/Ch field) 10 160 showlabel
(List Box) showcomment
[ /Subtype /Widget
/Rect [100 87 137 160]
/F 4
/T (List Box)
/FT /Ch
/DA (/Helv 10 Tf 1 0 0 rg)
/Opt [(1)(2)(3)(4)(5)]
/DV (3)
/V (3)
/MK <<
/BG [1 1 1] % Background: white
/BC [0 0 0] % Border colour: black
>>
% MK is 'An appearance characteristics dictionary (see Table 189)'
% --PDF32000:2008 Table 188 p.408
% Without an /MK entry, Acrobat Pro 8.0 complains of an error
% when displaying this field, and some entries aren't displayed.
/ANN pdfmark
(/Btn button) 160 85 showlabel
(/S /SubmitForm action) showcomment
% Example of how the /MK dictionary is used.
[ /Subtype /Widget
/Rect [ 130 10 270 50 ]
/F 4
/T (Submit)
/FT /Btn
/H /P
/A <<
/S /SubmitForm
/F (http://posttestserver.com/post.php) % Thanks, Henry!
/Flags 16#6 % IncludeNoValueFields, ExportFormat
>>
/DA (/HeBo 18 Tf 0 0 1 rg)
/Ff 65536
/MK <<
/BC [ 1 0 0 ]
/BG [ 0.75 0.45 0.75 ]
/CA (Submit)
/AC (Submitted!)
>>
/BS <<
/W 3
/S /I
>>
/ANN pdfmark
% When pressing the Submit button in Adobe Acrobat Professional 8.3.1,
% there is a pause, and then Acrobat displays a PDF file with the
% results of the HTTP POST operation. This is text like,
% Successfully dumped 3 post variables. View it at
% http://www.posttestserver.com/data/2012/03/04/01.29.271751566025
% Post body was 0 chars long.
%
% Browse to that URL, and you will see diagnostics with the following:
% ....
% Post Params:
% key: 'Check_Box' value: 'Oui'
% key: 'List_Box' value: '4'
% key: 'SL_Text' value: '3.14'
% Empty post body.
showpage % make sure a page gets produced
は、PDFリーダーで得られたPDF文書を開きます。フォームの値を変更します。上部のテキストフィールドでは、小数点以下2桁の数値に制限され、数値の前に$
の記号が表示されます。 Javascriptコードでこれを行います。チェックボックスをオンにすると、値Oui
が送信されます。
Submit
ボタンをクリックすると、PDFリーダーは各フォームフィールドのキーとそのフィールドの値を取得し、HTTP POST
コールを使用してURLに送信します。私が使った目的地はHenry's HTTP Post Dumping Serverです。サーバーはPOSTにテキスト応答を返し、サーバーが受け取った内容を見ることができるURLを与えます。 Adobe Acrobat Professionalはこの応答をPDFファイルに変換しますが、これには数秒かかる場合があります。そのURLにアクセスすると、探しているフィールド名と値のペアが表示されます。 PerlモジュールのPDFを使用して
:: API2
私はPerlで非常に経験豊富ではない、と私はPDF::API2 moduleを使用したことがありません。しかし、コード検査から、私はPDF :: API2でPDFフォームを生成するのは簡単ではないと思う。
PDF::API2::Annotサブモジュールは有望です。しかし、上記のサンプルプログラムのメソッドを使用するには、/Subtype /Widget
のPDFアノテーションを作成する必要があります。 が表示されます。PDF :: API2 :: Annotはこれをサポートしていません。
source code of PDF::API2::Annotを見ると、他の注釈タイプをどう扱うかの例が分かります。例えば、リンク注釈の種類は次のようなコードによって部分的に作成されます。
$self->{Subtype}=PDFName('Link');
サポートするウィジェットの注釈たが、一つは$self->{Subtype}=PDFName('Widget')
のような文を見ることを期待します。しかし、このモジュール(バージョン2.019)には文字列Widget
のインスタンスはありません。したがって、ウィジェットアノテーションをサポートするために、このモジュールを拡張する可能性があります。
注釈は、特定の内容のPDF辞書のみです。基本部分のウィジェットアノテーションを構築するには、おそらくPDF::API2::Basic::PDF::Dictを使用することが可能です。しかし、私はこれが拡張するよりももっと多くの仕事をするだろうと推測しています。PDF :: API2 :: Annot。
は、この質問を取る、と恵みはそれが印として、惹か:多くの喜びがあるでしょう、誰かが
PDF :: API2 :: Annotのにウィジェット注釈サポートを追加し、そしておそらく
PDF :: API2を行う場合: :フォームモジュール!
おそらく[このディスカッション](http://stackoverflow.com/questions/4346590/submit-pdf-form-fields-to-a-http-post-request)は役に立ちますか? – raina77ow
明確化:結果のPDFを塗りつぶし可能なフォームにしたいですか? –