SSRS .net PDF to Image from SQL - c#

I have looked and there doesnt seem to be anything around to do this.
I have a database with a varbinary column that contains a PDF.
I want to display this as an image in SSRS.
I can't find any way with ghostscript or spire.pdf etc (the free options) that allow you to pass a stream as the pdf input, and then output the images, they all seem to need an actual file.
Googling this gives a codeproject example from 2009 which uses a component you now have to buy, plus sqlclr which seems overly complicated.
I just want a .net class i can build and reference in my SSRS rdl file which i can pass the field as the result of the sql query and get back a list of images (1 per page)

Instead of trying to display PDF stored in VARBINARY(MAX) directly in SSRS, I would try to obtain the images before generating the report:
1) use a tool to generate an image from a PDF (e.g. ImageMagick). More details about this conversion can be found here.
2) Display images in SSRS from VARBINARY(MAX) using this tutorial.
This means to have some redundancy (extra space needed), but reports will generate faster.

Related

Saving PDFs in SQL Server

From the DB schema that we have I think we are saving images in the SQL Server, I found a column called ImageContents(text null) in our Images table.
Now I have a folder that has bunch of PDF files and I want to save them in that table.
How do we do that? Why is it s text type column?
I Googled the topic but mostly they were saying save the image somewhere else and save a link to its address in the SQL Server but that is not how we do it so I couldn't find an answer by myself.
Since you're stuck with a text field, and you have binary data, you will need to encode your binary data into something that will go in a text column, and you will also have to decode it when you get it out again.
Base 64 encoding is one way to do this. (Note that the encoded form will take somewhat more space.)
Convert.ToBase64String(bytes) and Convert.FromBase64String(string) should get you back and forth, as in this example. (For the byte array step, use File.ReadAllBytes or see Vinikov's link.)
Again, it would probably be better to store a path and filename in the database, and keep the PDF files in the file system, but I understand you don't have the option to do that in this case.
P.S. SQL Server now has a FileStream attribute on varbinary(max) fields, that will store large files like this in the file system (though you have to enable it and configure it). Again, I understand that you don't have the option to use varbinary(max) in this case.
If you are already storing images in your database, look again and probably that you will find a column of type Image or varbinary(max). This is what you need to store your PDF files as they are binary files and not text files. Possibly that you can use the same type of code as what you are already using for storing your images; if such code is available. Otherwise, you shouldn't have any problem to find on the internet how to store an image file into a column of type Image or Varbinary(max). Storing a PDF file is exactly the same as storing an image file; except maybe for the extraction of metadata (such as decoding the width and the length of an image) and the checking of the suffix (.GIF, .PNG, etc.).
Do not use the column of type Text (or of varchar(max) or nvarchar(max)) because there would be a real possibility of corrupting your PDF files.
With the older versions of SQL Server such as 6.5 or 7.0; there was a real performance issue with storing files in a database but these problems have since been corrected.

.NET Windows Form Data to PDF

I have a C# .NET Windows Form with text fields. The user enters data into this form and once they submit I need to generate a PDF file with their data arranged neatly. What is the best way to do this? Should I move the data into a database or can I directly export to PDF?
There is no need to add it to a database if you don't want to persist the data for later use. There are tons of libraries out there for pdf creation in c#.
Here's a post made not long ago with some great references. It also covers almost the same topic.
you want to export directly to pdf. are you have any specific format, how it should Looks.
otherwise create a crystal report. Design a format.After that write this code
Crystalreportobject.ExportToDisk(ExportFormatType.PortableDocFormat, name + ".pdf");
ExportToDiskMethod can Export directly to PDF

Compare SSRS report values with C# variables

I have to compare data contained in rendered SSRS report (chart and tablix values for example) with variables stored in a C# application. How can it be done?
So far I know only about generating report in Xml and parsing the Xml to get the desired data. Is there an easier way to achieve that without any user interaction? Alternatively, is there a way to drop report chart/tablix data to an array or list in C#?
You have one special requirement there... it might help if you tell us why you want this, because there may well be other solutions to your actual problem.
Having said that, if you want to "compare data contained in rendered SSRS reports" to "variables stored in C#", you probably have the best approach already. Given that approach, you seem to suppose that there's user interaction needed to generate the XML, but it's not: there's the SSRS Web Service where you can run reports without users intervening. The render method allows you to specify the format:
Format
Type: System.String
The format in which to render the report. This argument maps to a rendering extension. Supported extensions include XML, NULL, CSV, IMAGE, PDF, HTML4.0, HTML3.2, MHTML, EXCEL, and Word.
Guessing at your actual case being the need to check if the report data is "correct" by comparing it to C#-generated data, I'd suggest a different approach though. Place as much data-logic as you can in Views or Stored Procs, use those in your reports, and in C# compare your calculated results to the results read from the View through something like ADO.NET. Much easier than parsing SSRS XML reports (though a bit less reliable, because SSRS may still screw up interpretation of the data).

Programmatically printing dynamic tabular data using Visual Studio 2008 C#

I am planning to write an application to automate generation of package slips. The idea is that the application would pick up customer order details from the database (say every morning) and generate package slips for them which could be printed out with the click of a button.
I would like to be able to either print one package slip per page or (in order to save on paper) maximum 2 (if there is enough space left to fit both). I would also prefer to have an option of print preview before printing.
The package slips use a table with some columns spanning over multiple columns above/below.
Not so important at this point, but a need may arise to be able to export the daily package slips generated by the application to word or PDF.
What is the best way to achieve this?
I'm not sure if it would work in your case. But most of what you are asking to do can be achieved using iTextSharp to generate a PDF file dynamically. Because it would generate a PDF you would get a lot of your requirements for free (such as printing, print preview etc). However, not sure about going from PDF to Word. Worth considering though as iTextSharp has good support for tabular data.

Wanted: ASP.NET control to view/print PDF, TIFF, possibly more?

I'm looking for an asp.NET control that will allow for viewing and printing of a pdf and TIFF within a web form. I'm willing to use more than 1 control if needed (1 control for pdf, 1 for Tiff, show and hide based on file extension), but I have not been able to find a good Tiff viewer.
Files are stored on our LAN in a shared folder, and this application is an intranet site.
Open source / free licensing preferred, but I'm willing to look at paid options as well.
http://www.alternatiff.com/ is one of the viewers that I've seen used for this type of viewing of tiffs.
You can get a free licence of ABCPDF (provided you link back to their site) which will do the conversion from TIFF to PDF for you as per #Chris Lively 's suggestion.
It'll also do conversion from PDF to TIFF if you decide to do things backwards.
It makes sense to present the content in a common format. If you wanted to you can embed the PDF in the browser to create the 'seamless' experience you're looking for using something like PDFObject.
As #BenCr says though, PDF is a really common format and the tools already exist to open and work with them, so introducing new ways to perform existing tasks could actually end up complicating matters unnecessarily.
I'm in total agreement with #BenCr on this.
Viewing PDFs is an extremely common thing to do. This isn't a "technical" issue by any stretch.
It sounds like you have some type of faxing solution in place that is creating these documents. Most likely multi-page TIFF and PDFs.
If this is the case you might want to just convert the TIFFs to PDFs to begin with and run everything through Adobe's pdf reader. Every online fax solution does this.
You could try http://issuu.com/ and they appear to have a API too if you want to go that deep.
We used the the Seadragon control to do this. I think it was an overkill and we should have just rolled our own -- would have been cheaper than integrating it. TIFFs and PDFs are converted to PNG on the server side. I don't think you can do better than that, especially with PDFs (assuming you don't want to use Acrobat Reader to display them). Convert PDFs to PNG using Xpdf/Poppler.
How about using Google Docs Viewer?
EDIT: Probably not working, since the viewer has to read the document from your URL; when it's on the Intranet, this won't work.
If you can mess about with mime types -- mainly by making the .tiff files expose an application/pdf mimetype -- you should be able to get acrobat to open TIFF files directly by effectively fooling the browser to open TIFF files with acrobat. Then all you need is a trusty old iframe to get you familiar UI with print buttons.

Categories

Resources