Report Table of Contents fails when transforming word to pdf

2 visualizaciones (últimos 30 días)
F Schmid
F Schmid el 28 de Sept. de 2023
Editada: Akshat el 1 de Oct. de 2023
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")

Respuesta aceptada

Akshat
Akshat el 1 de Oct. de 2023
Editada: Akshat el 1 de Oct. de 2023
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.

Más respuestas (0)

Etiquetas

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by