diff --git a/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/PDFiumSharp/PDFiumSharp.Wpf.dll b/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/PDFiumSharp/PDFiumSharp.Wpf.dll deleted file mode 100644 index 9e92d16..0000000 Binary files a/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/PDFiumSharp/PDFiumSharp.Wpf.dll and /dev/null differ diff --git a/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/PDFiumSharp/PDFiumSharp.Wpf.xml b/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/PDFiumSharp/PDFiumSharp.Wpf.xml deleted file mode 100644 index 6d7dfe0..0000000 --- a/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/PDFiumSharp/PDFiumSharp.Wpf.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - PDFiumSharp.Wpf - - - - - Renders the page to a - - The page which is to be rendered. - The bitmap to which the page is to be rendered. - The destination rectangle in . - The orientation at which the page is to be rendered. - The flags specifying how the page is to be rendered. - - - - Renders the page to a - - The page which is to be rendered. - The bitmap to which the page is to be rendered. - The orientation at which the page is to be rendered. - The flags specifying how the page is to be rendered. - - - diff --git a/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/PDFiumSharp/PDFiumSharp.dll b/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/PDFiumSharp/PDFiumSharp.dll deleted file mode 100644 index 96bcd8a..0000000 Binary files a/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/PDFiumSharp/PDFiumSharp.dll and /dev/null differ diff --git a/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/PDFiumSharp/PDFiumSharp.xml b/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/PDFiumSharp/PDFiumSharp.xml deleted file mode 100644 index 8e91bf4..0000000 --- a/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/PDFiumSharp/PDFiumSharp.xml +++ /dev/null @@ -1,1521 +0,0 @@ - - - - PDFiumSharp - - - - - PDF Action Types - - - - - Unsupported action type. - - - - - Go to a destination within current document. - - - - - Go to a destination within another document. - - - - - URI, including web pages and other Internet resources. - - - - - Launch an application or open a file. - - - - - Gray scale bitmap, one byte per pixel. - - - - - 3 bytes per pixel, byte order: blue, green, red. - - - - - 4 bytes per pixel, byte order: blue, green, red, unused. - - - - - 4 bytes per pixel, byte order: blue, green, red, alpha. - - - - - Flags specifying document permissions. - - - - PDF Reference: Table 22 - - - - For of 2: Print the document. - For of 3 or greater: Print the document - (possibly not at the highest quality level, depending on whether is also set). - - - - - Modify the contents of the document by operations other than those controlled by , - and . - - - - - For of 2: Copy or otherwise extract text and graphics from the document, - including extracting text and graphics (in support of accessibility to users with disabilities or for other purposes). - For of 3 or greater: Copy or otherwise extract text and graphics from - the document by operations other than that controlled by . - - - - - Add or modify text annotations, fill in interactive form fields, and, if is also set, - create or modify interactive form fields (including signature fields). - - - - - For of 3 or greater: Fill in existing interactive form fields - (including signature fields), even if is not set. - - - - - For of 3 or greater: Extract text and graphics - (in support of accessibility to users with disabilities or for other purposes). - - - - - For of 3 or greater: Assemble the document - (insert, rotate, or delete pages and create bookmarks or thumbnail images), even if is not set. - - - - - For of 3 or greater: Print the document to a representation - from which a faithful digital copy of the PDF content could be generated. When is not set - (and is set), printing is limited to a low-level representation of the appearance, possibly of degraded quality. - - - - - Flatten for normal display. - - - - - Flatten for print. - - - - - Flatten operation failed. - - - - - Flatten operation succeed. - - - - - Nothing to be flattened. - - - - - Unknown page mode. - - - - - Document outline, and thumbnails hidden. - - - - - Document outline visible. - - - - - Thumbnail images visible. - - - - - Full-screen mode, no menu bar, window controls, or other decorations visible. - - - - - Optional content group panel visible. - - - - - Attachments panel visible. - - - - - - - - Gets the pages in the current . - - - - - Gets the PDF file version. File version: 14 for 1.4, 15 for 1.5, ... - - - - - Gets the revision of the security handler. - - PDF Reference: Table 21 - - - - Creates a new . - must be called in order to free unmanaged resources. - - - - - Loads a from the file system. - must be called in order to free unmanaged resources. - - Filepath of the PDF file to load. - - - - Loads a from memory. - must be called in order to free unmanaged resources. - - Byte array containing the bytes of the PDF document to load. - The index of the first byte to be copied from . - The number of bytes to copy from or a negative value to copy all bytes. - - - - Loads a from '' bytes read from a . - must be called in order to free unmanaged resources. - - - The number of bytes to read from the . - If the value is equal to or smaller than 0, the stream is read to the end. - - - - - Closes the and frees unmanaged resources. - - - - - Saves the to a . - - - The new PDF file version of the saved file. - 14 for 1.4, 15 for 1.5, etc. Values smaller than 10 are ignored. - - - - - Saves the to the file system. - - - The new PDF file version of the saved file. - 14 for 1.4, 15 for 1.5, etc. Values smaller than 10 are ignored. - - - - - Static class containing the native (imported) PDFium functions. - In case of missing documentation, refer to the PDFium header files. - - - - - Gets a value indicating whether the PDFium library is available. - false is returned if the native libraries could not be - loaded for some reason. - - - - - Loads a PDF document from memory. - - The data to load the document from. - The index of the first byte to be copied from . - The number of bytes to copy from or a negative value to copy all bytes. - - - - Loads a PDF document from '' bytes read from a stream. - - - The number of bytes to read from the . - If the value is equal to or smaller than 0, the stream is read to the end. - - - - - Get the named destination by index. - - Handle to a document. - The index of a named destination. - - The destination handle and name for a given index, or (, null) - if there is no named destination corresponding to . - - - - - - - Get the title of . - - Handle to the bookmark. - The title of the bookmark. - - - - Gets the file path of a of type or . - - Handle to the action. Must be of type or . - The file path of . - - - - - Gets URI path of a of type . - - Handle to the document. - Handle to the action. Must be of type . - The URI path of . - - - - - Enumerates all the link annotations in . - - Handle to the page. - All the link annotations in . - - - - Get meta-data content from . - - Handle to the document. - - The tag to retrieve. The tag can be one of: - Title, Author, Subject, Keywords, Creator, Producer, - CreationDate, or ModDate. - - The meta-data. - - For detailed explanations of these tags and their respective - values, please refer to PDF Reference 1.6, section 10.2.1, - 'Document Information Dictionary'. - - PDF Reference - - - - - Get meta-data content from . - - Handle to the document. - The tag to retrieve. - The meta-data. - - For detailed explanations of these tags and their respective - values, please refer to PDF Reference 1.6, section 10.2.1, - 'Document Information Dictionary'. - - PDF Reference - - - - - Insert into . - - Handle to a page. - Handle to a page object. The will be automatically freed. - - - - Load an image from a JPEG image file and then set it into . - - All loaded pages, may be null. - Handle to an image object. - Stream which provides access to an JPEG image. - The number of bytes to read from or 0 to read to the end. - - If true, this function loads the JPEG image inline, so the image - content is copied to the file. This allows - to be closed after this function returns. - - true on success. - - The image object might already have an associated image, which is shared and - cached by the loaded pages. In that case, we need to clear the cached image - for all the loaded pages. Pass to this API - to clear the image cache. If the image is not previously shared, null is a - valid value. - - - - - Set to . - - All loaded pages, may be null. - Handle to an image object. - Handle of the bitmap. - true on success. - - - - Returns a font object loaded from a stream of data. The font is loaded - into the document. The caller does not need to free the returned object. - - Handle to the document. - A value specifying if the font is a CID font or not. - The data, which will be copied by the font object. - The index of the first byte to be copied from . - The number of bytes to copy from or a negative value to copy all bytes. - Returns NULL on failure. - - - - Imports pages from to - - Zero-based index of where the imported pages should be inserted in the destination document. - Zero-based indices of the pages to import in the source document - - - - Saves a PDF document to a stream. - - - The new PDF file version of the saved file. - 14 for 1.4, 15 for 1.5, etc. Values smaller than 10 are ignored. - - - - - - - Get the alternative text for a given element. - - Handle to the struct element. - The alternative text for . - - - Initialize the PDFium library - Convenience function to call for - backwards comatibility purposes. - - - - Initialize the PDFium library - You have to call this function before you can call any PDF - processing functions. - - - - Release all resources allocated by the PDFium library. - You can call this function to release all memory blocks allocated by - the library. - After this function is called, you should not call any PDF - processing functions. - - - - Open and load a PDF document.Path to the PDF file (including extension). - A string used as the password for the PDF file. - If no password is needed, or null can be used. - A handle to the loaded document, or NULL on failure. - Loaded document can be closed by . - If this function fails, you can use to retrieve - the reason why it failed. - - - - - Open and load a PDF document from memory.Pointer to a buffer containing the PDF document.Number of bytes in the PDF document. - A string used as the password for the PDF file. - If no password is needed, or null can be used. - A handle to the loaded document, or NULL on failure. - - The memory buffer must remain valid when the document is open. - The loaded document can be closed by . - If this function fails, you can use to retrieve - the reason why it failed. - - - If PDFium is built with the XFA module, the application should call - function after the PDF document loaded to support XFA - fields defined in the fpdfformfill.h file. - - - - - - Load PDF document from a custom access descriptor.A structure for accessing the file.Optional password for decrypting the PDF file.A handle to the loaded document, or NULL on failure. - - The application must keep the file resources valid until the PDF - document is closed. - The loaded document can be closed with FPDF_CloseDocument. - - - If PDFium is built with the XFA module, the application should call - function after the PDF document loaded to support XFA - fields defined in the fpdfformfill.h file. - - - - - - Get the file version of the given PDF document.Handle to a document.The PDF file version. File version: 14 for 1.4, 15 for 1.5, ...True if succeeds, false otherwise. - If the document was created by , - then this function will always fail. - - - - - Get last error code when a function fails. - If the previous SDK call succeeded, the return value of this - function is not defined. - - - - - - - - - - - - Get total number of pages in the document.Handle to document.Total number of pages in the document. - - - - - Load a page inside the document.Handle to document.Zero-based index of the page.A handle to the loaded page, or NULL if page load fails.The loaded page can be closed using FPDF_ClosePage. - - - - - Get page width.Handle to the page. - Page width (excluding non-displayable area) measured in points. - One point is 1/72 inch (around 0.3528 mm). - - - - - Get page height.Handle to the page. - Page height (excluding non-displayable area) measured in points. - One point is 1/72 inch (around 0.3528 mm) - - - - - Get the size of the page at the given index.Handle to document.Zero-based index of the page.Pointer to a double to receive the page width (in points).Pointer to a double to receive the page height (in points). - - - - Render contents of a page to a device independent bitmap. - Handle to the device independent bitmap (as the - output buffer). The bitmap handle can be created - by . - Handle to the page.Left pixel position of the display area in bitmap coordinates.Top pixel position of the display area in bitmap coordinates.Horizontal size (in pixels) for displaying the page.Vertical size (in pixels) for displaying the page.Page orientation. - for normal display, or combination of the Page - Rendering flags defined above. With the - flag, it renders all annotations that do not require - user-interaction, which are all annotations except - widget and popup annotations. - - - - - Render contents of a page to a device independent bitmap. - Handle to the device independent bitmap (as the - output buffer). The bitmap handle can be created - by . - Handle to the page.The transform matrix.The rect to clip to. - for normal display, or combination of the Page - Rendering flags defined above. With the - flag, it renders all annotations that do not require - user-interaction, which are all annotations except - widget and popup annotations. - - - - Close a loaded PDF page.Handle to the loaded page. - - - - Close a loaded PDF document.Handle to the loaded document. - - - - - - - - - - - - Create a device independent bitmap (FXDIB).The number of pixels in width for the bitmap. Must be greater than 0. The number of pixels in height for the bitmap. Must be greater than 0.A value indicating whether the alpha channel is used.The bitmap handle, or if parameter error or out of memory. - The bitmap always uses 4 bytes per pixel. The first byte is always - double word aligned. - - The byte order is BGRx (the last byte unused if no alpha channel) or BGRA. - - The pixels in a horizontal line are stored side by side, with the - left most pixel stored first (with lower memory address). - Each line uses width * 4 bytes. - - Lines are stored one after another, with the top most line stored - first. There is no gap between adjacent lines. - - This function allocates enough memory for holding all pixels in the - bitmap, but it doesn't initialize the buffer. Applications can use - to fill the bitmap using any color. - - - - - Create a device independent bitmap (FXDIB).The number of pixels in width for the bitmap. Must be greater than 0. The number of pixels in height for the bitmap. Must be greater than 0. - A pointer to the first byte of the first line if - using an external buffer. If this parameter is - then the a new buffer will be created. - Number of bytes for each scan line, for external buffer only.The bitmap handle, or if parameter error or out of memory. - Similar to function, but allows for more formats - and an external buffer is supported. The bitmap created by this - function can be used in any place that a handle is required. - - If an external buffer is used, then the application should destroy - the buffer by itself. function will not destroy - the buffer. - - - - - Fill a rectangle in a bitmap.The handle to the bitmap.The left position. Starting from 0 at the left-most pixel.The top position. Starting from 0 at the top-most line.Width in pixels to be filled.Height in pixels to be filled. - This function sets the color and (optionally) alpha value in the - specified region of the bitmap. - - NOTE: If the alpha channel is used, this function does NOT - composite the background with the source color, instead the - background will be replaced by the source color and the alpha. - - If the alpha channel is not used, the alpha parameter is ignored. - - - - - - Get data buffer of a bitmap.Handle to the bitmap as returned by .The pointer to the first byte of the bitmap buffer. - The stride may be more than width * number of bytes per pixel - - Applications can use this function to get the bitmap buffer pointer, - then manipulate any color and/or alpha values for any pixels in the bitmap. - - The data is in BGRA format. Where the A maybe unused if alpha was - not specified. - - - - - Get width of a bitmap.Handle to the bitmap as returned by .The width of the bitmap in pixels. - - - - Get height of a bitmap.Handle to the bitmap as returned by .The height of the bitmap in pixels. - - - - Get number of bytes for each line in the bitmap buffer.Handle to the bitmap as returned by .The number of bytes for each line in the bitmap buffer.The stride may be more than width * number of bytes per pixel. - - - - Destroy a bitmap and release all related buffers.Handle to the bitmap as returned by . - This function will not destroy any external buffers provided when - the bitmap was created. - - - - - Whether the PDF document prefers to be scaled or not.Handle to the loaded document. - - - - Returns the number of copies to be printed.Handle to the loaded document.The number of copies to be printed. - - - - Page numbers to initialize print dialog box when file is printed.Handle to the loaded document.The print page range to be used for printing. - - - Returns the paper handling option to be used when printing from the print dialog.Handle to the loaded document.The paper handling option to be used when printing. - - - - Gets the contents for a viewer ref, with a given key. The value must be of type "name".Handle to the loaded document.Name of the key in the viewer pref dictionary.A string to write the contents of the key to.Length of the buffer. - The number of bytes in the contents, including the NULL terminator. - Thus if the return value is 0, then that indicates an error, such - as when |document| is invalid or |buffer| is NULL. If |length| is - less than the returned length, or |buffer| is NULL, |buffer| will - not be modified. - - - - Get the count of named destinations in the PDF document.Handle to the loaded document.The count of named destinations. - - - - - Get a the destination handle for the given name.Handle to the loaded document.The name of a destination.The handle to the destination. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Create a new PDF document.Returns a handle to a new document, or NULL on failure. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - A bitmap to which a can be rendered. - - - - - Creates a new . Unmanaged memory is allocated which must - be freed by calling . - - The width of the new bitmap. - The height of the new bitmap. - A value indicating wheter the new bitmap has an alpha channel. - - A bitmap created with this overload always uses 4 bytes per pixel. - Depending on the is then either - or . - - - - - Creates a new using memory allocated by the caller. - The caller is responsible for freeing the memory and that the adress stays - valid during the lifetime of the returned . To free - unmanaged resources, must be called. - - The width of the new bitmap. - The height of the new bitmap. - The format of the new bitmap. - The adress of the memory block which holds the pixel values. - The number of bytes per image row. - - - - Fills a rectangle in the with . - The pixel values in the rectangle are replaced and not blended. - - - - - Fills the whole with . - The pixel values in the rectangle are replaced and not blended. - - - - - - Saves the in the BMP file format. - - - - - Saves the in the BMP file format. - - - - - Exposes the underlying image data directly as read-only stream in the - BMP file format. - - - - - Gets the page width (excluding non-displayable area) measured in points. - One point is 1/72 inch(around 0.3528 mm). - - - - - Gets the page height (excluding non-displayable area) measured in points. - One point is 1/72 inch(around 0.3528 mm). - - - - - Gets the page width and height (excluding non-displayable area) measured in points. - One point is 1/72 inch(around 0.3528 mm). - - - - - Gets the page orientation. - - - - - Gets the zero-based index of the page in the - - - - - Gets the which contains the page. - - - - - Renders the page to a - - The bitmap to which the page is to be rendered. - The destination rectangle in . - The orientation at which the page is to be rendered. - The flags specifying how the page is to be rendered. - - - - Renders the page to a - - The bitmap to which the page is to be rendered. - The orientation at which the page is to be rendered. - The flags specifying how the page is to be rendered. - - - - Gets the number of pages in the . - - - - - Gets the at the zero-based in the . - - - - - Imports pages of into the current . - - - - - - Imports pages of into the current . - - - - - - Inserts a new page at . - - - - - Adds a new page to the end of the document. - - - - - Removes the page at . - - - - - Removes the from the document. - - - - - Set if annotations are to be rendered. - - - - - Set if using text rendering optimized for LCD display. - - - - - Don't use the native text output available on some platforms - - - - - Grayscale output. - - - - - Set if you want to get some debug info. - - - - - Set if you don't want to catch exceptions. - - - - - Limit image cache size. - - - - - Always use halftone for image stretching. - - - - - Render for printing. - - - - - Set to disable anti-aliasing on text. - - - - - Set to disable anti-aliasing on images. - - - - - Set to disable anti-aliasing on paths. - - - - - Set whether to render in a reverse Byte order, this flag is only used when rendering to a bitmap. - - - - - If not set, it will not match case by default. - - - - - If not set, it will not match the whole word by default. - - - - - No error. - - - - - Unknown error. - - - - - File not found or could not be opened. - - - - - File not in PDF format or corrupted. - - - - - Password required or incorrect password. - - - - - Unsupported security scheme. - - - - - Page not found or content error. - - - - - Load XFA error. - - - - - Layout XFA error. - - - - Handle to a FPDF_ACTION - - - Gets a value indicating whether the handle is null. - - - Gets a handle representing null. - - - Handle to a FPDF_BITMAP - - - Gets a value indicating whether the handle is null. - - - Gets a handle representing null. - - - Handle to a FPDF_BOOKMARK - - - Gets a value indicating whether the handle is null. - - - Gets a handle representing null. - - - Handle to a FPDF_CLIPPATH - - - Gets a value indicating whether the handle is null. - - - Gets a handle representing null. - - - Handle to a FPDF_DEST - - - Gets a value indicating whether the handle is null. - - - Gets a handle representing null. - - - Handle to a FPDF_DOCUMENT - - - Gets a value indicating whether the handle is null. - - - Gets a handle representing null. - - - Handle to a FPDF_FONT - - - Gets a value indicating whether the handle is null. - - - Gets a handle representing null. - - - Handle to a FPDF_LINK - - - Gets a value indicating whether the handle is null. - - - Gets a handle representing null. - - - Handle to a FPDF_PAGE - - - Gets a value indicating whether the handle is null. - - - Gets a handle representing null. - - - Handle to a FPDF_PAGELINK - - - Gets a value indicating whether the handle is null. - - - Gets a handle representing null. - - - Handle to a FPDF_PAGEOBJECT - - - Gets a value indicating whether the handle is null. - - - Gets a handle representing null. - - - Handle to a FPDF_PAGERANGE - - - Gets a value indicating whether the handle is null. - - - Gets a handle representing null. - - - Handle to a FPDF_RECORDER - - - Gets a value indicating whether the handle is null. - - - Gets a handle representing null. - - - Handle to a FPDF_SCHHANDLE - - - Gets a value indicating whether the handle is null. - - - Gets a handle representing null. - - - Handle to a FPDF_STRUCTELEMENT - - - Gets a value indicating whether the handle is null. - - - Gets a handle representing null. - - - Handle to a FPDF_STRUCTTREE - - - Gets a value indicating whether the handle is null. - - - Gets a handle representing null. - - - Handle to a FPDF_TEXTPAGE - - - Gets a value indicating whether the handle is null. - - - Gets a handle representing null. - - - Handle to a FPDF_STRINGHANDLE - - - Gets a value indicating whether the handle is null. - - - Gets a handle representing null. - - - Handle to a FPDF_WIDGET - - - Gets a value indicating whether the handle is null. - - - Gets a handle representing null. - - - - Handle which can be used with the native functions. - - - - - Gets a value indicating whether was already - called on this instance. - - - - - Implementors should clean up here. This method is guaranteed to only be called once. - - - - diff --git a/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/PDFiumSharp/System.ValueTuple.dll b/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/PDFiumSharp/System.ValueTuple.dll deleted file mode 100644 index b7cb4f7..0000000 Binary files a/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/PDFiumSharp/System.ValueTuple.dll and /dev/null differ diff --git a/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/PdfPageExtension.cs b/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/PdfPageExtension.cs index 1f8f50d..e1b1d79 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/PdfPageExtension.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/PdfPageExtension.cs @@ -1,4 +1,4 @@ -// Copyright © 2017 Paddy Xu +// Copyright © 2018 Paddy Xu // // This file is part of QuickLook program. // @@ -16,39 +16,43 @@ // along with this program. If not, see . using System; -using System.Windows.Media; +using System.Drawing; using System.Windows.Media.Imaging; -using PDFiumSharp; +using PdfiumViewer; +using QuickLook.Common.ExtensionMethods; using QuickLook.Common.Helpers; namespace QuickLook.Plugin.PDFViewer { internal static class PdfPageExtension { - public static BitmapSource RenderThumbnail(this PdfPage page) + public static BitmapSource RenderThumbnail(this PdfDocument doc, int page) { - var factorX = 130d / page.Width; - var factorY = 210d / page.Height; + var size = doc.PageSizes[page]; + var factorX = 130d / size.Width; + var factorY = 210d / size.Height; - return page.Render(Math.Min(factorX, factorY), false); + return doc.Render(page, Math.Min(factorX, factorY), false); } - public static BitmapSource Render(this PdfPage page, double factor, bool fixDpi = true) + public static BitmapSource Render(this PdfDocument doc, int page, double factor, bool fixDpi = true) { + var size = doc.PageSizes[page]; var scale = DpiHelper.GetCurrentScaleFactor(); var dpiX = fixDpi ? scale.Horizontal * DpiHelper.DefaultDpi : 96; var dpiY = fixDpi ? scale.Vertical * DpiHelper.DefaultDpi : 96; - var realWidth = (int) Math.Round(page.Width * scale.Horizontal * factor); - var realHeight = (int) Math.Round(page.Height * scale.Vertical * factor); + var realWidth = (int) Math.Round(size.Width * scale.Horizontal * factor); + var realHeight = (int) Math.Round(size.Height * scale.Vertical * factor); - var bitmap = new WriteableBitmap(realWidth, realHeight, dpiX, dpiY, PixelFormats.Bgr24, null); - page.Render(bitmap, - flags: RenderingFlags.LimitImageCache | RenderingFlags.Annotations | RenderingFlags.DontCatch | - RenderingFlags.LcdText); + var bitmap = doc.Render(page, realWidth, realHeight, dpiX, dpiY, + PdfRenderFlags.LimitImageCacheSize | PdfRenderFlags.LcdText | PdfRenderFlags.Annotations|PdfRenderFlags.ForPrinting) as Bitmap; - bitmap.Freeze(); - return bitmap; + var bs = bitmap?.ToBitmapSource(); + bitmap?.Dispose(); + + bs?.Freeze(); + return bs; } } } \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/PdfViewerControl.xaml.cs b/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/PdfViewerControl.xaml.cs index a787690..e73ea16 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/PdfViewerControl.xaml.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/PdfViewerControl.xaml.cs @@ -1,4 +1,4 @@ -// Copyright © 2017 Paddy Xu +// Copyright © 2018 Paddy Xu // // This file is part of QuickLook program. // @@ -19,13 +19,14 @@ using System; using System.Collections.ObjectModel; using System.ComponentModel; using System.Diagnostics; +using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Media.Imaging; -using PDFiumSharp; +using PdfiumViewer; using QuickLook.Common.ExtensionMethods; namespace QuickLook.Plugin.PDFViewer @@ -39,7 +40,10 @@ namespace QuickLook.Plugin.PDFViewer private bool _initPage = true; private double _maxZoomFactor = double.NaN; private double _minZoomFactor = double.NaN; + + private PdfDocument _pdfHandle; private bool _pdfLoaded; + private Stream _pdfStream; private double _viewRenderFactor = double.NaN; public PdfViewerControl() @@ -58,9 +62,7 @@ namespace QuickLook.Plugin.PDFViewer public ObservableCollection PageThumbnails { get; set; } = new ObservableCollection(); - public PdfDocument PdfHandle { get; private set; } - - public int TotalPages => PdfHandle.Pages.Count; + public int TotalPages => _pdfHandle.PageCount; public int CurrentPage { @@ -86,8 +88,9 @@ namespace QuickLook.Plugin.PDFViewer } _pdfLoaded = false; - PdfHandle?.Close(); - PdfHandle = null; + _pdfHandle?.Dispose(); + _pdfHandle = null; + _pdfStream.Close(); } public event PropertyChangedEventHandler PropertyChanged; @@ -160,16 +163,16 @@ namespace QuickLook.Plugin.PDFViewer // First time showing. Set thresholds here. if (double.IsNaN(_minZoomFactor) || double.IsNaN(_maxZoomFactor)) { - factor = Math.Min(pagePanel.ActualHeight / PdfHandle.Pages[CurrentPage].Height, - pagePanel.ActualWidth / PdfHandle.Pages[CurrentPage].Width); + factor = Math.Min(pagePanel.ActualHeight / _pdfHandle.PageSizes[CurrentPage].Height, + pagePanel.ActualWidth / _pdfHandle.PageSizes[CurrentPage].Width); _viewRenderFactor = factor; _minZoomFactor = 0.1 * factor; _maxZoomFactor = 5 * factor; } else if (pagePanel.ZoomToFit) { - factor = Math.Min(pagePanel.ActualHeight / PdfHandle.Pages[CurrentPage].Height, - pagePanel.ActualWidth / PdfHandle.Pages[CurrentPage].Width); + factor = Math.Min(pagePanel.ActualHeight / _pdfHandle.PageSizes[CurrentPage].Height, + pagePanel.ActualWidth / _pdfHandle.PageSizes[CurrentPage].Width); } else { @@ -180,7 +183,7 @@ namespace QuickLook.Plugin.PDFViewer pagePanel.MaxZoomFactor = _maxZoomFactor / factor; } - var image = PdfHandle.Pages[CurrentPage].Render(factor); + var image = _pdfHandle.Render(CurrentPage, factor); pagePanel.Source = image; pagePanel.ResetZoom(); @@ -214,19 +217,21 @@ namespace QuickLook.Plugin.PDFViewer public static Size GetDesiredControlSizeByFirstPage(string path) { Size size; - using (var tempHandle = new PdfDocument(path)) + + using (var s = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { - size = new Size(0, 0); - tempHandle.Pages.Take(5).ForEach(p => + using (var tempHandle = PdfDocument.Load(s)) { - size.Width = Math.Max(size.Width, p.Width); - size.Height = Math.Max(size.Height, p.Height); - }); + size = new Size(0, 0); + tempHandle.PageSizes.Take(5).ForEach(p => + { + size.Width = Math.Max(size.Width, p.Width); + size.Height = Math.Max(size.Height, p.Height); + }); - if (tempHandle.Pages.Count > 1) - size.Width += /*listThumbnails.ActualWidth*/ 150; - - tempHandle.Close(); + if (tempHandle.PageCount > 1) + size.Width += /*listThumbnails.ActualWidth*/ 150; + } } return new Size(size.Width * 3, size.Height * 3); @@ -234,12 +239,13 @@ namespace QuickLook.Plugin.PDFViewer public void LoadPdf(string path) { - PdfHandle = new PdfDocument(path); + _pdfStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); + _pdfHandle = PdfDocument.Load(_pdfStream); _pdfLoaded = true; BeginLoadThumbnails(path); - if (PdfHandle.Pages.Count < 2) + if (_pdfHandle.PageCount < 2) listThumbnails.Visibility = Visibility.Collapsed; } @@ -247,16 +253,19 @@ namespace QuickLook.Plugin.PDFViewer { new Task(() => { - using (var handle = new PdfDocument(path, password)) + using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { - handle.Pages.ForEach(p => + using (var handle = PdfDocument.Load(stream, password)) { - var bs = p.RenderThumbnail(); + for (var p = 0; p < handle.PageCount; p++) + { + var bs = handle.RenderThumbnail(p); - Dispatcher.BeginInvoke(new Action(() => PageThumbnails.Add(bs))); - }); + Dispatcher.BeginInvoke(new Action(() => PageThumbnails.Add(bs))); + } - handle.Close(); + handle.Dispose(); + } } }).Start(); } diff --git a/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/QuickLook.Plugin.PdfViewer.csproj b/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/QuickLook.Plugin.PdfViewer.csproj index 0960cd2..1ed1905 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/QuickLook.Plugin.PdfViewer.csproj +++ b/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/QuickLook.Plugin.PdfViewer.csproj @@ -1,5 +1,7 @@  + + Debug @@ -12,6 +14,8 @@ v4.6.2 512 + + true @@ -61,18 +65,15 @@ - - False - PDFiumSharp\PDFiumSharp.dll - - - False - PDFiumSharp\PDFiumSharp.Wpf.dll + + ..\..\packages\PdfiumViewer.2.13.0.0\lib\net20\PdfiumViewer.dll + + @@ -110,12 +111,14 @@ - - PreserveNewest - - - PreserveNewest - + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/packages.config b/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/packages.config new file mode 100644 index 0000000..71bd5ce --- /dev/null +++ b/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/packages.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/pdfium_x64.dll b/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/pdfium_x64.dll deleted file mode 100644 index 17008df..0000000 Binary files a/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/pdfium_x64.dll and /dev/null differ diff --git a/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/pdfium_x86.dll b/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/pdfium_x86.dll deleted file mode 100644 index 5251186..0000000 Binary files a/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/pdfium_x86.dll and /dev/null differ