Create fillable PDF forms using Report generator programatically
8 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Saffan
on 12 Sep 2023
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 Comments
See Also
Categories
Find more on MATLAB Report Generator in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!