Create fillable PDF forms using Report generator programatically

조회 수: 6 (최근 30일)
Karteek Popuri
Karteek Popuri 2022년 8월 2일
답변: Saffan 2023년 9월 12일
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.

답변 (1개)

Saffan
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:

카테고리

Help CenterFile Exchange에서 Report Generator Creation에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by