I have been using the (free version) HiQPdf libraries to converto html pages to pdf documents.
I am also using in my pages several Chart objecs from the .Net Framework (System.Web.UI.DataVisualization.Charting.Chart) to produce bar graphics dysplaying values changing along time. It works wonders in my local environment when I debug with VS, but when I publish on my IIS or on other servers the charts do not appear at all on the pdf - note: they do appear on the webpages just not on the pdf.
In the Pdfs all the html is displayed correctly, inlcuding css, showing it exactly as seen on the page, except the chart images. I kind of understand that they would not appear as in the html, the image source from the charts results in something like:
<img id="MainContent_MyPageControl_ctl00" src="/MyTestWebSite/ChartImg.axd?i=charts_0/chart_0_2.png&g=396d61e14ceb41c08be06fd956cd4dca"
Because the real generated png image is not even directly referenced as usual. But the fact is they do appear on the generated pdf when running local from VS, which produces a similar html anyway as the above.
Only difference I see is that when I run local the Image Chart Handler key is defined in the webconfig as:
add key="ChartImageHandler" value="storage=file;timeout=20;dir=c:\TempImageFiles\;"
but when publishing on a server I have changed it to:
add key="ChartImageHandler" value="storage=file;timeout=20;Url=~/MyfolderTempcharts/;deleteAfterServicing=false;"
So why dont the charts appear too on my generated pdf, or why they do appear if Im running from VS?
Anyone ever had this problem?
So I have figured out a way to deal with my problem, and I am sharing here if anyone is also in need. The deal is that the Chart objects use http handlers to render the chart generated images (you can read more about it in detail from these guys: https://web.archive.org/web/20201205231110/https://www.4guysfromrolla.com/articles/081909-1.aspx)
At first I thought I could manipulate the html (that I get before the page render) and replace the image sources with accessible links to send to the HiQPdf - for that I would need to temporarely copy the generated images to a public folder. That would be fine unless in my case I deal with sensitive data that should never be accessed even if only momentarily.
So what I do is I check that the image file does exists (in my configured folder) and extract the byte data from it, convert it to base 64 and replace it in the image source html where the handler is, and voila.
example of Base64 html embeded image:
Notice that this manipulated html is never accessible from the outside and is only worked on on the server side, in order to provide a "normal" html that the HiQPdf can pprocess.
Related
In my system, there are multiple PDFs listed in the website. I need to show the preview image of 1st page of all the PDFs.
There are two previews which I want to display -
One small preview
One big preview on mouse hover
What I am doing now?
We are taking help few third party preview generators. Which is used to create JPEG image and using those images in the website for previews.
What I tried differently?
I used EvoPDFtoHTML tool to use HTML instead of images directly but for many files the generated HTML is not appropriate.
Also, These both process is taking a lot of time and making website
slow in response.
I would like to know that is there any better way to achieve this?
Image attached below for better understandings -
An approach that is worth exploring
Parse the PDF and extract the 1st page.You may use command line tools like : PDFtk, Ghostscript, or Implement your own class to parse out the first page in C#
Then use Google doc viewer and embed an iframe to point to PDF
Example of PDFtk:
pdftk input.pdf cat 1 output page-1-of-input.pdf
Example of GhostScript:
gs -o page-1-of-input.pdf -sDEVICE=pdfwrite -dPDFLastPage=1 input.pdf
References:
Display first page of PDF as Image
You can also look at Fahims answer for the C# snippet that he tried
The graph exported by the export server fails to render the images from a specified URL that are to be used as the marker for each series datapoint, such as of the following example:
"series":[{"data":[{"y":0.06,"x":3.5815,"marker":{"symbol":"url(https://www.highcharts.com/samples/graphics/sun.png)","width":40,"height":40}}}]
The rendering is inconsistent in the sense that it loads at times and doesn't at others. I am assuming the highchart export server returns the graph much before the images from the URL are loaded onto it.
Alternatively, is there any other way to load images as markers onto the graph by passing such a parameter in the JSON file?
I noticed that you already reported this issue here: https://github.com/highcharts/node-export-server/issues/43. Until this bug is fixed, you can use the older version of the export server (using PhantomJS). At the bottom of this page: https://www.highcharts.com/docs/export-module/render-charts-serverside you will find instruction how to install and configure legacy export server. Here is the example of use:
phantomjs highcharts-convert.js -infile options.js -outfile chart.png
I tried to generate image this way and it renders without any problems, resulting in:
I have hundreds of PDF files that i need to present to users. When presenting these files through my MVC web app i don't want the users to have the ability to download the files, e.g.. i don't want the Acrobat reader controls for print/save showing up. Reading this stackoverflow post it seems that it's not possible to disable those controls.
I know users can still take screen shots and print out the page, but that's not an issue in my case.
What is the best way to go about this. I've reasearched using SWFTOOLS which looks like it may be a good solution, but i dont want to save the swf files to my filesystem. The optimal solution is PDF.js, but another problem i have is users will be accessing the files through IE8 - so PDF.js is out of the question. Unless there is another similar library that will convert the files to HTML 4.
Basically I just need to display the PDF files, on the fly would be best, in a different format than PDF
Any suggestions?
I had a similar project a while back, where sensitive pdfs were needed to be displayed to specific users but they weren't allowed to download/print/save it.
Since it was a web app I ended up using pdf.js. It is Mozilla's PDF renderer for firefox. It renders the pdf on to a canvas and by default has all the bells and whistles. If you have firefox, open a pdf file to see it in action.
It was tough to get it running at first but I ended up using a demo I found online as the base of the project. After removing each functionality that was forbidden the finished product did exactly what was required. You will need to add a print css file to block printing or find a better solution. I ended up using the css approach since print preview by passed my javascript check for the print action. Also ensure you block ctrl + s which allows the user to save the pdf.
Another aspect to note is that it works better on later versions of IE and struggles on older versions as the file size increases. Firefox and chrome are not a problem and I believe its the same for opera although I haven't tested that.
I would convert it to an image file, you can find tools or write script to do it, I personally would do it by displaying them in browser first and then use browser plug-ins to take screenshot of the entire webpage.
(you can automate this)
then just display then converted pdfs
**this is probably not the best solution :( **
Currently, I have an aspx page in vb that launches a RadHTMLChart and I want to grab the SVG code of that chart. However, since the chart is rendered client-side, I have to launch this aspx page and then grab the SVG code from a second aspx page during postback. Currently, I am using Server.Execute (firstpage.aspx) to grab the SVG code but this does not work. I want to use the SVG to generate a PDF document but the Server.Execute command seems to run in the background and the code that comes after it do not wait for it to finish first, hence I am not grabbing the SVG content. Does anyone know of another way to grab this SVG content?
It seems you need all of this done on the server, so you need to find a way to launch a browser on the server, get the needed data from it and close it. I think a tool called PhantomJS can do this for you, so you can give it a crack (it's free I think).
Here is an example on exporting an HtmlChart, but it relies on a user interaction (which can be automated via some scripts) but it needs the page opened on the client machine: http://www.telerik.com/support/code-library/exporting-radhtmlchart-to-png-and-pdf. Anyway, it may still be helpful for ideas and to show how to get the SVG string.
Using WKHtmlToPDF to generate PDFs for my company's web-based mapping service.
Essentially, I take a template HTML file, inject an image into a div, save the HTML to disk and use WKHtmlToPDF to render to PDF.
Now, on most templates it works a treat. On one particular one though, where the image should be (int the pdf) is a grey area. HOWEVER, if I right click on the grey area, and select "Save Image As...", the saved image is correct.
Linked are the created PDF and the HTML on which it is based. Help required most urgently, and hints appreciated.
Zip File Containing HTML and PDF
I was having an issue where a particular image was not being printed to the PDF. Other images on the same page were. The src of the missing image is from a CDN, but had no extension, i.e. src="\\path/to/image?param". Using the aforementioned -n switch (disable Javascript), the image shows up in the resulting PDF. Thanks Jordaan.
Don't know WHY this worked, but adding the "--disable-smart-shrinking" option, and/or removing the "-n"(Disable Javascript) option, fixed it.