Create fillable PDF forms using Report generator programatically
3 次查看(过去 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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 MATLAB Report Generator 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!