Skip to main content
GameDev.net gamedev.net
🔒 Locked 🤖 Godot

[.net] .net PDF Viewer Component

Started by gavco98 Aug 30, 2007 at 5:51 AM 11 replies 21.7k views
Original Post
gavco98
gavco98
I would like to create a PDF viewer application, as I hate Acrobat, as it lacks some of they key features I need. I have tried looking around, and most components seem to be for creating PDFs, and are quite expensive. Does anyone know of a relatively cheap component that simply allows you to view them? Im looking for something under $200, or ideally, free.
Gavin Coates
[size="1"]IT Engineer / Web Developer / Aviation Consultant
[size="1"][ Taxiway Alpha ] [ Personal Home Page ]
benryves
benryves
If you embed the WebBrowser control on a form that will display PDFs using whichever PDF viewer the user has installed (such as Foxit Reader).

I'm afraid to say I looked around for a component myself and couldn't find anything that was cheap either.
[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]
mrbastard
mrbastard
ABCPDF is cheap(ish) but has a free option.

It's geared more towards creating pdfs, but will let you render them to an image, which you could then use in your viewer.
[size="1"]
gavco98
gavco98
Quote:
Original post by mrbastard
ABCPDF is cheap(ish) but has a free option.

It's geared more towards creating pdfs, but will let you render them to an image, which you could then use in your viewer.


