Coder Social home page Coder Social logo

pdfiumviewer's Introduction

PdfiumViewer

Apache 2.0 License.

Download from NuGet.

Archived

I regret to announce I'm archiving this project. I haven't been able to spend any real time on this for a long time now, and must face the fact I'm not in a position to properly support this project.

I understand that even though I haven't been able to spend time, other developers have stepped in helping out answering issues, and archiving this project will make it more difficult finding help using PdfiumViewer. I'm sorry for this inconvenience.

Together with archiving this project, I will also be archiving the PdfiumBuild project. I'll make a number of successful builds available in the PdfiumBuild repository for anyone who needs them, but the build server will be shutdown as part of archiving these projects.

I've had a great time developing this project and helping you out using this project, and I'm sad I have to now close this down. I hope PdfiumViewer has been of value to you. The source code and NuGet packages won't be going anywhere, so keep using them if they're of value to you.

Introduction

PdfiumViewer is a PDF viewer based on the PDFium project.

PdfiumViewer provides a number of components to work with PDF files:

  • PdfDocument is the base class used to render PDF documents;

  • PdfRenderer is a WinForms control that can render a PdfDocument;

  • PdfiumViewer is a WinForms control that hosts a PdfRenderer control and adds a toolbar to save the PDF file or print it.

Compatibility

The PdfiumViewer library has been tested with Windows XP and Windows 8, and is fully compatible with both. However, the native PDFium libraries with V8 support do not support Windows XP. See below for instructions on how to reference the native libraries.

Using the library

The PdfiumViewer control requires native PDFium libraries. These are not included in the PdfiumViewer NuGet package. See the Installation instructions Wiki page for more information on how to add these.

Note on the PdfViewer control

The PdfiumViewer library primarily consists out of three components:

  • The PdfViewer control. This control provides a host for the PdfRenderer control and has a default toolbar with limited functionality;
  • The PdfRenderer control. This control implements the raw PDF renderer. This control displays a PDF document, provides zooming and scrolling functionality and exposes methods to perform more advanced actions;
  • The PdfDocument class provides access to the PDF document and wraps the Pdfium library.

The PdfViewer control should only be used when you have a very simple use case and where the buttons available on the toolbar provide enough functionality for you. This toolbar will not be extended with new buttons or with functionality to hide buttons. The reason for this is that the PdfViewer control is just meant to get you started. If you need more advanced functionality, you should create your own control with your own toolbar, e.g. by starting out with the PdfViewer control. Also, because people currently are already using the PdfViewer control, adding more functionality to this toolbar would be a breaking change. See issue #41 for more information.

Building PDFium

Instructions to build the PDFium library can be found on the Building PDFium wiki page. However, if you are just looking to use the PdfiumViewer component or looking for a compiled version of PDFium, these steps are not required. NuGet packages with precompiled PDFium libraries are made available for usage with PdfiumViewer. See the chapter on Using the library for more information.

Alternatively, the PdfiumBuild project is provided to automate building PDFium. This project contains scripts to build PdfiumViewer specific versions of the PDFium library. This project is configured on a build server to compile PDFium daily. Please refer to the PdfiumBuild project page for the location of the output of the build server. The PdfiumViewer specific libraries are located in the PdfiumViewer-... target directories.

Bugs

Bugs should be reported through github at http://github.com/pvginkel/PdfiumViewer/issues.

License

PdfiumViewer is licensed under the Apache 2.0 license. See the license details for how PDFium is licensed.

pdfiumviewer's People

Contributors

dmester avatar hrhrprasath avatar iemiya avatar jasonhendrix avatar jmh3142 avatar mafshin avatar pablot avatar peter0302 avatar pvginkel avatar shameleo avatar sirmossi avatar snipx avatar stefanoraggi avatar vitorrigoni avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pdfiumviewer's Issues

Line Weight - Control + 5

Is there some way to adjust line weight for a PDF like you can in Adobe? In Adobe you can press CTRL + 5 and it will set the line weight in a PDF to 1 pixel.

ASP.NET support

Even when only one application is assigned to an application pool, multiple instances of that application are loaded during recycling. This presents problems with unmanaged DLLs that don't have a concept of app domains, but rather deal with some things at a process level.

FPDF_InitLibrary, FPDF_DestroyLibary, FPDF_GetLastError, and FSDK_SetUnSpObjProcessHandler are the methods that could be problematic.

It should be possible to modify FPDF_InitLibrary and FPDF_DestroyLibary to succeed even if the desired state (initialized, freed) is already achieved.

Callback registration, however, must stored in a thread-local manner, and re-registered before every P/Invoke call I.e, (FPDF_GetLastError, and FSDK_SetUnSpObjProcessHandler).

If anyone sees another way around theses issues (other than modifying PDFium itself), please let me know.

Navigation on content by links in PDF.

The Pdfium supported the the definition of links on a page that is very convenient to navigate through content.

I think it can be done by determining the list of rectangles of the links on the corresponding page.

I've written the following code that returns the associative array with areas (rectangles) on page and appropriate link address (page numbers):

        private Dictionary<Rectangle, int> GetLinks(IntPtr document, IntPtr page, double width, double height)
        {
            Dictionary<Rectangle, int> linckAreas = new Dictionary<Rectangle, int>();

            int startPos = 0;
            IntPtr linkAnnot;

            while (NativeMethods.FPDFLink_Enumerate(page, ref startPos, out linkAnnot))
            {
                IntPtr pdfDest = NativeMethods.FPDFLink_GetDest(document, linkAnnot);

                if (pdfDest == IntPtr.Zero)
                    continue;

                int index = (int)NativeMethods.FPDFDest_GetPageIndex(document, pdfDest);

                NativeMethods.FS_RECTF rect = new NativeMethods.FS_RECTF();
                _RectCallbacksHandle = GCHandle.Alloc(rect);

                if (NativeMethods.FPDFLink_GetAnnotRect(linkAnnot, out rect))
                {
                    int deviceX, deviceY;

                    NativeMethods.FPDF_PageToDevice(page, 0, 0, (int)width, (int)height,
                        0, rect.left, rect.top, out deviceX, out deviceY);
                    linckAreas.Add(
                        new Rectangle(deviceX, deviceY, (int)(rect.right - rect.left),
                        (int)(rect.top - rect.bottom)), index);
                }
            }

            return linckAreas;
        }

Could you help me embed this logic into your project?

FPDF_InitLibrary not getting called

Found a pretty insidious bug (or I'm doing something wrong, but I'm pretty sure it's not me), and I think the bug is in the CLR possibly. Fortunately there's an easy workaround.

InitLibrary gets called in the constructor of internal class PdfLibrary. A static instance of PdfLibrary is supposed to get created as part of the internal static PdfFile class, specifically the _library field. The code assumes - which as far as I know is supposed to always be the case - that the _library field is initialized automatically the first time any static class method is called.

Apparently this is not always the case. Under certain conditions I haven't completely identified, it is possible for _library not to be initialized when Create or another PdfFile method is called. As a result, InitLibrary does not get called, and Pdfium then crashes when any other library call is made.

I discovered this problem when installing my application onto a fresh Windows 7 install. Pdfium.dll was causing an exception and forcing a shutdown. Oddly, when I ran the application through the Visual Studio debugger, everything was fine. Since I couldn't use the debugger (as the problem would then not occur), I inserted MessageBox calls to advise when certain code lines were reached. That's when I discovered that Create was getting called before the PdfLibrary constructor.

I'm still scratching my head as to why this would happen. What's even more bizarre is why it happens running an application standalone, but not when using the VS debugger. At first I thought perhaps it was a problem with the C# code optimizer used for Release configurations. It's possible the compiler saw that the _library field was never actually referenced in the PdfFile class, and so it dropped it as an optimization. But turning off optimization didn't help. Thus I think it's a bug or at least an inconsistency in the way the CLR runtime works in standalone mode versus through a debugger.

In any event, it's easily fixed. In the PdfFile.Create method, I just added:

if ( _library == null )
_library = new PdfLIbrary();

Voila, problem solved.

I guess the lesson is we can't rely on static field initializers to get called before other class methods if those fields are not actually used by the class. If you have code that has to be called before a static class method is invoked, apparently it must be in a static constructor or the method itself.

Hope I've helped and maybe saved someone else a lot of trouble. I didn't think it was worth forking the project for this. Strongly encourage the author to make this update though as it no doubt will arise again.

PDF file stays locked after a new document load

Hello,

I started to trying to use PdfiumViewer and I think I found some bugs. (or I do something wrong :))
But first of all thank you! This is the fastest solution for PDF viewing I found so far.
Keep it up!

