Report Table of Contents fails when transforming word to pdf
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I create a report (mlreportgen.dom) with a word template. At the end I want to show only a pdf-version, not the word-document. I tried what was said in https://de.mathworks.com/matlabcentral/answers/17041-converting-word-file-report-to-pdf-file but then my Table of contents is not showing anymore. When I use rptview(doc.OutputPath,'pdf'); it opens the word AND pdf, but i only want the pdf. I can close the word but then it always shows up for a second until its closed again. Code for proof that TOC is missing:
import mlreportgen.dom.*;
d = Document("mydoc",'docx');
open(d);
title = append(d, Paragraph('My TOC Document'));
title.Bold = true;
title.FontSize = '28pt';
toc = append(d,TOC(2,' '));
toc.Style = {PageBreakBefore(true)};
h1 = append(d,Heading1('Chapter 1'));
h1.Style = {PageBreakBefore(true)};
p1 = append(d,Paragraph('Hello World'));
h2 = append(d,Heading2('Section 1.1'));
h2.Style = {PageBreakBefore(true)};
p2 = append(d,Paragraph('Another page'));
close(d);
% rptview(d.OutputPath);
docview("mydoc.docx",'convertdocxtopdf','closeapp');
open(outputPath+"PerformanceReport.pdf")
0 commentaires
Réponse acceptée
Akshat
le 1 Oct 2023
Modifié(e) : Akshat
le 1 Oct 2023
Hi @F Schmid
I understand that you are facing issues in adding Table of Contents when transforming Word to PDF. I examined the attached code and was able to reproduce the issue on my end. On investigating the requirements mentioned in the question, I determined a workaround to address the issue which adds an option 'updatefields' alongside the additional options specified in the 'docview' function. Therefore, the updated line of code is as follows
docview("mydoc.docx",'updatefields','convertdocxtopdf','closeapp');
By including the 'updatefields' option, the Table of Contents will be properly generated in the PDF version of report.
Read more about the operations that can be performed in Word using the 'docview' function from the following link.
I hope this helps.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Platform and License dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!