cfchart not printing in PDF - pdf

I'm trying to print PDF from HTML using cfdocument. The code works fine when I access it through localhost, but when I use static IP to test it online on the same server it timeouts.
I tried cfhtmltopdf it didn't timeouts but it doesn't generate the chart and shows "image missing icon". nor charts get generated nor images. text gets printed fine. And it takes like 20 to 30 seconds to generated the PDF when an image or chart is used.
I tried this on CF11 32bit and 6bit both having same issue.
Even the simplest codes fails:
<cfhtmltopdf>
<!DOCTYPE html>
<html>
<body>
<div class="pdf_logo" style="margin-bottom: 20px;">
<img src="images/logo.png" width="180">
</div>
</body>
</html>
</cfhtmltopdf>

Your problem is probably with resolution of the path to the image. try an absolute path (http://) Or a file path (file:\) ... try resolving the image from the desktop of the server itself.
Remember that the server internally must resolve your images/logo.png into something like . If (for example) your pdf generating cfm is in a folder that is not the root, the server may resolve it to http://blah.com/some folder/images/logo.png - which naturally won't work because there's no "images" folder in there.
Other possibilities? Your server can't resolve an "internal" natted address, or is trying to use an external non-natted address through the firewall interface.
Fortunately almost all these problems can be easily tested or resolved. You will also save yourself headaches by simply using the file method to include any resources into your PDF file.
For more on resolution issues see my post on Network address resolution and Cfdocument.
Hope this helps! good luck.

I've encountered a similar issue with cfhtmltopdf. In my case, I was using a cfimage tag, and the images were being rendered in the PDF document very sporadically.
I suspect that the rendering of the cfhtmltopdf tag happens asynchronously, in a separate thread from any rendering that may happen inside that tag (for example, cfimage or cfchart). So the cfhtmltopdf tag will finish rendering, and it won't have the results from the rendering of cfimage or cfchart, so it displays the "broken image" icon because it can't find the source.
So this solution based on ColdFusion documentation† might help you:
<!--- 1. Generate the chart as a jpeg image. --->
<cfchart name="myChart" format="jpg">
<cfchartseries type="pie">
<cfchartdata item="New Vehicle Sales" value=500000>
<cfchartdata item="Used Vehicle Sales" value=250000>
<cfchartdata item="Leasing" value=300000>
<cfchartdata item="Service" value=400000>
</cfchartseries>
</cfchart>
<!--- 2. Write the jpeg image to a temporary directory. --->
<cffile
action="write"
file="#ExpandPath('/charts/vehicle.jpg')#"
output="#myChart#" />
<!--- 3. Generate the PDF file. --->
<cfhtmltopdf>
<!DOCTYPE html>
<cfoutput>
<html>
<body>
<div class="chart">
<!--- This image tag refers to the file created by cffile --->
<img src="/charts/vehicle.jpg" />
</div>
</body>
</html>
</cfoutput>
</cfhtmltopdf>
† Based on the example here: http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec22c24-7934.html

Related

Body background style not working in google chrome?

So keeping it simple, I am trying to add a background image to the entire body of a basic software I am designing.
From what it seems, when I use Adobe Dreamwaver (which allows you to see both the code and the live page), there seems to be no issue with the background image, however, when I open the file using localhost (via XAAMP) on Google Chrome, it doesn't load the image.
The specific piece of code, is as follows:
<!doctype html>
<html>
<head>
</head>
<body style="background: url('file:///C:/xampp/htdocs/Mind%20Notes/gradient.jpeg')no-repeat
center center fixed;">
</body>
</html>"
Really basic, but just to illustrate. I have tried using the body-style segment in my main code, but it didn't work. I tried the code, as above, and still got nothing.
I suspect, its an issue with my browser, not any conflicting code, otherwise the simple code above would have worked.
Many thanks
T

html to pdf ASP.NET.Core 1.1 image not showing after conversion

I am using this open source library for html to pdf. Everything is working, but when it comes to adding a <img src> tag, it is not showing the image I want in PDF. For example,
string image = "~/images/test.png";
string htmlToConvert = string.Format(#"
<div>
<table>
<tr>
<td>
<img srcset='{0}'>
</td>
</tr>
</table>
</div>", image);
Is there anything wrong with my format or is it simply just not supporting images? If it is true, any working library for asp.net core 1.1? (important because some libraries/suggestions were based on 1.0 which contained project.json file)
p.s. I am going to deploy it via Azure web app service
The image must be in the same folder as where the phantomjs executabels are.
Just take a look at method
PdfGenerator.WriteHtmlToTempFile
There you can see that your html is stored into a file in the phantomjs-installation directory. And this is the root of your html-file, which means that the images must be there too.
https://github.com/TheSalarKhan/PhantomJs.NetCore/blob/master/PdfGenerator.cs.
I suggest that you use the phantomjs-executabels directly to better understand what is going on.

Apache add Content of a Link to response

I want to know if it is possible to let apache substitue a link in the html I return to the client with the html of the site behind the link.
So instead of
<html>
<head>
</head>
<body>
Link
</body>
</html>
I want something like this:
<html>
<head>
</head>
<body>
// the html of the page behind the link
</body>
</html>
I can´t use javascript or php or anything, let´s assume I only have html.IFrames are as well no solution for my problem.
Just for everyone that comes to a similar situation, Ulrich Schwarz gave a good hint with SSIs, which is in this scenario the only way that could work. However, due to cancelling the project, I was not able to validate the usage of SSI for this scenario.
This can be little painful to do and might not be suitable for all cases but you can maintain a plaintext file for every html page you want to show source of and add a link to that file instead.
For eg: Instead of <a href='somefile.html'>Click</> do <a href='somefile.source'>Click</>
where somefile.source is the copy of the somefile.html. Add triple qoutes """ in the first and the last line of the file. I didn't try a lot of combinations but this works for fairly decent html codes.

How to protect layout from malformatted html content on a generated webpage?

I have a container layout of a webpage that works like this:
<html>
#header#
<div class="content_container"> #content inserted here# </div>
#footer#
</html>
If the content has a div that is not closed or closes a div without it being opened, the content_container's div and so the layout gets messed up.
How is this situation normally avoided or solved?
Hy,
From what i found on the net, you could parse the fragment as a HTML document using the DOM loadHTML function, then spit it back out again as HTML. That will fix any HTML well-formedness errors.
Or you could use the Tidy extension for php5
http://www.php.net/tidy

unable to integrate datatables into a rails 3 app

I am using the no configuration option and have taken the following steps:
put the js files into root/public/javascripts
put the image files into root/public/images
put the demo css files into root/public/stylesheets
put css call in the head section of my layout file
<%= stylesheet_link_tag "demo_table", :media => "all" %>
put the initialization script in the head section of my layout file:
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$('#example').dataTable();
} );
</script >
first line of my table layout is:
<table width="100%" style="border-collapse:collapse; " id="example">
I restarted my server. Nothing happens. What am i missing?
The zero config relies on having a properly formatted table, which your example isn't showing. It must also have <thead> and <tbody> elements to render properly. Ensure that's properly setup first.
Second, open the page in Chrome or Firefox, view source. Click on the links to the Datatables.js and Datatables.css files as well as Jquery.js (or whatever each of these files is named) Do they open? If not, there's your problem.
Javascript is essentially platform independent. Sure, you get information TO the script in different manners in Rails, PHP, .net, etc, but there's no reason that this doesn't work in any of the major scripting language.
I have been using the RailsDatatables plugin in my rails apps without any problem. Maybe give that a try?