How to render pdfs using C#
There are a few other choices in case the Adobe ActiveX isn't what you're looking for (since Acrobat must be present on the user machine and you can't ship it yourself).
For creating the PDF preview, first have a look at some other discussions on the subject on StackOverflow:
- How can I take preview of documents?
- Get a preview jpeg of a pdf on windows?
- .NET open PDF in winform without external dependencies
- PDF Previewing and viewing
In the last two I talk about a few things you can try:
You can get a commercial renderer (PDFViewForNet, PDFRasterizer.NET, ABCPDF, ActivePDF, XpdfRasterizer and others in the other answers...).
Most are fairly expensive though, especially if all you care about is making a simple preview/thumbnails.In addition to Omar Shahine's code snippet, there is a CodeProject article that shows how to use the Adobe ActiveX, but it may be out of date, easily broken by new releases and its legality is murky (basically it's ok for internal use but you can't ship it and you can't use it on a server to produce images of PDF).
You could have a look at the source code for SumatraPDF, an OpenSource PDF viewer for windows.
There is also Poppler, a rendering engine that uses Xpdf as a rendering engine.
All of these are great but they will require a fair amount of commitment to make make them work and interface with .Net and they tend to be be distributed under the GPL.You may want to consider using GhostScript as an interpreter because rendering pages is a fairly simple process.
The drawback is that you will need to either re-package it to install it with your app, or make it a pre-requisite (or at least a part of your install process).
It's not a big challenge, and it's certainly easier than having to massage the other rendering engines into cooperating with .Net.
I did a small project that you will find on the Developer Express forums as an attachment.
Be careful of the license requirements for GhostScript through.
If you can't leave with that then commercial software is probably your only choice.
C# solution for rendering PDFs and OCRing the resulting images?
I think you might want to give Docotic.Pdf another chance.
The library can extract text chunks, words and even individual characters with their bounding rectangles. Please have a look at the sample for extraction of words from PDFs.
Also, Docotic.Pdf can create images from PDFs and draw pages on a System.Drawing.Graphics
. Please have a look at Draw and print Pdf group of samples.
Disclaimer: I am one of developers of the library.
How to Render pdf to file
Actually the Filestream You are using is correct. the point is check where your calling this code. i have used in render event(page-prerender) and got error.
Undocumented windows built-in PDF renderer capabilities?
The library used by general Windows 10 apps is not the same as windows.data.pdf.dll
, it's simply a namespace defined in Windows.Foundation.UniversalApiContract
On the other hand, Windows.Data.Pdf.dll
is a native function library, so you need to see if you can get DllImport
to work with it.
EDIT: Here is the output of DependencyWalker of Windows.Data.Pdf.dll
The function that interests you is probably PdfCreateRenderer
Related Topics
How to Convert an Iso8601 Timespan to a C# Timespan
How to Bind Crystal Report to Manually Created Dataset
How to Pass Data from Mainwindow to a User Control That's Inside the Mainwindow
How to Provide Custom Cast Support for My Class
Access to Foreach Variable in Closure Warning
Cancelling a Task Is Throwing an Exception
Exception When Addwithvalue Parameter Is Null
Convert Any Currency String to Double
How to Find System.Web.Helpers, System.Web.Webpages, and System.Web.Razor
JSONserializersettings and ASP.NET Core
SQL Where Clause Matching Values with Trailing Spaces
How Does Transactionscope Roll Back Transactions
What's the Difference Between Application.Run() and Form.Showdialog()
How to Check If a List Is Ordered