Create fillable PDF forms using Report generator programatically
조회 수: 6 (최근 30일)
이전 댓글 표시
I am looking for pointers for creating fillable PDF forms using the MATLAB Report Generator toolbox. Attached is a sample of the kind of fillable PDFs that I would like to generate.
댓글 수: 0
답변 (1개)
Saffan
2023년 9월 12일
Hi Karteek,
To create fillable PDF forms, you can utilize the report generator to create a template with designated "holes" for the input values. These "holes" act as placeholders where the data can be inserted. Here is an example code snippet that demonstrates how to create a template with "holes":
import mlreportgen.dom.*;
type = 'pdf';
% Create a template object
t = Template('mytemplate', type);
% Create a paragraph for the name field
p = Paragraph();
append(p, 'Name:');
append(p, TemplateHole('NAME'));
append(t, p);
% Create a paragraph for the weight field
p = Paragraph();
append(p, 'Weight:');
append(p, TemplateHole('WEIGHT'));
append(t, p);
% Create a paragraph for the height field
p = Paragraph();
append(p, 'Height:');
append(p, TemplateHole('HEIGHT'));
append(t, p);
% Create a paragraph for the BMI field
p = Paragraph();
append(p, 'BMI:');
append(p, TemplateHole('BMI'));
append(t, p);
close(t);
Once you have created the template, you can proceed to fill in the data and generate PDF documents. Here is an example code snippet:
rpt = Document('MyForm', type, 'mytemplate');
open(rpt);
% Create a loop to cycle through the holes
while(~strcmp(rpt.CurrentHoleId, '#end#'))
switch(rpt.CurrentHoleId)
case 'NAME'
append(rpt, 'My Name');
case 'WEIGHT'
append(rpt, '63');
case 'HEIGHT'
append(rpt,'175');
case 'BMI'
append(rpt,'23')'
end
moveToNextHole(rpt);
end
% Generate and view the report
close(rpt);
rptview(rpt.OutputPath);
Please refer to this for more information:
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!