So the first problem:

pdfViewer1.Document = PdfDocument.Load("D:\1.pdf");
pdfViewer1.Document = PdfDocument.Load("D:\2.pdf");
//here I cannot delete D:\1.pdf
pdfViewer1.Document = null;
pdfViewer1.Document.Dispose();
//no change

After the form closed I can delete all of them.

Regards,
Csontikka

Editable PDF Support in PDFViewer

Hi,

I would like to know if there's any support for Editable PDF in PDFViewer, as i want to use the PDFViewer and PDF has editable fields which after filled will be saved.

And also, support for Signature is there?

Thanks

Change license to the Apache2 license

I would like to change the license of the PdfiumViewer project to the Apache2 license. The Apache2 license puts less restrictions on how the PdfiumViewer library is used in other projects compared to the LGPL 3.0 license.

For this I need permission from people who made significant contributions to PdfiumViewer. If this isn't a problem for you, please leave a comment so that the license can be changed:

Programmatically scroll to a particular spot on a page upon display

Hi Pieter, I believe we are almost at the end of the road here. If you are able to help out with this last requirement, it would be really great. Due to size very small size of the screen that my users will be using to view pdf documents, I'd like to go to scroll to a particular Y cordinate on a page upon displaying the page. So far, the methods that you have provide will take you to the top of a document or the bottom of one. You also created a new method to take a user to a specified page. I've tried to use the code pdfViewerBox.Renderer.SetDisplayRectLocation(new Point(0, -fieldposY)) to accomplish this goal, "-fieldposY" representing the spot that I want to go to. This works great when it's only one page but then when you have a multiple page document, it does not go beyond the first page. Perhaps because of the PDFRenderer. Please advise. Thanks

Increase private const ZoomMax?

Hallo Pieter,

firstly thank you so much for providing this great control.
My only problem is the max zoom value for which the underlying reason is something else:
The problem is that the initial zoom value when loading a document is always 1 and not the "true" zoom value relative to the size of the document.
I am sure you had your reasons for that behaviour - because you also calculate the "true" zoom internally. But it basically means that when having a large document and/or a relatively small initial size of the control your document only gets opened with maybe 20% of its original size and you are not able to zoom it to more than 100% of its size.

Is there a need for a max value at all? And if so would it not at least be possible to increase it to something like 100?

Thanks for reading,
Boris

Printouts are moved (resized?) to bottom-right corner.

On physical printer (tested on 2 printers HP and EPSON) printouts are moved to bottom - right corner. Sometimes they has cutted right edge. I attached hard copies from pdfium and syncfusion. As you can see in syncfusion (bottom image) is in center of sheet, but in pdfium is moved (or resized?) to bottom-right corner.

When I use XPS printer everything is ok, the issue is only on physical printers!

pdfium
syncfusion

I have hope that i can check code and repair that in maybe 2 weeks from now. But if you have some time I will be very grateful.

ZoomIn functionality

The current ZoomIn function will not retain the current page in the render's view. The Mouse Scroll function will calculate the current mouse location, which works fine, but the zoomin function for buttons should be modified to stay in the current sheet in view.

EX: Open a document with say 7 pages. Scroll down to the last page and zoom in multiple times, you will end up back at page 3 or 2.

Current Workaround I have implemented, create a method to return the current page bounds in the PdfRenderer class and then create a new zoomin method in the PanningZoomingScrollControll class to accept the bounds from the current page and zoom in.

It would be nice if there was either a method to call to do this or have the zoomin function do this by default.

Memory usage

I noticed that if I opened a sample PDF, closed it, opened a different sample, and repeated the process that the memory usage continually increased.

So I used the PdfiumViewer.Demo project and the only change I made was to make the project use .NET Framework 4.6.1 rather than the default so that I could use the built in memory diagnostic tool in Visual Studio. The same problem happened there as well.

Is there something I should do to properly dispose items once finished viewing a given file?

Trimmed bookmark titles

From version 2.8.0.0 PdfiumViewer trim last character from bookmark titles. Problem is in PdfFile.cs - native method FPDF_BookmarkGetTitle returns real bookmark title and trimming last character is useless.

