Save Live Script automatically as PDF

199 ビュー (過去 30 日間)
Jana Pecke
Jana Pecke 2020 年 11 月 16 日
コメント済み: Pierre Harouimi 2024 年 8 月 26 日
Hello everyone,
I have a problem!
I wrote a program for the calculation of test data in the App Designer. The test results of the test person should be given to them in a report. Since I do not have access to the report generator, I have compiled the results in a live script and output them. I have set the button on the right to "hide code" and to save I press "save" and then "export to pdf".
Since I would like to compile the program as a standalone program, I cannot press the buttons myself and save the live script as a PDF.
I already tried the following:
matlab.internal.liveeditor.executeAndSave (which ('Handout.mlx'));
matlab.internal.liveeditor.openAndConvert ('Handout.mlx', 'test.pdf');
Unfortunately, the code is always displayed there! But the design fits :-)
Is there another way to automatically save the LiveScript as PDF without code?

採用された回答

Martin Knelleken
Martin Knelleken 2021 年 3 月 25 日
Hi Jana,
Thanks for using the Live Editor!
Actually, your workflow is expected to work. Unfortunately, there is a known issue that the 'Hide Code' state is not reliably stored with the document when no other edit opereation is made. We're working on fixing that bug.
As a workaound, you should try again to switch to Hide Code View and additionally make another change to the document. E.g. type a charachter and delete it. Then save. If you now close and reopen the Live Script, it should appear in 'Hide Code' mode.
With that, openAndConvert should export it properly without code.
Btw, I strongly recommend to not use openAndConvert and executeAndSave! Those functions were made for internal purposes and can be changed or removed at any time. Furthermore, they're not bullet-proof tested and may behave unexpectedly or wrongly.
However, since you're using it anyway, there is another solution for your worklfow. You can call
matlab.internal.liveeditor.openAndConvert ('Handout.mlx', 'test.pdf', 'HideCode', true);
With that additional argument, it always exports without code, regardless of the state of the document.
Again, be careful with using openAndConvert. Don't rely on its stability or existence in upcoming releases,
We're actively working on a public and well documented API to export Live Scripts programmatically. Stay tuned.
I hope, some of this helps.
Kind regards
- Martin
  2 件のコメント
steve l
steve l 2022 年 1 月 13 日
If we're not supposed to use openAndConvert and executeAndSave what are we supposed to use?
Martin Knelleken
Martin Knelleken 2022 年 1 月 24 日
@steve l: Actually, there is no alternative yet. We're working on a replacement for both. It will come in one of the very next releases. If the internal functions above fulfil your needs, you can continue to usem them for the time being. Just be aware of the potential weknesses mentioned above.

サインインしてコメントする。

その他の回答 (2 件)

Sahithi Kanumarlapudi
Sahithi Kanumarlapudi 2020 年 11 月 18 日
Hi,
From your question I understand that you would like to store the output of a live script without the code. If that is what you are intending to do you can use the 'publish()' function to view the output in html format.
You can refer to the below link to find more info and examples on how to use publish function
Hope this helps!
  1 件のコメント
Jana Pecke
Jana Pecke 2020 年 11 月 19 日
thank you for your Answer.
It works that i dont see my Code but I also can not see my predesigned things like headings and co...
do you have another idear?

サインインしてコメントする。


Pierre Harouimi
Pierre Harouimi 2023 年 4 月 3 日
You can now use (since R2022a release) the export function:
pdffile = export("myscript.mlx","myconvertedpdffile.pdf")
  2 件のコメント
Mukesh Soni
Mukesh Soni 2024 年 8 月 26 日
export from within the mlx file doesn't save/export the latest run output..
it is very frustrating.
Pierre Harouimi
Pierre Harouimi 2024 年 8 月 26 日
It is possible to save the latest run, by using:
currentDoc = matlab.desktop.editor.getActive;
currentDoc.save;
% And then hide the code if you want
export(matlab.desktop.editor.getActiveFilename,HideCode=true)
However, I wouldn't use neither save neither export within the file, except you don't have any other solution.
I'd use:
matlab.internal.liveeditor.executeAndSave('filename.mlx')
export('filename.mlx')

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by