How to create a pdf viewer in WPF from scratch - c#

Hi I'm looking forward to create a pdf viewer like the one in the syncfusion library, telerik library, I would like to learn the working of pdf viewer as I don't want to use the third party application in my application. After some searches realized that we should have to rasterise the pdf doc into image and draw the each image to a frame. Is this the correct way to start. Are there any other ways? please give suggestions
Thankyou

I would take a look at this (now archived) project. It uses the Pdfium rasterizer which is made by Google and is open source and free. The rest of it is from scratch. It will show you everything you need to use Pdfium for what you're suggesting:
https://github.com/pvginkel/PdfiumViewer
As some of the comments alluded, you're not going to realistically be able to make your own renderer from scratch. But there's no reason to. Pdfium is outstanding and interops with C#/WPF perfectly fine.

Related

Opening Word (.docx) files on a Windows Form C#

I'm trying to make my program have the ability to display a Microsoft Word file on a form but not having any luck in doing so. I want to be able to open the file and display it on the form as a Read-Only. So basically just display it's contents. Various users on the web have recommended displaying files in the WebBrowser control (under toolbox). I have tried this but failed to get it working. My end goal is to be able to annotate on top of the web browser (or something of similar manner) and subsequently save the annotations along with the opened file.
I'm not that experienced in the C# language too so any help on how to achieve my problem would be greatly appreciated.
You need a DOCX viewer control. My company recently gave away our multi-format WinForms viewer control as a free product - XtremeDocumentStudio .NET Free. It can display DOCX and is available on NuGet. It does not require a Web Browser control for embedding an online viewer or Word software installed locally.
http://www.nuget.org/packages/XtremeDocumentStudio.NETFree/
There are some good links that might help you.
First, you will find a closely related or similar question here
And in that conversation someone posted the following link which is about how to build a user control for displaying Word documents in a webbrowser control.
I also found another article here about how to integrate Excel in a Windows Form application using WebBrowser. But Excel is used as an example and you may be able to adapt it to Word.

Open PDF in C# as view only without adobe

im needing to create a form in my C# project that just allows the user to view the pdf.
i have a way to open the pdf and read it but i need to disable features like printing, saving, highlighting, copy/pasting while maintaining the ability to search in the document
they should really just be able to open the document, read it,search for words in the document, close it
any help would be great
thanks in advanced
You could use Ghostscript to convert PDF to images and then show the images on your form or you could rasterize your PDF directly to the screen.
To use Ghostscript from .NET you can take a look at the Ghostscript.NET library (managed wrapper around the Ghostscript library).
Ghostscript Viewer C# sample that rasterizes PDF directly to the screen can be found here: https://github.com/jhabjan/Ghostscript.NET/tree/master/Ghostscript.NET.Viewer
To search for the text inside the pdf you can use iTextSharp
(Disclaimer I worked on this component at Software Siglo XXI)
If you don't want to mess with Ghostscript API and need a quick working solution to visualise the documents, you could use ImageZoom Viewer .NET. It's available for both 32 and 64 bit and is very cheap and effective. I'd recommend you to try it since it's a very fancy and fast. You can browse, scroll and print the pages from the viewer.
You can take a look here: http://softwaresigloxxi.com/ImageZoom.html
This is for quick browsing and reading. Then, when you want to use text operations, you could let the user to use Adobe Reader, launching the PDF from there.

How to highlight text in Pdf Winforms C#