I would be looking to redistribute the program I write, so that pushes the cost of ABCPDF up to $3,000. :(

Gavin Coates
[size="1"]IT Engineer / Web Developer / Aviation Consultant
[size="1"][ Taxiway Alpha ] [ Personal Home Page ]
Headkaze
Headkaze
You can use GhostScript to convert pdf pages into png's for display in your application. But you will not be able to distribute it with your application.

You can use the ActiveX control that comes with Acrobat Reader 5+. I believe the user will have to have the right version of Acrobat Reader installed to be able to use it. You will also have a bar to the left of the viewer which you can't get rid of.

It took me alot of messing around to get this class written as there doesn't seem to be much info on the Net about it. I hope it's of some use to you.

// SetView():// 'Fit'       fits whole page within the window both vertically//                and horizontally.// 'FitH'     fits the width of the page within the window.// 'FitV'     fits the height of the page within the window.// 'FitB'     fits bounding box within the window both vertically//                and horizontally.// 'FitBH'   fits the width of the bounding box within the window.// 'FitBV'   fits the height of the bounding box within the window.// * "fitv 0"// ======== // SetLayoutMode():// 'DontCare'              use the current user preference// 'SinglePage'           use single page mode (as in pre-Acrobat//                                 3.0 viewers)// 'OneColumn'           use one-column continuous mode// 'TwoColumnLeft'    use two-column continuous mode, first//                                  page on the left// 'TwoColumnRight'  use two-column continuous mode, first//    // SetPageMode():// 'none' or 'bookmarks' or 'thumbs' (Will not eliminate tabs)using System;using System.Collections.Generic;using System.Text;using System.Windows.Forms;namespace PDFViewer{    class PDFManager : IDisposable    {        private Control m_parent = null;        private AxAcroPDFLib.AxAcroPDF axAcroPDF1;        public PDFManager(Control parent)        {            m_parent = parent;        }        public bool Initialize()        {            try            {                if (axAcroPDF1 != null)                    Dispose();                //System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(PDFResource));                this.axAcroPDF1 = new AxAcroPDFLib.AxAcroPDF();                ((System.ComponentModel.ISupportInitialize)(this.axAcroPDF1)).BeginInit();                m_parent.SuspendLayout();                this.axAcroPDF1.Parent = m_parent;                this.axAcroPDF1.Visible = false;                this.axAcroPDF1.Enabled = false;                this.axAcroPDF1.Dock = System.Windows.Forms.Dockstyle.Fill;                this.axAcroPDF1.Location = new System.Drawing.Point(0, 0);                this.axAcroPDF1.Name = "axAcroPDF1";                //this.axAcroPDF1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axAcroPDF1.OcxState")));                this.axAcroPDF1.Size = new System.Drawing.Size(m_parent.Bounds.Width, m_parent.Bounds.Height);                this.axAcroPDF1.TabIndex = 0;                m_parent.Controls.Add(this.axAcroPDF1);                ((System.ComponentModel.ISupportInitialize)(this.axAcroPDF1)).EndInit();                m_parent.ResumeLayout();                axAcroPDF1.setShowScrollbars(false);                axAcroPDF1.setShowToolbar(false);                axAcroPDF1.setLayoutMode("SinglePage");                axAcroPDF1.setPageMode("none");                axAcroPDF1.setView("FitH");            }            catch (Exception ex)            {                return false;            }            return true;        }        public bool Open(string filename)        {            if (axAcroPDF1 == null)                return false;            try            {                if (axAcroPDF1.src == filename)                    return true;                axAcroPDF1.LoadFile(filename);                axAcroPDF1.gotoFirstPage();                axAcroPDF1.Refresh();                axAcroPDF1.Enabled = true;                axAcroPDF1.Visible = true;            }            catch            {                return false;            }            return true;        }        public void Refresh()        {            if (axAcroPDF1 == null)                return;            axAcroPDF1.SetBounds(0, 0, m_parent.Bounds.Width, m_parent.Bounds.Height);        }        public void NextPage()        {            if (axAcroPDF1 == null)                return;            axAcroPDF1.gotoNextPage();        }        public void PreviousPage()        {            if (axAcroPDF1 == null)                return;            axAcroPDF1.gotoPreviousPage();        }        public bool Visible        {            get { if (axAcroPDF1 != null) { return axAcroPDF1.Visible; } else return false; }            set { if (axAcroPDF1 != null) { axAcroPDF1.Visible = value; } }        }        public bool Toolbar        {            set { if (axAcroPDF1 != null) { axAcroPDF1.setShowToolbar(value); } }        }        public float Scroll        {            set { if(axAcroPDF1 != null) { axAcroPDF1.setViewScroll("FitH", value); } }        }        #region IDisposable Members        public void Dispose()        {            if (axAcroPDF1 != null)            {                axAcroPDF1.Dispose();                axAcroPDF1 = null;            }        }        #endregion    }}


[Edited by - Headkaze on June 16, 2008 1:26:44 AM]
gavco98
gavco98
thanks for the code Headkaze. However, am I right in assuming this requires Adobe Professional to be installed to work?

Unfortunately I need to be able to redistribute this application...
Gavin Coates
[size="1"]IT Engineer / Web Developer / Aviation Consultant
[size="1"][ Taxiway Alpha ] [ Personal Home Page ]
Headkaze
Headkaze
Quote:
Original post by gavco98
thanks for the code Headkaze. However, am I right in assuming this requires Adobe Professional to be installed to work?

Unfortunately I need to be able to redistribute this application...


No you don't you only need Acrobat Reader installed. Try it, it works. But like I said AFAIK they need the same version installed as the Active X control you embed in your application. Not a big problem. You did need Adobe Acrobat Pro for version 4 of the ActiveX control I believe but not 5+.

At least this way it will not cost you anything for a control. I have looked everywhere for a free alternative but there isn't one.
xDS4Lx
xDS4Lx
I'm not sure what they use but have you thought about poking around the OpenOffice.org source code, I seem to remember the Word application, I think its called Writter, had the ability to output to pdf.
"Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
gavco98
gavco98
Quote:
Original post by Headkaze
Quote:
Original post by gavco98
thanks for the code Headkaze. However, am I right in assuming this requires Adobe Professional to be installed to work?

Unfortunately I need to be able to redistribute this application...


No you don't you only need Acrobat Reader installed. Try it, it works. But like I said AFAIK they need the same version installed as the Active X control you embed in your application. Not a big problem. You did need Adobe Acrobat Pro for version 4 of the ActiveX control I believe but not 5+.

At least this way it will not cost you anything for a control. I have looked everywhere for a free alternative but there isn't one.


Ill give it another try tonight, what library do i need to reference in the code? i cant remember what one I added, but it gave me an AcroPDFLib class, which cannot be used without having Pro installed.

I did find one tutorial that referenced the AxAcroPDFLib class, however the component they mentioned to reference doesnt seem to exist on my system...?
Gavin Coates
[size="1"]IT Engineer / Web Developer / Aviation Consultant
[size="1"][ Taxiway Alpha ] [ Personal Home Page ]
Headkaze
Headkaze
Quote:
Original post by gavco98
Quote:
Original post by Headkaze
Quote:
Original post by gavco98
thanks for the code Headkaze. However, am I right in assuming this requires Adobe Professional to be installed to work?

Unfortunately I need to be able to redistribute this application...


No you don't you only need Acrobat Reader installed. Try it, it works. But like I said AFAIK they need the same version installed as the Active X control you embed in your application. Not a big problem. You did need Adobe Acrobat Pro for version 4 of the ActiveX control I believe but not 5+.

At least this way it will not cost you anything for a control. I have looked everywhere for a free alternative but there isn't one.


Ill give it another try tonight, what library do i need to reference in the code? i cant remember what one I added, but it gave me an AcroPDFLib class, which cannot be used without having Pro installed.

I did find one tutorial that referenced the AxAcroPDFLib class, however the component they mentioned to reference doesnt seem to exist on my system...?


Install Acrobat Reader 5/6/7 and look for Program Files\Adobe\Acrobat x.0\ActiveX\AcroPDF.dll. Reference that and it should give you AxAcroPDFLib.
fchivu
fchivu
You can use the html to pdf converter for .net html to pdf from http://www.winnovative-software.com to perform the html to pdf conversion with only 2 lines of code:

PdfConverter pdfConverter = new PdfConverter();
byte[] downloadBytes = pdfConverter.GetPdfFromUrlBytes(MyURL);
Headkaze
Headkaze
Quote:
Original post by fchivu
You can use the html to pdf converter for .net html to pdf from http://www.winnovative-software.com to perform the html to pdf conversion with only 2 lines of code:

PdfConverter pdfConverter = new PdfConverter();
byte[] downloadBytes = pdfConverter.GetPdfFromUrlBytes(MyURL);


I believe the OP was asking how to view PDF files inside a .NET application not how to convert html to pdf. It seems there are many components available to convert different formats to pdf's but very few to view them (free ones anyway).
the_rizman
the_rizman
They may be to expensive for what you need (don't remember the pricing), but you can check out TallComponents. They have a few .NET controls for displaying, creating etc... pdf's.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.