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

Inquiry on PHPWord Features for TOC, Tiny Editor, Margin, image ,and Page Numbers in DOCX Generation #2521

Open
Khushboo75 opened this issue Dec 5, 2023 · 0 comments

Comments

@Khushboo75
Copy link

Khushboo75 commented Dec 5, 2023

<?php
require "vendor/autoload.php";

use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\IOFactory;
use PhpOffice\PhpWord\Element\TextRun;
use PhpOffice\PhpWord\Element\TOC;
use PhpOffice\PhpWord\SimpleType\Jc;
use PhpOffice\PhpWord\Style\ListItem;

$phpWord = new PhpWord();
$phpWord->setDefaultFontName('Calibri');
$phpWord->setDefaultFontSize(12);

$marginSettings = [
    'marginLeft' => 720,
    'marginRight' => 720,
    'marginBottom' => 720,
    'marginTop' => 720,
];

$apiUrl = 'https://jsonplaceholder.typicode.com/photos';
$response = file_get_contents($apiUrl);

$data = json_decode($response, true);

$section = $phpWord->addSection($marginSettings);
/*
* ISSUE- 1: Dynamic page numbers are not rendering appropriately within the Table of Contents (TOC) section (issue is uncommented)
*/

$section->addTOC(array('tabPos' => 720, 'hanging' => 360));

$section->addTitle('Test 1', 1, 5);
for ($i = 0; $i < 10; $i++) {
    $item = $data[$i];

    $html = '<p><strong>Album ID:</strong> ' . $item['albumId'] . '</p>' .
        '<p><strong>ID:</strong> ' . $item['id'] . '</p>' .
        '<p><strong>Title:</strong> ' . $item['title'] . '</p>' .
        '<p><strong>URL:</strong> ' . $item['url'] . '</p>';
    /*
        * ISSUE-2: image is not working (issue is commented)
        */

    // '<p><strong>Thumbnail URL:</strong> <img src="' . $item['thumbnailUrl'] . '" alt="Thumbnail"></p>';
    /*
        * ISSUE-3 : We would also use the image but it was not working (issue is commented)
        */


    // <img src="data:' . $self_service_img["img_type"] . ';base64,' .  $item['thumbnailUrl']  . '" width="657" height="830" alt="Self Service Digitalization with CLaaS@Work Image"/>


    \PhpOffice\PhpWord\Shared\Html::addHtml($section, $html);
}
$section->addPageBreak();


// Add a title
$section->addTitle('Test 2', 1, 5);
/*
        * ISSUE- 4 : Tiny Editor code is not working after creating the file (issue is commented)
        */

// $html =
//     '<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. 
// Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer 
// took a galley of type and scrambled it to make a type specimen book. It has surviv Ipsum \"Digital Marketing\" Lorem 
// Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy 
// text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen, but also 
// the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of
//  Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker 
//  including versions of Lorepsum.</p>\n<p>The course \"Digital Transformation\" covers a comprehensive set of instructional 
//  units that empower learners to navigate the digital realm successfully. In the unit \"Innovative Venture Creation,\" Lorem 
//  Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text
//   ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has 
//   survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in
//    the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like 
//    Aldus PageMaker including versions of Lorem Ipsum.</p>\n<p>The unit on \"Business Model Innovation\" explores how businesses can adapt their
//     existing models to address digital disruptions and changing consumer behaviors. Learners analyze and redesign business models, leveraging digital 
//     technologies and emerging trends to ensure sustainability and competitiveness in the market.
    


/*
        * ISSUE- 5 :"&" letter   is not working after creating the file (issue is commented)
        */
// $html ='<p>>Lorem Ips & </p>';
// Add the HTML content to the section
\PhpOffice\PhpWord\Shared\Html::addHtml($section, $html);


$file = 'test.docx';
$objWriter = IOFactory::createWriter($phpWord, 'Word2007');
$objWriter->save($file);

header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . $file . '"');
header('Content-Length: ' . filesize($file));

readfile($file);
@Khushboo75 Khushboo75 changed the title Inquiry on PHPWord Features for TOC, Tiny Editor, Margin, and Page Numbers in DOCX Generation Inquiry on PHPWord Features for TOC, Tiny Editor, Margin, image ,and Page Numbers in DOCX Generation Dec 6, 2023
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