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

Problem: read header and footer in documents #293

Open
hp3k opened this issue Jun 26, 2014 · 10 comments
Open

Problem: read header and footer in documents #293

hp3k opened this issue Jun 26, 2014 · 10 comments

Comments

@hp3k
Copy link

hp3k commented Jun 26, 2014

How to get header and footer in documents and parse to html?


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

@hp3k
Copy link
Author

hp3k commented Jun 26, 2014

I have a PHP code:

<?php
if(isset($_FILES['document'])){
    include 'fileupload.php';
    $source = 'upload/'.$_FILES['document']['name'];
    echo date('H:i:s'), " Reading contents from `{$source}`", EOL;
    $phpWord = \PhpOffice\PhpWord\IOFactory::load($source);
    print_r($phpWord);

}
  1. I have exception in docx document:
    uploaded12:33:19 Reading contents from upload/generate_file.docx

( ! ) Fatal error: Uncaught exception 'PhpOffice\PhpWord\Exception\InvalidImageException' in C:\wamp\www\src\PhpWord\Element\Image.php on line 371

( ! ) PhpOffice\PhpWord\Exception\InvalidImageException: in C:\wamp\www\src\PhpWord\Element\Image.php on line 371

Call Stack

Time

Memory

Function

Location

1 0.0006 248248 {main}( ) ..\Sample_32_Coig.php:0
2 0.0058 347992 PhpOffice\PhpWord\IOFactory::load( ) ..\Sample_32_Coig.php:53
3 0.0072 404328 PhpOffice\PhpWord\Reader\Word2007->load( ) ..\IOFactory.php:73
4 0.0293 1118552 PhpOffice\PhpWord\Reader\Word2007->readPart( ) ..\Word2007.php:69
5 0.0300 1168512 PhpOffice\PhpWord\Reader\Word2007\Document->read( ) ..\Word2007.php:93
6 0.0402 1632888 PhpOffice\PhpWord\Reader\Word2007\Document->readWPNode( ) ..\Document.php:57
7 0.0402 1632888 PhpOffice\PhpWord\Reader\Word2007\AbstractPart->readParagraph( ) ..\Document.php:157
8 0.0412 1634360 PhpOffice\PhpWord\Reader\Word2007\AbstractPart->readRun( ) ..\AbstractPart.php:175
9 0.0415 1634920 addImage ( ) ..\AbstractPart.php:222
10 0.0415 1635256 PhpOffice\PhpWord\Element\AbstractContainer->__call( ) ..\AbstractPart.php:222
11 0.0416 1641912 call_user_func_array:{C:\wamp\www\src\PhpWord\Element\AbstractContainer.php:101} ( ) ..\AbstractContainer.php:101
12 0.0417 1642312 PhpOffice\PhpWord\Element\AbstractContainer->addElement( ) ..\AbstractContainer.php:101
13 0.0425 1746592 newInstanceArgs ( ) ..\AbstractContainer.php:138
14 0.0425 1747896 PhpOffice\PhpWord\Element\Image->__construct( ) ..\AbstractContainer.php:138
15 0.0430 1809040 PhpOffice\PhpWord\Element\Image->checkImage( ) ..\Image.php:129
2) I have a problem. I can't read headers and footers.
Help me please

@ivanlanin
Copy link
Contributor

  1. Can you view the images in upload/generate_file.docx using a word processor?
  2. Headers and footers can be read from DOCX (see Sample_11_ReadWord2007.php), but they're not written to HTML.

@hp3k
Copy link
Author

hp3k commented Jul 1, 2014

Okey, but how to get footer and header tekst and settings and assign to array or parse to html?

@ivanlanin
Copy link
Contributor

Good question. From the object model, you can use getHeaders and getFooters method of a section, but it will be cumbersome. So the final result that you want is to have the content of footers and headers as HTML?

@hp3k
Copy link
Author

hp3k commented Jul 2, 2014

Yes I don't know how I can get header and footer also how I can get values?

@rajeshbabu54
Copy link

Hello everyone,
I want to add some images and text to existing docx in phpword.I tried with the following code but it is not showing correct.

include_once 'Sample_Header.php';
// New Word document
$name = basename(FILE, '.php');
$source = DIR . "/resources/{$name}.docx";
//$phpWord = new \PhpOffice\PhpWord\PhpWord();
$phpWord1 = \PhpOffice\PhpWord\IOFactory::load($source);
$document = $phpWord1->loadTemplate($source);
$document->saveAs('temp.docx');
$phpWord = \PhpOffice\PhpWord\IOFactory::load('temp.docx');
$section = $phpWord->addSection();
$section->addText(htmlspecialchars('Local image without any styles:'));
$section->addImage('resources/_mars.jpg');
$section->addTextBreak(2);
$source = 'https://php.net/images/logos/php-med-trans-light.gif';
$section->addText(htmlspecialchars("Remote image from: {$source}"));
$section->addImage($source);
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord , 'Word2007');
$xmlWriter->save('result1234566.docx');

Please send me the code. Please help me out from this problem

Thank you

Rajesh babu

@ascendedcrow
Copy link

ascendedcrow commented Aug 15, 2017

I Get this error when replacing the attached docx with the code, even when fixing it, the images gets lost in saving the file:
`<?php
include_once 'Sample_Header.php';

// Read contents
$name = basename(FILE, '.php');
$source = "D:\Temp\Letterhead.docx";

echo date('H:i:s'), " Reading contents from {$source}", EOL;
$phpWord = \PhpOffice\PhpWord\IOFactory::load($source);

// Save file
echo write($phpWord, basename(FILE, '.php'), $writers);
if (!CLI) {
include_once 'Sample_Footer.php';
}`

Warning: Division by zero in D:\Work\Test\PHPWebProject1\PHPWebProject1\vendor\phpoffice\phpword\src\PhpWord\Writer\ODText\Style\Paragraph.php on line 41

Letterhead.docx

@94sukhbrar
Copy link

Hi
Please tell me how I read the content of the .doc or .docxfile.

@gaby64
Copy link

gaby64 commented Jun 27, 2022

Good question. From the object model, you can use getHeaders and getFooters method of a section, but it will be cumbersome. So the final result that you want is to have the content of footers and headers as HTML?

Could we have a HTML writer that outputs as pages, with headers and footers?

@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
Development

No branches or pull requests

7 participants