Spire.PDF Load Binary PDF Data into PdfDocument - c#

I'm working in C# with Spire.PDF. Specifically, my goal is to load binary PDF data from a database into a Spire.Pdf.PdfDocument object.
According to this documentation, I should be able to use the LoadFromStream() method or some unspecified method that takes a byte array (see bottom of page at link where there is a link but only to the general documentation). However, this method seems absent from the current NuGet package.
So, in summary, how can I make a Spire.Pdf.PdfDocument object using a byte array of data? Thanks in advance.
Please comment if you know a better .NET library for converting PDFs to and from images.

Related

Convert word/excel bytes to pdf document and show to ASP.NET MVC view

I have been searching for a way to convert word/excel byte array from sql server to a pdf file and then I want to show it to the view using <object> tag.
But I cant find any proper solution to this problem online because almost of them use non-free packages etc.
Does anybody know a way how to do it in c# without using other libraries ?
If there is no way to do this please recommend me any package that is free and simple because I just want to use it for this purpose.
Refering to this question here I could use https://docs.google.com/gview?url=myDocUrl or https://view.officeapps.live.com/op/embed.aspx?src= but I dont know how to make them work with files saved in database as byte arrays and how to test them locally in visual studio.
If anybody knows how to use them with byte arrays please let me know as well.
Thanks in advance.
First, you'll need to put your byte array into a format that the Office API can understand--probably save the byte array to a file on disk, then using the Word or Excel API library (Microsoft.Office namespace) to open the file and process it (such as saving it to a PDF file).

Reading TIFF Image Metadata

I'm currently writing an application to read a TIFF File and then perform some compression algorithm. I have successfully done that .. But now, I want to read the metadata of the TIFF Image, but can't seem to find the correct way to do that.
What library and function should I use?
Even if I do not know which metadata you need to read, maybe the standard TiffBitmapDecoder class can help you. Take a look to its Metadata property.
From:
http://www.codeproject.com/Articles/7888/A-library-to-simplify-access-to-image-metadata
In .NET Framework, you can store and retrieve metadata by calling the SetPropertyItem and GetPropertyItem methods of the Image class, and you don't have to be concerned with the details of how a particular file format stores that metadata.

MigraDoc add image to table from stream

I've been using MigraDoc to generate PDFs and I've got the layout of everything working great except for adding in images. for the part of the program we're generating these PDFs for we're using a program that only saves their information as XML and from there am able to convert the XML into System.Drawing.Image objects. The problem I'm running into is somehow getting the System.Drawing.Image objects now into my PDFs.
MigraDoc was designed to work with filenames. So one option is saving the stream to a temporary file and then use the filename.
Or modify the MigraDoc source code to work with image objects - such a patch can be found on the PDFsharp forum.
BTW: The downvote is not from me. Maybe someone thinks that very little effort was used to post the question here.
Update (January 16, 2016): With version 1.50 (currently available as beta version only, but it is pretty stable) you can pass images in the filename: the filename will contain the image bytes using BASE64 encoding.
It's a bit of a hack, but should work for all scenarios.
Sample code here:
http://pdfsharp.net/wiki/MigraDoc_FilelessImages.ashx
So MigraDoc still uses filenames only, but it is no longer necessary to save images in temporary files.
I don't know where this solution started working, but I usually solve this problem with simple method to convert stream into virtual file path.
internal static string LoadImageFromBytes(byte[] cData)
{
return $"base64:{Convert.ToBase64String(cData)}";
}
And then use it in AddImage() method:
row[0].AddImage(LoadImageFromBytes(byteArray))

How to Save a Binary Representation to file

I have the following textual binary representation: "0x255044462D312E340D0A25FFFFFFF..."
I know it's a pdf.
I know it's the textual represantation from a sql server column (image data type).
But im lost to find out how to save this binary to a pdf file on my disk and view the content.
Maybe someone can hint me in the right direction.
Best Regards and Thanks in Advance
You're correct that it is a PDF file (at least it masquerades like on. You have hexadecimally encoded bytes; the first read:
255044462D312E340D0A
%PDF-1.4<CR><LF>
So you appear to have a PDF 1.4 string.
Just take two characters from the string, treat them as hex, convert them to the correct byte and write them to a file. Write binary, not textually (you don't want to add additional line-breaks in there, PDF is too binary to let that work.
(I did the conversion using this site: http://www.dolcevie.com/js/converter.html)
I'm not sure what database you are working with or how you are getting your string that you have above.
Many databases allow you to save binary data as a blob or some other byte array type. I believe in MSSQL this is called an "image" but I am not 100% on that. I would start by looking into the two following links in order. The first link talks about how to pull byte array data from a database. The example is in Visual Basic but should be easily changed to C# if that is what you are using.
The second link contains an example of how to save that byte array data to the file system.
I would also suggest posting some of the code you have tried as well so that the community may comment and point out areas you possibly had misunderstandings on.
1.) http://support.microsoft.com/kb/308042
2.) Save and load MemoryStream to/from a file
http://www.pdfsharp.com/PDFsharp/ can read in binary data and you can call .Save() and it will make the PDF file to disk for you.

How to convert PDF to Excel in C#?

I want to read tables which are in a PDF document and I want to store these values in a Database.
What I have found so far through searching the web:
Read text from PDF using abcpdf .net, which is freeware available. But it's not right solution because I want to read the tables.
Convert PDF document into Excel/Word. Tables will come in the target document as it is. Word conversion is possible by using EasyPDF Converter which is third party tool which is much cheaper than the other solution available in other tool which converts PDF into Excel.
But I am looking for any other solution/API classes which can convert PDF into Excel.
There are 2 possible solutions
a) Cometdocs makes a free online conversion from PDF to XLS surprisingly good and send for your email the result file.
b) Cognview is a comertial shareware that converts PDF to XLS. There is OCR and text version. I didn't use personally, but they have good recomendations.
If you are looking to upload your data into a database, converting your PDFs to CSV is probably the safest option. The PDFTables API will allow you to do this with C#, converting as many PDFs at once as necessary. https://pdftables.com/pdf-to-excel-api#csharp
You can try to use Quablo, a PDF table extractor available at this web page (link updated/corrected).

Categories