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

Captions for Images/Tables #809

Open
kilianweisl opened this issue Aug 19, 2024 · 6 comments
Open

Captions for Images/Tables #809

kilianweisl opened this issue Aug 19, 2024 · 6 comments

Comments

@kilianweisl
Copy link

Hello!

I'd like to add captions to images or tables.

I couldn't find anything in the docs.
Either it's possible to get the height of a dynamic shape after filling it (like adding rows to a table) or there is a solution implemented already.

For images, I could also pre-calculate the height when drawing the image with a specific width (considering its aspect-ration), but getting the height via the library would be much more convenient.

Many thanks in advance!

@Progi1984
Copy link
Member

@kilianweisl Hi have you got a sample file as expected result for analysis ?
Thanks

@kilianweisl
Copy link
Author

@Progi1984 Sure! Thanks for the fast reply.

Suppose I have the following code:

  public function createTable()
  {
    $pptx = new PhpPresentation();
    $slide = $pptx->getActiveSlide();

    $shape = $slide->createTableShape(3);
    $shape->setWidth(Converter::convertEmuToPx($pptx->getLayout()->getCX()) - 20);
    $shape->setOffsetX(10);
    $shape->setOffsetY(10);

    for($rowCount = 0; $rowCount < 3; $rowCount++) {
      $row = $shape->createRow();
      for($cellCount = 0; $cellCount < 3; $cellCount++) {
        $cell = $row->nextCell();
        $cell->createTextRun('Cell ' . $cellCount)
          ->getFont()
          ->setSize(20);
      }
    }

    $writer = IOFactory::createWriter($pptx, 'PowerPoint2007');
    $writer->save('./table.pptx');
  }

The output .pptx file is:

Screenshot 2024-08-19 at 17 29 58

Now the problem is, I don't know how many rows my table has and I need to add a caption below it like so:

Screenshot 2024-08-19 at 17 31 43

How can I get the final height of the table (after adding all rows) in order to place a text object afterwards?

This might also include splitting the table and printing them on multiple slides, as mentioned in #72.

@Progi1984
Copy link
Member

@kilianweisl Could you send me a sample docx file with expected result ? I want to analyze the file. Thanks

@kilianweisl
Copy link
Author

Do you mean the pptx file? It's just a bunch of rows and a text underneath it.

table.pptx

@Progi1984
Copy link
Member

Oh. I didn't understand it. I think you must all calculate : font size, margin, border size, etc...

@kilianweisl
Copy link
Author

While that'd be somehow possible with simple tables, I don't think that it is possible when you e.g. have the following case, where an arbitrary column contains text that forces a line break.

Or is there a way to access the height of a cell/row/RichTextShape after putting text into it?

Screenshot 2024-08-19 at 18 09 30

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