watermark on pdf report in deployed app will not work

1 回表示 (過去 30 日間)
Martin Jensen
Martin Jensen 2023 年 12 月 21 日
回答済み: Venkat Siddarth Reddy 2023 年 12 月 26 日
Following code for the watermark will not work in deployed app, but works fine in matlab app designer:
import mlreportgen.dom.*
%--------------------------------------------------------------------------
CustomProjName = compose("%s",app.Customer_ProjectName);
rpt = Document(CustomProjName,"pdf");
open(rpt);
currentLayout = rpt.CurrentPageLayout;
currentLayout.PageSize.Height = "297mm";
currentLayout.PageSize.Width = "210mm";
currentLayout.PageSize.Orientation = "portrait";
currentLayout.PageMargins.Top = '0.0mm';
wm = mlreportgen.dom.Watermark('Hexagons_word_GP_v4.png');
wm.Width = '205mm';
wm.Height = [];
rpt.CurrentPageLayout.Watermark = wm;

回答 (1 件)

Venkat Siddarth Reddy
Venkat Siddarth Reddy 2023 年 12 月 26 日
I understand that you are trying to add watermark to a report and generate it using MATLAB App designer. However, the above code is working in MATLAB App Designer, but not in the deployed/complied application.
From the code provided, I observed that the watermark image path given is just the file name.So please verify the following:
  • Check the working directory when the app is deployed. The working directory might be different from the development environment. Therefore you may need to change the file location to the working directory or provide the full path to the water mark image
  • Try adding try-catch block, this might help identifying the specific issue:
try
% Add existing code here
disp('Watermark added successfully');
catch ME
% Display an error message
disp('Error adding watermark:');
disp(ME.message);
end
To know more about error handling in MATLAB, please refer to the following documentation:
I hope this resolves the issue

Community Treasure Hunt

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

Start Hunting!

Translated by