private string GetBookmarkTitle(IntPtr bookmark)
{
      uint length = NativeMethods.FPDF_BookmarkGetTitle(bookmark, null, 0);
      byte[] buffer = new byte[length];
      NativeMethods.FPDF_BookmarkGetTitle(bookmark, buffer, length);

      string result = Encoding.Unicode.GetString(buffer);
      return result.Substring(0, result.Length - 1);
}

image

Document Rotation

Are you able to rotate a already loaded PDF document? I cannot seem to find any function for this inside of the code.

Text Extraction

Hey guys -
I needed simple text extraction and went ahead and added it in my copy. Very easy to do. The changes are:

NativeMethods.cs, NativeMethods, add:

    /* PNM */
    [DllImport("pdfium.dll")]
    public static extern int FPDFText_CountChars(IntPtr page);

    /* PNM */
    [DllImport("pdfium.dll")]
    public static extern int FPDFText_GetText(IntPtr page, int startIndex, int count, IntPtr result);

PdfFile.cs, PdfFile, add:

    /*PNM*/
    public int GetCharacterCount(int pageNumber)
    {
        using (var pageData = new PageData(_document, _form, pageNumber))
        {
            return NativeMethods.FPDFText_CountChars(pageData.TextPage);
        }
    }

    /*PNM*/
    public unsafe string GetText(int pageNumber)
    {
        using (var pageData = new PageData(_document, _form, pageNumber))
        {
            int count = NativeMethods.FPDFText_CountChars(pageData.TextPage);
            IntPtr buffer = Marshal.AllocHGlobal((count+1) * 2);
            int read = NativeMethods.FPDFText_GetText(pageData.TextPage, 0, count, buffer);
            var result = new String((char*)buffer);
            Marshal.FreeHGlobal(buffer);
            return result;
        }
    }

PdfDocument.cs, PdfDocument, add:

    /* PNM */
    public int GetCharacterCount (int page)
    {
        return _file.GetCharacterCount(page);
    }

    /* PNM */
    public string GetText (int page)
    {
        return _file.GetText(page);
    }

Just want to know if you'd prefer I fork this or if you want to incorporate it yourself. If I do fork it I'll probably add some more sophisticated extraction such as obtaining the coordinates of the text.

Also, are we still under LGPL3 or did you switch to Apache? I saw the issue was closed but the license still says LGPL3. Fine either way.

Peter

WinRT (Windows Store App) Support?