I have a pdf file which I want to open in a Windows Forms Application and perform following tasks-
View the pdf document
Zoom +/- document
Search Text
Highlight a specific text
Show it in a listbox/dropdown
select those words and highlight in pdf
Remove selection/Highlight.
I have tried using certain libraries like pdfSharp/iTextSharp even Acrobat Reader OCX control.
Its really bugging me..is there any help??
I'd suggest looking at some means of converting the PDF if you don't have a direct need to edit it. Even then, it may be easier to convert to a different form, make changes, and then convert back. PDF is a form of PostScript, which makes it powerful, but also makes it a mess to deal with and my personal preference is to skip that headache. Not always avoidable (had a lot of fun creating Thai support in PDF print#home ticket creation once without bloating the document beyond unusable), but highly recommended where possible.
Anyways, there are a variety of PDF conversion libraries out there, some of which may be available for .NET. Worst case, you may need to create a managed C++ layer to allow your C# code to access them.
Doesn't acrobat reader OCX already have all those features ? What exactly doesnt the OCX do that you need to do in your code ?
You might try contacting Adobe and getting their full SDK for PDF. It might have controls which you can use to solve your problem.
Come to think of it , is there even an SDK for PDF from Adobe ?
You have not mentioned your preference of using Free or Commercial PDF Viewer option. If you are open to use Commercial PSF viewer, you may evaluate SyncFusion PDF Viewer control, Telerik PDF Viewer, Dynamic PDF Viewer or TallComponents. I have checked feature set and all seem to have features you are looking for. I do not represent or promote any of these SDKs, I have used TallComponents and Dynamic PDF for PDF manipulation and both have excellent support, I would say PDF Veterans in .NET space.

HTML Printing

I am too cheap to buy crystal reports so i built the report in asp.net, the only problem I'm facing is printing the report and making it look professional. On different printer's the report looks diff, i want to be able to control the final output and make the report print standard across all printers. You guys have any suggestions on how to achieve this properly?
Why not just use Reporting Services? It's free and easy to integrate with both WebForms and WinForms apps. Supports export to PDF, Excel, etc.
Mabye a stylesheet? Google it, good luck
You could try implementing a print stylesheet (you'll find many examples Googling the term), but that can be laborious if you're not familiar with css.
If you're checking out pdf solutions, I've used iTextSharp to create pdfs. It's relatively easy, open source and mature and used by many corporations.
You could try printing to a PDF. Not sure what your budget is, but ExpertPDF is a good option I'm using now.
You could create the report as a PDF using a C# library such as PDFsharp (Open-Source).
This approach allows you to:
Serve PDF files to your user, giving them the option to:
print it now
archive it for later use
Automatically email reports to your users using a scheduled task
Store generated PDFs in a database or on the file system
cutePDF is a free PDF writer and should work for what you need

Using C# to display powerpoint

Is there any good way to use a windows application written in C# to display/control a powerpoint slideshow? Ultimately I would like to show thumbnails in a form and clicking these thumbnails would advance the slides shown on a second monitor (similar to using Powerpoint itself to show a slideshow on a second monitor).
I would like to be able to use Powerpoint Viewer if Powerpoint is not installed.
There seems to be some ActiveX-controls that allows integration of Powerpoint in a form, but most of these seem to cost money, does anyone have experience using one of these controls?
Edit: I know that there is an object model accessable by adding a reference to Microsoft.Office.InterOp.Powerpoint, but I want to be able to distribute the resulting program without having Microsoft Office as a prerequisite, that was why I mentioned Powerpoint Viewer because it can be distributed freely.
This kb lays out the basics for working with the powerpoint presentation viewer object model. I'd suggest you include the viewer when you distribute your application.
http://support.microsoft.com/kb/265385
Once you get a reference to the viewer (top level) object it is basically the same as working with the powerpoint.presentation object model, but with less functionality (i.e. editing, etc)
If you are working with Powerpoint 2007, then you can add editing functionality by using the System.XML and related namespaces to work with the presentation file as an open xml file.
Regarding the comments about UNO/openoffice.org, I think these miss the point, as you cannot use UNO for working with powerpoint, it is for openoffice and that was not the origianl requirement of the questioner.
there are 3rd party toolsets like aspose, but then your goal was to work with the powerpoint viewer component (free) so I'm guessing you want to avoid paying for dev tools? Either way viewer components OM is perfectly suitable for displaying and previewing and existing slide show. (you will need one copy of Powerpoint so that you can author the presentation from scratch, plus Visual Studio to create the VSTO project).
One of our softwares here at work does that. Initially we used MS Office but recently we switched to use OpenOffice.org Uno since it offers better control than MS Office and is easier to work with. It has .NET CLI-bindings.
To answer your question, yes it can be done but our engineers would recommend you use OpenOffice.org instead.
Just like with Microsoft Excel and Word, Powerpoint has an Object Model that you can access in code by including a reference in your project to:
Microsoft.Office.InterOp.Powerpoint.
I've used the Excel and Word models, but haven't used the one for Powerpoint. You can get a little taste of what's available by opening up the Object Browser once you've included the reference to see what kind of functionality is available. This might be a viable solution for you if you don't want to use a 3rd party tool to access the object model.
I have used the Word toolkit from Aspose -- they have a Powerpoint toolkit too that I think would be worth looking at.
http://www.aspose.com/categories/file-format-components/aspose.slides-for-.net-and-java/default.aspx

Categories