SVG content of Telerik RadHtmlChart - c#

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.

Related

PDF First page image preview in DIV on website

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

HiQPdf not displaying Charts on the generated PDF

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.

WPF WebBrowser control: Disable download or how to find out all displayable filetypes

I'm writing a document view and I'd like to use the capabilities of the WebBrowser control for some file formats (pdf, e-mail).
Now I have the problem, that for every file format that is unknown to the WebBrowser control, it offers to download the file.
So the question is: How to find out what file formats (file extensions) can be displayed by the browser, so that I can display a message to the user that the current fileformat is not supported for displaying instead of getting a "Do you want to download" dialog box.
If I was you I wouldn't use a WebBrowser control for following reasons:
WebBrowser is just a wrapper around IE engine. It uses old version of IE by default, so it can have troubles displaying correctly HTML documents with basic CSS styling. It can be forced to use newer versions of IE or even other engines, but it takes some effort.
WebBrowser control purpose is to display and navigate throught web pages. And navigating is essentially downloading. I believe it's gonna be hard if not impossible to prevent WebBrowser from downloading files. I believe one way you can do it is by modifying html files like this: Remove hyperlink but keep text? Also you would probably want to prevent context menu from openning.
WebBrowser control is capable of displaying PDF as described here Displaying a PDF in a WPF Application Not Working - WebBrowser or Adobe Control But I have no idea how would you prevent following the links placed in pdf
Instead of using WebBrowser I suggest you to use one of many royalty-free PDF viewing controls and convert your html documents to PDF. I believe suggested approach will take you less time and will be more robust

How to convert PDF files to swf or HTML for viewing in C# MVC 4.5

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 :( **

Automated copy of selected text in pdf file loaded using web browser control in c#.net

This is what I have done:
I have loaded a pdf file in web browser,
Now I want to select text from that file and paste into a text box.
Can anyone help me?
I'm pretty sure that this is going to be prohibitively difficult, if not impossible, to do.
The browser does not 'run' the PDF, it acts as a host for the PDF application, which ends up sharing it's main window. After that, control of the cursor etc passes to the PDF application and the browser is effectively no longer aware of what happens inside it. If the PDF application being used exposes COM interfaces for manipulating the cursor/text selection (doubtful), then it's possible to script against those interfaces from client script - but you won't be able to actually run any script in that window because the browser is showing a PDF, not a web page.
It might be possible if you hosted the web control on a windows forms application, but even so I wouldn't even know where to start on that one.
If your goal is to extract text from the PDF then you're probably better off pushing it through a .Net PDF library. A quick google on that one will yield you some suitable libraries.
if your pdf file has form elements then the file can be submitted to a url.
check this link.. it might help.
Can a PDF fillable form post itself to an HTTPS URL?

Categories

Resources