Challenges with createPDF plugin

Hi all,

I’m experiencing 2 challenges converting a web page to a PDF using the createPDF Plugin. (The PDF is fine except for these two issues)

1) I’m using highlight_string to display recipes in my CMSB Cookbook with the following code: <?php
$recipe = wordwrap($record['recipe'],140) ;
$recipe = highlight_string($recipe) ;

?>
When both the wordwrap and the highlight_string lines are included in the code, none of the links in the converted PDF work.

When I remove either the wordwrap or highlight_string lines from the code, the links in the converted PDF are live again.

____________________________________________

2) I’m using javascript to change the background color of the page to white before converting it to a PDF. But the background color of the PDF reverts to the original color (#9FF)
<script type="text/javascript">
function changeBGC(color){
document.body.style.backgroundColor = color;
}
</script>
</head>

<body style="background-color:#9FF">


And in the body to change the color: <input type = "button" value = "Change Background Color to White" onclick = changeBGC("white")>

Any ideas?

Thanks,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Challenges with createPDF plugin

By Dave - November 22, 2010

Hi Jerry,

Can you check if those web page features work in Chrome and Safari first? Chrome and Safari both use the 'webkit' browser rendering engine which powers createPDF.

If they both work, the next step would be to create a small test page that demonstrates the problem (smaller the better) and then email me all the details and I'll research this for you.

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Challenges with createPDF plugin

Hi Dave,

Thanks for looking at this.

The result is the same in FF IE Chrome and Safari, but I made an interesting discovery.

The links are not missing, but they seem to be offset. The active area and the link text do not line up. The active area is down and to the right of the text.

It's worse inhttp://www.thecmsbcookbook.com/cookbook.php, the complete page, then it is in the short page, http://www.thecmsbcookbook2.com/cookbook.php

The background color issue is still the same though.

I've attached the short version of the viewer and have sent you login credentials via email.

Thanks again,

Jerry
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Attachments:

cookbook2.php 4K

Re: [gkornbluth] Challenges with createPDF plugin

By Dave - November 24, 2010

Hi Jerry,

To have the page display with a white background for the PDF you can use something like this:

<?php if (@$_REQUEST['pdf']): ?>
<body style="background-color:#FFF">
<?php else: ?>
<body style="background-color:#9FF">
<?php endif ?>


When createPDF loads the page it's as if a new browser is loading the page over again so it won't "remember" any background-color changes previously made with javascript.

It looks like highlight_string() replaces all the spaces with &nbsp;. I updated your code with this to switch them back to spaces:

<?php
$recipe = $record['recipe'];
$recipe = wordwrap($recipe, 140) ;
$recipe = highlight_string($recipe, true);
$recipe = str_replace('&nbsp;', ' ', $recipe);
print $recipe;
?>


My guess is something about the long lines was causing problems with the PDF conversion. Can you take a look and let me know if this works better?

http://thecmsbcookbook.com/cookbook2.php

Let me know how it goes.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Challenges with createPDF plugin

One more quick question, Dave...

I’m using: <a href="#<?php echo $record['num'] ?> and:<a name="<?php echo $record['num'] ?>">&nbsp;</a>as named anchors to navigate a page that has both a table of contents and the corresponding recipes.

The page works fine, but when I convert to a PDF, the anchor links come out as:

http://www.thecmsbcookbook.com//_createPDF_temp_69c2735399608dbec7d43fd52e7c57a6.html#26

instead of just #26, etc.

I’ve set up a simplified test page at http://www.thecmsbcookbook.com/combined5.php

Any insights?

Thanks,

Jerry
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Challenges with createPDF plugin

By Dave - November 26, 2010

Hi Jerry,

Hmm, let me do some research on this and get back to you.

I'll be in touch soon.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Challenges with createPDF plugin

Thanks Dave
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Challenges with createPDF plugin

By Dave - December 1, 2010

Hi Jerry,

I've been doing some research on this. No great luck yet. One solution would be to disable links by changing this line in createPDF.php:

$switches = "-q --disable-internal-links --disable-external-links";

Another would be to detect we were in PDF mode and display links that had the to-be-generated PDF filename in them:

<?php if (@$_REQUEST['pdf']): ?>
<a href="example.pdf#bottom">Bottom</a>
<?php else: ?>
<a href="#bottom">Bottom</a>
<?php endif ?>


But I see there's a bug report for this on the underlying wkhtmltopdf library here:
http://code.google.com/p/wkhtmltopdf/issues/detail?id=417&q=anchor

I think there's an issue with how it's converting links. There's a new binary coming out soon that I'd like to try to see if it helps. Otherwise I'll keep looking.

Thanks!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Challenges with createPDF plugin

Dave,

Thanks for pursuing this.

Seems like this might affect many users as the plugin gains popularity.

Hope that the new version solves it.

Look forward to your findings,

Jerry
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php