Page 1 of 1

Wrapping text around images and managing image captions

Posted: 28 Jul 2016, 13:49
by cwdee
Hi

I am trying to use PhocaPDF to allow certain articles from my site to be downloaded as a PDF. As a basic function it works, but I am having two problems with the layout.

1) The text is not wrapped around the image as it is in th eHTML. Is that even possible? If so how do I make PhocaPDF do that?

2) The image captions are rendered inline with all the other text. The HTML structure for captioned images is created with JCE-caption like:

Code: Select all

<span class="wf_caption" ... >
<img src="..." />
<span>CAPTION TEXT</span>
</span>
Is there anyway to influence how the caption text is presented in the PDF (or even suppress it from the PDF)?

Thanks, Chris

Re: Wrapping text around images and managing image captions

Posted: 28 Jul 2016, 22:49
by Jan
Hi,

1) see the red warning box:
https://www.phoca.cz/phocapdf
HTML is dynamic document, PDF is static document, not every dynamic features can be transformed to PDF :-(

2) I think, that only way is to somehow customize the TCPDF library, which is a library which creates the PDF (tries to transform HTML to PDF)
:idea:

Jan

Re: Wrapping text around images and managing image captions

Posted: 29 Jul 2016, 11:12
by cwdee
Thanks. Where exactly in the PhocaPDF code is the article content passed to TCPDF? Maybe there I could catch the image caption and remove orreformat. Maybe wrapping the image and its caption in a table might work.

Thanks, Chris

Re: Wrapping text around images and managing image captions

Posted: 31 Jul 2016, 15:53
by Jan
Hi, not sure if I understand?
Where exactly in the PhocaPDF code is the article content passed to TCPDF?
Phoca PDF sends the HTML output into the TCPDF class which then tries to transform the html to the fixed design in PDF :idea:

Jan

Re: Wrapping text around images and managing image captions

Posted: 31 Jul 2016, 20:28
by cwdee
Yes, which piece of PhocaPDF code does this? I assume I can manipulate the HTML before it is sent.

Thanks, Chris

Re: Wrapping text around images and managing image captions

Posted: 02 Aug 2016, 14:40
by Jan
Hi, then see the plugin for content:

Phoca PDF Content plugin:
plugins/phocapdf/content.php and see the $documentOutput variable.

Jan

Re: Wrapping text around images and managing image captions

Posted: 04 Aug 2016, 18:30
by cwdee
Thanks, that really helped.

I have improved the rendering substantially by including the following, to wrap the image in a paragraph and wrap and style the immediately following span element :

Code: Select all

// Style JCE captions
$pattern = '/(<img.*>)\s?(<span.*>.*<\/span>)/';
$replacement = '<p>$1</p><p style="font-size: 0.75em;"><i>$2</i></p>';
$documentOutput = preg_replace($pattern, $replacement, $documentOutput);
It is probably not bomb-proof but produces a better PDF than without.

Ideally JCE Caption would tag the inserted span, maybe with a unique class, so that it can be detected.

Chris

Re: Wrapping text around images and managing image captions

Posted: 07 Aug 2016, 21:52
by Jan
Hi, thank you for the guide.

Jan