Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read TOC and PreserveText #2293

Closed
Faridabdallah01 opened this issue Sep 13, 2022 · 0 comments
Closed

Read TOC and PreserveText #2293

Faridabdallah01 opened this issue Sep 13, 2022 · 0 comments

Comments

@Faridabdallah01
Copy link

Faridabdallah01 commented Sep 13, 2022

Hello,

Thank you for your time.

Here is the bug encounter

  • TOC consider as an instance of PerserveText
  • Unable to retrieve the contents of my table of contents

I would like to read a summary in a word document.

Steps to Reproduce

<?php
require __DIR__ . '/vendor/autoload.php';

use PhpOffice\PhpWord\Element\PreserveText;
use Symfony\Component\HttpFoundation\JsonResponse;

$phpWord = IOFactory::load($file->getRealPath());
$sections = $phpWord->getSections();
$paragraphs = [];
  foreach ($sections as $section) {
            foreach ($section->getElements() as $elementValue) {
                if($elementValue instanceof PreserveText) {
                    $paragraphs[] = $elementValue->getText();
                }
         }  
 }
return new JsonResponse($paragraphs);

Expected

I would like to retrieve the table of contents (if possible with the link) otherwise only the content.

Current

When I try to retrieve the content, to at least display the table of contents, i have this result (JsonResponse):

"{ TOC \\o &quot;1-1&quot; \\h \\z \\u }"

image

Context

  • PHP Version: 8.1
  • PHPWord Version: 0.18.3
  • Symfony 5.4

Thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant