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

Loading document with TOC: BadMethodCallException (Cannot add PreserveText in Section.) #501

Open
lorenzadefanti opened this issue Mar 16, 2015 · 1 comment

Comments

@lorenzadefanti
Copy link

lorenzadefanti commented Mar 16, 2015

Hello,

I'm generating a docx document from HTML with a table of contents.
The docx document is saved correctly, but when I try to generate a PDF from this docx, it doesn't work.

Generating the docx:

$phpWord = new PhpWord();

$titleSection = $phpWord->addSection();
Html::addHtml($titleSection, 'some title text');
$titleSection->addPageBreak();
$titleSection->addTitle('');
$titleSection->addTOC();

foreach ($stepContents as $stepContent) {
    $section = $phpWord->addSection();
    $footer = $section->addFooter();
    $footer->addPreserveText('p. {PAGE}');
    $html = $stepContent->getValue();
   Html::addHtml($section, $html);
}

Saving the docx:

$fileDir = "/tmp/";
$fileName = "filename.docx";
$file = $fileDir . $fileName;

$phpWord->save($file, "Word2007");

Generating the pdf:

if ($format == "pdf") {
    Settings::setPdfRenderer(Settings::PDF_RENDERER_TCPDF, './vendor/tecnick.com/tcpdf');

    $pdfPhpWord = IOFactory::load($file);

    $pdfFileName = "filename.pdf";
    $pdfFile = $fileDir . $pdfFileName;

    $pdfWriter = IOFactory::createWriter($pdfPhpWord, 'PDF');
    $pdfWriter->save($pdfFile, 'PDF');

    $content = file_get_contents($pdfFile);
}

This line: $pdfPhpWord = IOFactory::load($file); produces an error, independently of which PDF-Renderer I choose (I've tried with dompdf and mpdf too).

load error

If I delete the TOC-line, I can generate the PDF correctly.


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If this is still an issue for you, please try to help by debugging it further and sharing your results.
Thank you for your contributions.

@github-actions github-actions bot added the Stale label Nov 18, 2022
@Progi1984 Progi1984 removed the Stale label Nov 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants