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

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.

Related

Can visualforce's RenderAs PDF include href links?

We're using SalesForce's renderAs="PDF" option, and we want a clickable link in the body of the generated PDF. Is this possible?
I have tried an ... and I've tried <apex:outputlink value="...">...</apex:outputlink>, both result in a non clickable rendered version.
Has anyone found a way that works in salesforce's engine?
<apex:page standardController="Opportunity" showHeader="false" renderas="pdf">
<apex:outputLink value="https://google.com">https://google.com</apex:outputLink>
<table border="0" cellspacing="0" cellpadding="0" width="100%" id="table1">
<tr>
<td>
...
Update:
This is browser dependent. Firefox doesn't let you click the link, Google Chrome does.
What type of link are you trying to render in the PDF, a relative link? Using outputlink I have previously had the same behaviour but only for relative links.
Using a full URL should render the hyperlink.

Sphinx : png's are not shown on a generated PDF

This is my first Sphinx project and I am trying to create a cross platform documentation on HTML, ePub and LatexPDF. The issue is that the static PNG's are shown via the HTML and ePub version but not in the PDF file. What am I missing so that the PNG are also showing up in the PDF ?
<p align="center">
<img width="100%" height="100%" src ="./_static/organizations.png" />
</p>
Found a solution :
![Some Text](../../../_static/UIListener1.png)
instead of the HTML ...

cfchart not printing in 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

Tagged PDF using an HTML to PDF Converter such as Winnovative

There are many converter available on the market to create and manipulate PDF file from a simple HTML/CSS page. These tools are very convenient to create quickly some nice PDF files without the hassle of the more complex reporting tools of this world.
I am using Winnovative software to achieve this goal but I was wondering how to create accessible file (tagged PDF) to improve text-to-speach tool processing.
Are there any HTML tags that exists to achieve this? Anybody has some experience with this kind of requirements?
The tool itself has to be able to support the pdf/ua spec (tagged pdf). The list of possible PDF tags corresponds nicely to html tags. For example, there are <h1> through <h6> tags, table tags (<table>, <th>, <tr>, <td>), list tags (<l>, <li>), and so on.
There are minor differences, such as the tag to start a list is <l> instead of html's <ul> or <ol>. With a PDF document, the screen reader will say "list with 3 items" and then you navigate through each item. It doesn't seem to care if it's bulleted or numbered, thus the reason pdf/ua has <l> and html has <ol> and <ul>.
Anyway, the point is you don't need to use any special html tags to generate tagged pdf. The tool that generates the pdf just needs to support pdf/ua. I didn't see anything on Winnovative's website that indicated it support it.
FYI, here are the tags available in PDF/UA
<Art>
<Annot>
<BibEntry>
<BlockQuote>
<Caption>
<Code>
<Div>
<Document>
<Figure>
<Form>
<Formula>
<H>
<H1>
<H2>
<H3>
<H4>
<H5>
<H6>
<Index>
<Lbl>
<Link>
<L>
<LI>
<Lbody>
<Note>
<P>
<Part>
<Quote>
<Reference>
<Sect>
<Span>
<Table>
<TD>
<TH>
<TOC>
<TOCI>
<TR>
Essential PDF supports generating tagged PDF when converting from HTML to PDF using the Internet Explorer MSHTML engine.
Note: I work for Syncfusion.
Good explanation in slugolicious' answer about tagging PDF. While researching accessible PDF output for a project I found PDFReactor (www.pdfreactor.com) can do this. Unfortunately there's no budget for a license in this project right now, so I haven't tested it in production, but have tried the free personal version with satisfying results.

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?