Hey Pieter-
While you're working on other updates to this great library, what are your thoughts about the possibility of this ever working on WinRT (Windows Store apps)? I know WinRT has a built-in PdfDocument API but it's very slow compared to Pdfium. We'd need to make a new build of Pdfium that played nice with WinRT but it shouldn't be too hard. (There could already be one for all I know, but I haven't found it).

Thanks!

Peter

Aliasing on Transparent Background

Is there a way to force the background color used for aliasing? It looks like text on a transparent background is aliased with the assumption that it will be rendered on black, not white.

Examples:

default (transparent)

pdf-1

when rendered on a black graphics context:

pdf-2

Rendering (not filling) form fields

Does PdfiumViewer support rendering form fields?
Example:
http://www.humanservices.gov.au/spw/health-professionals/forms/resources/pb154-1507en.pdf

(it's a PDF document from Medicare Australia with some PDF form fields on it)

I can fill out the form using Adobe, Nitro or even my own PDF toolkit (Essential Objects PDF). What I'd like to do is then render that PDF with its filled-in information.

There's an issue on here - #22 - which implies this isn't supported, but that issue more talks about filling in form fields rather than rendering them. I'm just trying to confirm whether or not rendering is actually supported (as I've got the filling aspect already covered)

Thanks!

Ian

Go to last page

Hi Pieter, looking at using pdfiumviewer for a c# windows project that I'm doing. Integration has been successful so far however i'm stuck at trying to have the viewer default to the the last page of the currently loaded document immediately it loads. I can't find any documentation on it and I'm not even sure this is the right place to come for help. The Adobe reader viewer has a command GoToLastPage that fulfills this goal but for other handicaps that Adobe reader has, my team prefers the PdfiumViewer. Can you please try to help me or point me a direction to get help on this? The c# code that I use to load my pdf document is
this.pdfViewer1.Document = PdfiumViewer.PdfDocument.Load(filename); . Thank you.

Missed parameters in the RenderPDFPageToBitmap() method.

Hello,

I'm using a custom printing form with additional parameters to print a document so I use RenderPDFPageToBitmap() method from PdfFile class instead of the standard Print(). But this method doesn't use dpiX and dpiY parameters, so I can't choose the quality of rendering.

Thanks,

64bit support?

Is 64bit support planned using a 64bit build of pdfium.dll? This would be useful to use the library to render pdf previews on windows server.

Feature request: pdffonts-like functionality

Just that - being able to get a list of linked, embedded fonts and some technical details about them. I submitted this upstream too (PDFium plain...I may or may not submit it to PDF.js also) but figure the more eyes on it who might be interested, the better.

Go to a particular page on display

Hi Pieter, a great feature to look at adding to the PDFiumviewer would be to be able to go to a particular or specified page number upon display of the pdf. Thanks

The orientation of pages

All pages in PdfViewer are displayed identically regardless of their orientation (portrait or landscape).

Question - zooming without Ctrl

Is it possible to change a setting on the viewer to allow the Mouse Scroll Wheel to Zoom rather than to scroll the document? (I see that it does this normally when you're holding Control)

Resolution is off in bitmap output

From what I've gathered, the page dimensions as reported by PdfiumViewer are off by a factor of 1.3 which ultimately leads to an incorrect size of the bitmap output.

The default DPI value for PDF documents is 72 DPI. I used ImageMagick output to confirm that that is also true for my test PDF file.

It looks like you are getting the page dimensions from the native library. So I am not sure whether this actually is something you can do anything about.

Here is what I am currently doing to work around that (and to output resolutions other than 96 DPI):

var dpiTarget = 150;
var pdfDpiDefault = 72D;

float systemDpiX;
float systemDpiY;
using (Graphics graphics = Graphics.FromHwnd(IntPtr.Zero))
{
    systemDpiX = graphics.DpiX;
    systemDpiY = graphics.DpiY;
}

var pageWidthPixels = (int)pdf3.PageSizes[0].Width;
var pageHeightPixels = (int)pdf3.PageSizes[0].Height;

var cX = systemDpiX / pdfDpiDefault;
var cY = systemDpiY / pdfDpiDefault;

var dpiX = (int)(dpiTarget * cX);
var dpiY = (int)(dpiTarget * cY);

var factorX = dpiX / systemDpiX;
var factorY = dpiY / systemDpiY;

var renderWidthPixels = (int)Math.Round(pageWidthPixels * factorX, 0, MidpointRounding.AwayFromZero);
var renderHeightPixels = (int)Math.Round(pageHeightPixels * factorY, 0, MidpointRounding.AwayFromZero);

using (var image = pdf3.Render(0, renderWidthPixels, renderHeightPixels, dpiX, dpiY, false))
{
    // ...
}

I also tried using the other Render signatures for getting the correct output resolution (i.e. Graphics.FromImage(bitmap) but using a value other than 96 dpi screwed up the output (e.g. incorrect font sizes and/or incorrect output size (lots of white space)). So I think that something is not quite right about the transforms in that method.

Go to the next / previous page.

Hello,

I found the issue, which is reproduced by the following steps:

  1. Load pdf that contain consecutive three portrait pages and three landscape pages

  2. Change zoom to 50%

  3. Invoke the next code 3 times.

    public void GoToNextPage()
    {
        _renderer.Page++;
    }
    

The viewer displays page 4, that is landscape.

  1. Try to invoke the next code:

    public void GoToPreviousPage()
    {
        _renderer.Page--;
    }
    

Actual result: the page is not changed.
Expected result: the viewer displays page 3.

Thanks,

Missed handling of Left and Right keys.

Hello,

I believe that in the IsInputKey(Keys keyData) method of PanningZoomingScrollControl class was missed code to handle clicking on Left and Right buttons:

case Keys.Left:
    PerformScroll(ScrollAction.LineUp, Orientation.Horizontal);
    return true;

case Keys.Right:
    PerformScroll(ScrollAction.LineDown, Orientation.Horizontal);
    return true;

Thanks,

Memory utilization in WPF

I am looking for recommendations (or fixes if need be) for rendering PDF's using native WPF controls, without unnecessarily inflating the application's memory footprint.

Testing environment:

  • PDF is 615kb, containing 8 pages of text scanned as an image (from some sort of multi-function printer/scanner). Specific file cannot be shared due to sensitivity, but does not appear to be abnormal.
  • WPF application using 4.5.1 framework

To isolate the impact as much as possible, I have made the following changes to the PDFDemo provided:
XAML:

    <ScrollViewer Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="2">
        <StackPanel>
            <Image x:Name="imageMemDC1" />
            <Image x:Name="imageMemDC2" />
            <Image x:Name="imageMemDC3" />
            <Image x:Name="imageMemDC4" />
            <Image x:Name="imageMemDC5" />
            <Image x:Name="imageMemDC6" />
            <Image x:Name="imageMemDC7" />
            <Image x:Name="imageMemDC8" />
        </StackPanel>
    </ScrollViewer>

XAML.CS:

    var imageMemDC = this.FindName(String.Format("imageMemDC{0}", i)) as System.Windows.Controls.Image;

so basically, instead of one image control, I've got one for each of the pages... then instead of rendering each page over the previous image, I render them to individual controls.


These changes alone are sufficient to reproduce the memory consumption I'm seeing, though in my application I've also adjusted the width/height to be the PageSize.Width * 4 and PageSize.Height * 4, to produce "crisp" images. Using the default pagesize (with 96 dpi) seems to generate blurry text. Again, not a huge difference, except that the memory consumption is larger with my changes, due to the larger image resolution.


Test Results:

The application's memory footprint starts at ~43mb (TaskMgr showing Private Working Set). VMMap shows that the total private bytes are 75MB, while private WS bytes is 45MB; of this, "Private Data" accounts for 45MB of the private memory, and 30MB of the private WS memory.

Once the PDF is loaded, TaskMgr shows the process to consume 80MB (private working set), VMMap shows 116MB total private, 83MB private WS, and private data accounts for 66MB of private and 50MB of private WS.

Once the pages are rendered, TaskMgr shows the process to consume 90MB, VMMap shows 130MB total private, 93MB private WS, and private data accounts for 77MB of private and 60MB of private WS.

Using the higher resolution (pagesize.width_4 x pagesize.height_4), the same PDF rendered consumes 311MB of memory (TaskMgr private WS), with VMMap showing 350MB total private, 317 private WS, and private data accounting for 299MB private and 282MB private WS.


I have also considered other approaches:

  • the PdfiumViewer nuget package includes two WinForms controls, the PdfViewer and PdfRenderer... by including them in the WPF application (wrapped in a WindowsFormHost control), the same file is rendered with no notable increase in memory usage. During rapid resizing of the application/controls, I noticed unpainted areas of the window (black areas while expanding the window), which leads me to suspect that the WinForms controls use GDI to repaint the PDF on scroll/resize/etc; I suspect that this is done directly from file each time, instead of keeping the file/pages in memory.

From searching for causes/solutions, I found #6 which suggests that perhaps the Render method (used by the WPFDemo code to render the PDF) was originally intended for saving pages to files. In this case, I would question what better alternatives there may be, for rendering pages of the PDF in native WPF controls.


I have attached screenshots of the difference between rendering with the PDF's PageSize dimensions, and PageSize * 4.
at pagesize
at 4x x 4x

Scrollbar not resets and has double size after a new document load to the same pdfViewer

Try it yourself:

pdfViewer1.Document = PdfDocument.Load("D:\1.pdf");
//now scroll down to the end of the file
//now load a new pdf to this viiewer
pdfViewer1.Document = PdfDocument.Load("D:\1.pdf");
//for me the result is:
//(first bug) the scroll bar is twice larger than it should be.
//(secong bug) It does not jumps back to the top of the document.

Br,
Csontikka

Document use case of the PdfViewer control

A number of issues and pull requests have been created to extend the toolbar of the PdfViewer control. However, these should not be applied. The reason for this is that the PdfViewer control really is not meant to be used for advanced use cases.

The purpose of the PdfViewer control is to have a fast starting point to get up and running. However, most people will want to customize their experience and have control over what kind of functionality they want to expose. Because of this they should be using the PdfRenderer control. This control has the same functionality as the PdfViewer control, except that it does not have a toolbar. The PdfViewer control can still be used as a starting point, e.g. by copy and pasting the code into your own project. That way you can get the exact functionality you desire.

The primary problem with the existence of the PdfViewer control is that people do use this and changing it will break their application, because they expect the buttons that are there now to stay there. Looking back the PdfViewer control should never have been added to the project.

This information should be documented in the main README file.

Signature fields

The current version does (by default) not show fields with a digital signature.

Is there a way to get those fields shown, or is the functionality currently unavailable?

An excellent piece of work, it took me about 1 minute to get a pdf file showing, zoomed to "fit width", in a new form!

Some PDFs can't be rendered

There are some PDF files which Pdfium fails to open.

One of them is this file. I have some other files like this. These can be viewed with Chrome, Acrobat and Windows Reader but Pdfium can't. Since chrome uses Pdfium behind the scene probably the ported version have some problems.

The other sample is this file that isn't rendered correctly. As I zoom in or out the cover render will change.

s

Text selection

Is text selection possible or is it a new feature?

(And after text selection, copy to clipboard)?

Opening a password protected PDF File

Hello Good Day,

I tried opening a password protected pdf document, the program crashes and said "vshost-clr1.exe has stopped working".....can you include support for password protected PDF Files. thank you very much

Make interface for navigation bar.

Hello,

I use PdfViewer in conjunction with the navigation bar, so it would be very convenient if PdfViewer supported interface, which would allow to communicate with the control panel.

I think it may look something like this:

interface IPdfViewerNavigation
{
    // Print the Document.
    void Print();
    // Fit one full page to window.
    void FitPage();
    // Fit to window width and enable scrolling.
    void FitPageWith();
    // Increase the scale.
    void ZoomIn();
    // Decrease the scale.
    void ZoomOut();
    // The certain value of zoom.
    double ExactZoomValue { get; set; }
    // Turn to the previous page.
    void GoToPreviousPage();
    // Turn to the next page.
    void GoToNextPage();
    // The current page.
    int CurrentPage { get; set; }
    // Returns the number of pages in the document.
    int PageCount { get; }
}

If PdfViewer will inherit this interface, it will be very convenient to associate it with any such navigation bar.

Thanks,

Can not run on XP.But can bulid.

Thanks for this great project.
But I can't run it. I didn't make any changes.
My environment is VS2010 +.Net4.0 + XP
Compiler success. But open the PDF file, prompt as follows:
"Try to read or write protected memory. This usually indicates that other memory is corrupt."
Who can help me?

Problem loading viewer

I'm a first time user of the PDFiumViewer. I Installed the viewer as instructed and have included image file demonstrating my setup. I believe the viewer is installed correctly and the problem is related to my lack of knowledge on how to use of the control. I have attached 2 image files that contain my code and show the error message I'm receiving. A couple of additional pieces of information about my setup. The project was developed with vs 2010, the os is window 7, vm 9x.
I'm hoping there is simple explanation. Thanks in advanced for the assistance in this matter.

pdfiumviewer error 1
pdfiumviewer error 2
pdfiumviewer error 3
pdfiumviewer error 4

Pdfium.Net SDK

Question - Does this work with the Pdfium.Net SDK NuGet package or do you still need to compile the SDK?

PdfPrintDocument hides the printing events

Just curious about the decision to override the OnBeginPrint, OnQueryPageSettings and OnPrintPage functions in PdfPrintDocument rather than simply using the delegate model and registering functions to be called for those events? By overriding the OnXXX funcitons, you have removed the ability for anyone using the PdfViewer control to add any specialized printing functions. For example, I have a program that prints documents without displaying the print dialog. There are settings within my program that allow the end user to choose what printer to use and what settings to use for the printer and I set that info myself before calling Print(). I now have a need to print the first page of a document from a different paper tray than the remaining pages. In order to do that, I need to be able to handle the QueryPageSettings and PrintPage events so that I can change the paper source as desired. I have already tested whether this would work with your PdfPrintDocument class and by changing the code from overriding the OnXXX functions, to using the delegate model, I get exactly the functionality that I need. I have attached my version of PdfPrintDocument.cs for your review.

PdfPrintDocument.cs.txt

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.