├── .gitignore ├── .gitmodules ├── CodeMaid.config ├── LICENSE-GPL.txt ├── QuickLook.Plugin.Metadata.Base.config ├── QuickLook.Plugin.SumatraPDFReader.sln ├── QuickLook.Plugin.SumatraPDFReader ├── ChildProcessTracer.cs ├── FodyWeavers.xml ├── FodyWeavers.xsd ├── Plugin.cs ├── Properties │ └── AssemblyInfo.cs ├── QuickLook.Plugin.SumatraPDFReader.csproj ├── Resources │ ├── SumatraPDF-settings-Darker.txt │ └── SumatraPDF-settings-Light.txt ├── SumatraPDFControl.Designer.cs ├── SumatraPDFControl.cs ├── SumatraPanel.cs └── SumatraPanel.xaml ├── README.md ├── Scripts ├── pack-zip.cmd ├── pack-zip.ps1 └── update-version.ps1 ├── Settings.XamlStyler └── SumatraPDF-settings.txt /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015/2017 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # Visual Studio 2017 auto generated files 31 | Generated\ Files/ 32 | 33 | # MSTest test Results 34 | [Tt]est[Rr]esult*/ 35 | [Bb]uild[Ll]og.* 36 | 37 | # NUNIT 38 | *.VisualState.xml 39 | TestResult.xml 40 | 41 | # Build Results of an ATL Project 42 | [Dd]ebugPS/ 43 | [Rr]eleasePS/ 44 | dlldata.c 45 | 46 | # Benchmark Results 47 | BenchmarkDotNet.Artifacts/ 48 | 49 | # .NET Core 50 | project.lock.json 51 | project.fragment.lock.json 52 | artifacts/ 53 | **/Properties/launchSettings.json 54 | 55 | # StyleCop 56 | StyleCopReport.xml 57 | 58 | # Files built by Visual Studio 59 | *_i.c 60 | *_p.c 61 | *_i.h 62 | *.ilk 63 | *.meta 64 | *.obj 65 | *.iobj 66 | *.pch 67 | *.pdb 68 | *.ipdb 69 | *.pgc 70 | *.pgd 71 | *.rsp 72 | *.sbr 73 | *.tlb 74 | *.tli 75 | *.tlh 76 | *.tmp 77 | *.tmp_proj 78 | *.log 79 | *.vspscc 80 | *.vssscc 81 | .builds 82 | *.pidb 83 | *.svclog 84 | *.scc 85 | 86 | # Chutzpah Test files 87 | _Chutzpah* 88 | 89 | # Visual C++ cache files 90 | ipch/ 91 | *.aps 92 | *.ncb 93 | *.opendb 94 | *.opensdf 95 | *.sdf 96 | *.cachefile 97 | *.VC.db 98 | *.VC.VC.opendb 99 | 100 | # Visual Studio profiler 101 | *.psess 102 | *.vsp 103 | *.vspx 104 | *.sap 105 | 106 | # Visual Studio Trace Files 107 | *.e2e 108 | 109 | # TFS 2012 Local Workspace 110 | $tf/ 111 | 112 | # Guidance Automation Toolkit 113 | *.gpState 114 | 115 | # ReSharper is a .NET coding add-in 116 | _ReSharper*/ 117 | *.[Rr]e[Ss]harper 118 | *.DotSettings.user 119 | 120 | # JustCode is a .NET coding add-in 121 | .JustCode 122 | 123 | # TeamCity is a build add-in 124 | _TeamCity* 125 | 126 | # DotCover is a Code Coverage Tool 127 | *.dotCover 128 | 129 | # AxoCover is a Code Coverage Tool 130 | .axoCover/* 131 | !.axoCover/settings.json 132 | 133 | # Visual Studio code coverage results 134 | *.coverage 135 | *.coveragexml 136 | 137 | # NCrunch 138 | _NCrunch_* 139 | .*crunch*.local.xml 140 | nCrunchTemp_* 141 | 142 | # MightyMoose 143 | *.mm.* 144 | AutoTest.Net/ 145 | 146 | # Web workbench (sass) 147 | .sass-cache/ 148 | 149 | # Installshield output folder 150 | [Ee]xpress/ 151 | 152 | # DocProject is a documentation generator add-in 153 | DocProject/buildhelp/ 154 | DocProject/Help/*.HxT 155 | DocProject/Help/*.HxC 156 | DocProject/Help/*.hhc 157 | DocProject/Help/*.hhk 158 | DocProject/Help/*.hhp 159 | DocProject/Help/Html2 160 | DocProject/Help/html 161 | 162 | # Click-Once directory 163 | publish/ 164 | 165 | # Publish Web Output 166 | *.[Pp]ublish.xml 167 | *.azurePubxml 168 | # Note: Comment the next line if you want to checkin your web deploy settings, 169 | # but database connection strings (with potential passwords) will be unencrypted 170 | *.pubxml 171 | *.publishproj 172 | 173 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 174 | # checkin your Azure Web App publish settings, but sensitive information contained 175 | # in these scripts will be unencrypted 176 | PublishScripts/ 177 | 178 | # NuGet Packages 179 | *.nupkg 180 | # The packages folder can be ignored because of Package Restore 181 | **/[Pp]ackages/* 182 | # except build/, which is used as an MSBuild target. 183 | !**/[Pp]ackages/build/ 184 | # Uncomment if necessary however generally it will be regenerated when needed 185 | #!**/[Pp]ackages/repositories.config 186 | # NuGet v3's project.json files produces more ignorable files 187 | *.nuget.props 188 | *.nuget.targets 189 | 190 | # Microsoft Azure Build Output 191 | csx/ 192 | *.build.csdef 193 | 194 | # Microsoft Azure Emulator 195 | ecf/ 196 | rcf/ 197 | 198 | # Windows Store app package directories and files 199 | AppPackages/ 200 | BundleArtifacts/ 201 | Package.StoreAssociation.xml 202 | _pkginfo.txt 203 | *.appx 204 | 205 | # Visual Studio cache files 206 | # files ending in .cache can be ignored 207 | *.[Cc]ache 208 | # but keep track of directories ending in .cache 209 | !*.[Cc]ache/ 210 | 211 | # Others 212 | ClientBin/ 213 | ~$* 214 | *~ 215 | *.dbmdl 216 | *.dbproj.schemaview 217 | *.jfm 218 | *.pfx 219 | *.publishsettings 220 | orleans.codegen.cs 221 | 222 | # Including strong name files can present a security risk 223 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 224 | #*.snk 225 | 226 | # Since there are multiple workflows, uncomment next line to ignore bower_components 227 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 228 | #bower_components/ 229 | 230 | # RIA/Silverlight projects 231 | Generated_Code/ 232 | 233 | # Backup & report files from converting an old project file 234 | # to a newer Visual Studio version. Backup files are not needed, 235 | # because we have git ;-) 236 | _UpgradeReport_Files/ 237 | Backup*/ 238 | UpgradeLog*.XML 239 | UpgradeLog*.htm 240 | ServiceFabricBackup/ 241 | *.rptproj.bak 242 | 243 | # SQL Server files 244 | *.mdf 245 | *.ldf 246 | *.ndf 247 | 248 | # Business Intelligence projects 249 | *.rdl.data 250 | *.bim.layout 251 | *.bim_*.settings 252 | *.rptproj.rsuser 253 | 254 | # Microsoft Fakes 255 | FakesAssemblies/ 256 | 257 | # GhostDoc plugin setting file 258 | *.GhostDoc.xml 259 | 260 | # Node.js Tools for Visual Studio 261 | .ntvs_analysis.dat 262 | node_modules/ 263 | 264 | # Visual Studio 6 build log 265 | *.plg 266 | 267 | # Visual Studio 6 workspace options file 268 | *.opt 269 | 270 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 271 | *.vbw 272 | 273 | # Visual Studio LightSwitch build output 274 | **/*.HTMLClient/GeneratedArtifacts 275 | **/*.DesktopClient/GeneratedArtifacts 276 | **/*.DesktopClient/ModelManifest.xml 277 | **/*.Server/GeneratedArtifacts 278 | **/*.Server/ModelManifest.xml 279 | _Pvt_Extensions 280 | 281 | # Paket dependency manager 282 | .paket/paket.exe 283 | paket-files/ 284 | 285 | # FAKE - F# Make 286 | .fake/ 287 | 288 | # JetBrains Rider 289 | .idea/ 290 | *.sln.iml 291 | 292 | # CodeRush 293 | .cr/ 294 | 295 | # Python Tools for Visual Studio (PTVS) 296 | __pycache__/ 297 | *.pyc 298 | 299 | # Cake - Uncomment if you are using it 300 | # tools/** 301 | # !tools/packages.config 302 | 303 | # Tabs Studio 304 | *.tss 305 | 306 | # Telerik's JustMock configuration file 307 | *.jmconfig 308 | 309 | # BizTalk build output 310 | *.btp.cs 311 | *.btm.cs 312 | *.odx.cs 313 | *.xsd.cs 314 | 315 | # OpenCover UI analysis results 316 | OpenCover/ 317 | 318 | # Azure Stream Analytics local run output 319 | ASALocalRun/ 320 | 321 | # MSBuild Binary and Structured Log 322 | *.binlog 323 | 324 | # NVidia Nsight GPU debugger configuration file 325 | *.nvuser 326 | 327 | # MFractors (Xamarin productivity tool) working folder 328 | .mfractor/ 329 | /*.qlplugin 330 | /GitVersion.cs 331 | /QuickLook.Plugin.Metadata.config 332 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "QuickLook.Common"] 2 | path = QuickLook.Common 3 | url = https://github.com/QL-Win/QuickLook.Common 4 | [submodule "SumatraPDF"] 5 | path = SumatraPDF 6 | url = https://github.com/sumatrapdfreader/sumatrapdf 7 | 8 | -------------------------------------------------------------------------------- /CodeMaid.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |
6 | 7 | 8 | 9 | 10 | 11 | 1 12 | 13 | 14 | True 15 | 16 | 17 | False 18 | 19 | 20 | True 21 | 22 | 23 | False 24 | 25 | 26 | False 27 | 28 | 29 | False 30 | 31 | 32 | False 33 | 34 | 35 | False 36 | 37 | 38 | False 39 | 40 | 41 | False 42 | 43 | 44 | False 45 | 46 | 47 | False 48 | 49 | 50 | False 51 | 52 | 53 | False 54 | 55 | 56 | False 57 | 58 | 59 | False 60 | 61 | 62 | True 63 | 64 | 66 | False 67 | 68 | 70 | False 71 | 72 | 74 | False 75 | 76 | 78 | False 79 | 80 | 82 | False 83 | 84 | 86 | False 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /LICENSE-GPL.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . -------------------------------------------------------------------------------- /QuickLook.Plugin.Metadata.Base.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | QuickLook.Plugin.SumatraPDFReader 4 | 0 5 | This plugin allows QuickLook to preview multi-format (EPUB, MOBI, CBZ, CBR, FB2, CHM, XPS, DjVu). 6 | -------------------------------------------------------------------------------- /QuickLook.Plugin.SumatraPDFReader.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.9.34728.123 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuickLook.Plugin.SumatraPDFReader", "QuickLook.Plugin.SumatraPDFReader\QuickLook.Plugin.SumatraPDFReader.csproj", "{863ECAAC-18D9-4256-A27D-0F308089FB47}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuickLook.Common", "QuickLook.Common\QuickLook.Common.csproj", "{85FDD6BA-871D-46C8-BD64-F6BB0CB5EA95}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Debug|x86 = Debug|x86 14 | Release|Any CPU = Release|Any CPU 15 | Release|x86 = Release|x86 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {863ECAAC-18D9-4256-A27D-0F308089FB47}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {863ECAAC-18D9-4256-A27D-0F308089FB47}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {863ECAAC-18D9-4256-A27D-0F308089FB47}.Debug|x86.ActiveCfg = Debug|x86 21 | {863ECAAC-18D9-4256-A27D-0F308089FB47}.Debug|x86.Build.0 = Debug|x86 22 | {863ECAAC-18D9-4256-A27D-0F308089FB47}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {863ECAAC-18D9-4256-A27D-0F308089FB47}.Release|Any CPU.Build.0 = Release|Any CPU 24 | {863ECAAC-18D9-4256-A27D-0F308089FB47}.Release|x86.ActiveCfg = Release|x86 25 | {863ECAAC-18D9-4256-A27D-0F308089FB47}.Release|x86.Build.0 = Release|x86 26 | {85FDD6BA-871D-46C8-BD64-F6BB0CB5EA95}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {85FDD6BA-871D-46C8-BD64-F6BB0CB5EA95}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {85FDD6BA-871D-46C8-BD64-F6BB0CB5EA95}.Debug|x86.ActiveCfg = Debug|Any CPU 29 | {85FDD6BA-871D-46C8-BD64-F6BB0CB5EA95}.Debug|x86.Build.0 = Debug|Any CPU 30 | {85FDD6BA-871D-46C8-BD64-F6BB0CB5EA95}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {85FDD6BA-871D-46C8-BD64-F6BB0CB5EA95}.Release|Any CPU.Build.0 = Release|Any CPU 32 | {85FDD6BA-871D-46C8-BD64-F6BB0CB5EA95}.Release|x86.ActiveCfg = Release|Any CPU 33 | {85FDD6BA-871D-46C8-BD64-F6BB0CB5EA95}.Release|x86.Build.0 = Release|Any CPU 34 | EndGlobalSection 35 | GlobalSection(SolutionProperties) = preSolution 36 | HideSolutionNode = FALSE 37 | EndGlobalSection 38 | GlobalSection(ExtensibilityGlobals) = postSolution 39 | SolutionGuid = {D545EDE6-0533-4E3F-BB67-308B17E4EDAC} 40 | EndGlobalSection 41 | EndGlobal 42 | -------------------------------------------------------------------------------- /QuickLook.Plugin.SumatraPDFReader/ChildProcessTracer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace QuickLook.Plugin.SumatraPDFReader; 6 | 7 | /// 8 | /// Make sures that child processes are automatically terminated 9 | /// if the parent process exits unexpectedly. 10 | /// 11 | internal sealed class ChildProcessTracer 12 | { 13 | public static ChildProcessTracer Default { get; } = new(); 14 | 15 | private static class Kernel32 16 | { 17 | [DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)] 18 | [return: MarshalAs(UnmanagedType.Bool)] 19 | public static extern bool AssignProcessToJobObject([In] nint hJob, [In] nint hProcess); 20 | 21 | [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)] 22 | public static extern nint CreateJobObject([In, Optional] SECURITY_ATTRIBUTES? lpJobAttributes, [In, Optional] string? lpName); 23 | 24 | [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)] 25 | public static extern bool SetInformationJobObject(nint hJob, JOBOBJECTINFOCLASS JobObjectInfoClass, nint lpJobObjectInfo, uint cbJobObjectInfoLength); 26 | 27 | [StructLayout(LayoutKind.Sequential)] 28 | public class SECURITY_ATTRIBUTES 29 | { 30 | public int nLength = Marshal.SizeOf(typeof(SECURITY_ATTRIBUTES)); 31 | 32 | public nint lpSecurityDescriptor; 33 | 34 | [MarshalAs(UnmanagedType.Bool)] 35 | public bool bInheritHandle; 36 | } 37 | 38 | public enum JOBOBJECTINFOCLASS 39 | { 40 | JobObjectBasicAccountingInformation = 1, 41 | JobObjectBasicLimitInformation, 42 | JobObjectBasicProcessIdList, 43 | JobObjectBasicUIRestrictions, 44 | JobObjectSecurityLimitInformation, 45 | JobObjectEndOfJobTimeInformation, 46 | JobObjectAssociateCompletionPortInformation, 47 | JobObjectBasicAndIoAccountingInformation, 48 | JobObjectExtendedLimitInformation, 49 | JobObjectJobSetInformation, 50 | JobObjectGroupInformation, 51 | JobObjectNotificationLimitInformation, 52 | JobObjectLimitViolationInformation, 53 | JobObjectGroupInformationEx, 54 | JobObjectCpuRateControlInformation, 55 | JobObjectCompletionFilter, 56 | JobObjectCompletionCounter, 57 | JobObjectReserved1Information = 18, 58 | JobObjectReserved2Information, 59 | JobObjectReserved3Information, 60 | JobObjectReserved4Information, 61 | JobObjectReserved5Information, 62 | JobObjectReserved6Information, 63 | JobObjectReserved7Information, 64 | JobObjectReserved8Information, 65 | JobObjectReserved9Information, 66 | JobObjectReserved10Information, 67 | JobObjectReserved11Information, 68 | JobObjectReserved12Information, 69 | JobObjectReserved13Information, 70 | JobObjectReserved14Information = 31, 71 | JobObjectNetRateControlInformation, 72 | JobObjectNotificationLimitInformation2, 73 | JobObjectLimitViolationInformation2, 74 | JobObjectCreateSilo, 75 | JobObjectSiloBasicInformation, 76 | JobObjectReserved15Information = 37, 77 | JobObjectReserved16Information = 38, 78 | JobObjectReserved17Information = 39, 79 | JobObjectReserved18Information = 40, 80 | JobObjectReserved19Information = 41, 81 | JobObjectReserved20Information = 42, 82 | JobObjectReserved21Information = 43, 83 | JobObjectReserved22Information = 44, 84 | JobObjectReserved23Information = 45, 85 | JobObjectReserved24Information = 46, 86 | JobObjectReserved25Information = 47, 87 | } 88 | 89 | [StructLayout(LayoutKind.Sequential)] 90 | public struct JOBOBJECT_EXTENDED_LIMIT_INFORMATION 91 | { 92 | public JOBOBJECT_BASIC_LIMIT_INFORMATION BasicLimitInformation; 93 | public IO_COUNTERS IoInfo; 94 | public SizeT ProcessMemoryLimit; 95 | public SizeT JobMemoryLimit; 96 | public SizeT PeakProcessMemoryUsed; 97 | public SizeT PeakJobMemoryUsed; 98 | } 99 | 100 | [StructLayout(LayoutKind.Sequential)] 101 | public struct JOBOBJECT_BASIC_LIMIT_INFORMATION 102 | { 103 | public TimeSpan PerProcessUserTimeLimit; 104 | public TimeSpan PerJobUserTimeLimit; 105 | public JOBOBJECT_LIMIT_FLAGS LimitFlags; 106 | public SizeT MinimumWorkingSetSize; 107 | public SizeT MaximumWorkingSetSize; 108 | public uint ActiveProcessLimit; 109 | public nuint Affinity; 110 | public uint PriorityClass; 111 | public uint SchedulingClass; 112 | } 113 | 114 | [Flags] 115 | public enum JOBOBJECT_LIMIT_FLAGS 116 | { 117 | JOB_OBJECT_LIMIT_WORKINGSET = 0x00000001, 118 | JOB_OBJECT_LIMIT_PROCESS_TIME = 0x00000002, 119 | JOB_OBJECT_LIMIT_JOB_TIME = 0x00000004, 120 | JOB_OBJECT_LIMIT_ACTIVE_PROCESS = 0x00000008, 121 | JOB_OBJECT_LIMIT_AFFINITY = 0x00000010, 122 | JOB_OBJECT_LIMIT_PRIORITY_CLASS = 0x00000020, 123 | JOB_OBJECT_LIMIT_PRESERVE_JOB_TIME = 0x00000040, 124 | JOB_OBJECT_LIMIT_SCHEDULING_CLASS = 0x00000080, 125 | JOB_OBJECT_LIMIT_PROCESS_MEMORY = 0x00000100, 126 | JOB_OBJECT_LIMIT_JOB_MEMORY = 0x00000200, 127 | JOB_OBJECT_LIMIT_DIE_ON_UNHANDLED_EXCEPTION = 0x00000400, 128 | JOB_OBJECT_LIMIT_BREAKAWAY_OK = 0x00000800, 129 | JOB_OBJECT_LIMIT_SILENT_BREAKAWAY_OK = 0x00001000, 130 | JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE = 0x00002000, 131 | JOB_OBJECT_LIMIT_SUBSET_AFFINITY = 0x00004000, 132 | JOB_OBJECT_LIMIT_JOB_MEMORY_LOW = 0x00008000, 133 | JOB_OBJECT_LIMIT_JOB_READ_BYTES = 0x00010000, 134 | JOB_OBJECT_LIMIT_JOB_WRITE_BYTES = 0x00020000, 135 | JOB_OBJECT_LIMIT_RATE_CONTROL = 0x00040000, 136 | JOB_OBJECT_LIMIT_CPU_RATE_CONTROL = JOB_OBJECT_LIMIT_RATE_CONTROL, 137 | JOB_OBJECT_LIMIT_IO_RATE_CONTROL = 0x00080000, 138 | JOB_OBJECT_LIMIT_NET_RATE_CONTROL = 0x00100000, 139 | } 140 | 141 | [StructLayout(LayoutKind.Sequential)] 142 | public struct IO_COUNTERS 143 | { 144 | public ulong ReadOperationCount; 145 | public ulong WriteOperationCount; 146 | public ulong OtherOperationCount; 147 | public ulong ReadTransferCount; 148 | public ulong WriteTransferCount; 149 | public ulong OtherTransferCount; 150 | } 151 | 152 | public struct SizeT 153 | { 154 | private nuint val; 155 | 156 | public ulong Value 157 | { 158 | readonly get => val; 159 | private set => val = new UIntPtr(value); 160 | } 161 | } 162 | } 163 | 164 | private readonly nint hJob; 165 | 166 | public ChildProcessTracer() 167 | { 168 | if (Environment.OSVersion.Version < new Version(6, 2)) 169 | { 170 | return; 171 | } 172 | 173 | hJob = Kernel32.CreateJobObject(null, $"{nameof(ChildProcessTracer)}-{Process.GetCurrentProcess().Id}"); 174 | 175 | Kernel32.JOBOBJECT_EXTENDED_LIMIT_INFORMATION extendedInfo = new() 176 | { 177 | BasicLimitInformation = new Kernel32.JOBOBJECT_BASIC_LIMIT_INFORMATION 178 | { 179 | LimitFlags = Kernel32.JOBOBJECT_LIMIT_FLAGS.JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE 180 | } 181 | }; 182 | 183 | int length = Marshal.SizeOf(extendedInfo); 184 | nint extendedInfoPtr = Marshal.AllocHGlobal(length); 185 | 186 | try 187 | { 188 | Marshal.StructureToPtr(extendedInfo, extendedInfoPtr, false); 189 | 190 | if (!Kernel32.SetInformationJobObject(hJob, Kernel32.JOBOBJECTINFOCLASS.JobObjectExtendedLimitInformation, extendedInfoPtr, (uint)length)) 191 | { 192 | Debug.WriteLine($"Failed to set information for job object. Error: {Marshal.GetLastWin32Error()}"); 193 | } 194 | } 195 | finally 196 | { 197 | // Free allocated memory after job object is set. 198 | Marshal.FreeHGlobal(extendedInfoPtr); 199 | } 200 | } 201 | 202 | /// 203 | /// Adds a process to the tracking job. If the parent process is terminated, this process will also be automatically terminated. 204 | /// 205 | /// The child process to be tracked. 206 | /// Thrown when the process argument is null. 207 | public void AddChildProcess(nint hProcess) 208 | { 209 | if (!Kernel32.AssignProcessToJobObject(hJob, hProcess)) 210 | { 211 | Debug.WriteLine($"Failed to assign process to job object. Error: {Marshal.GetLastWin32Error()}"); 212 | } 213 | } 214 | } 215 | -------------------------------------------------------------------------------- /QuickLook.Plugin.SumatraPDFReader/FodyWeavers.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | -------------------------------------------------------------------------------- /QuickLook.Plugin.SumatraPDFReader/FodyWeavers.xsd: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with line breaks 13 | 14 | 15 | 16 | 17 | A list of assembly names to include from the default action of "embed all Copy Local references", delimited with line breaks. 18 | 19 | 20 | 21 | 22 | A list of runtime assembly names to exclude from the default action of "embed all Copy Local references", delimited with line breaks 23 | 24 | 25 | 26 | 27 | A list of runtime assembly names to include from the default action of "embed all Copy Local references", delimited with line breaks. 28 | 29 | 30 | 31 | 32 | Obsolete, use UnmanagedWinX86Assemblies instead 33 | 34 | 35 | 36 | 37 | A list of unmanaged X86 (32 bit) assembly names to include, delimited with line breaks. 38 | 39 | 40 | 41 | 42 | Obsolete, use UnmanagedWinX64Assemblies instead. 43 | 44 | 45 | 46 | 47 | A list of unmanaged X64 (64 bit) assembly names to include, delimited with line breaks. 48 | 49 | 50 | 51 | 52 | A list of unmanaged Arm64 (64 bit) assembly names to include, delimited with line breaks. 53 | 54 | 55 | 56 | 57 | The order of preloaded assemblies, delimited with line breaks. 58 | 59 | 60 | 61 | 62 | 63 | This will copy embedded files to disk before loading them into memory. This is helpful for some scenarios that expected an assembly to be loaded from a physical file. 64 | 65 | 66 | 67 | 68 | Controls if .pdbs for reference assemblies are also embedded. 69 | 70 | 71 | 72 | 73 | Controls if runtime assemblies are also embedded. 74 | 75 | 76 | 77 | 78 | Controls whether the runtime assemblies are embedded with their full path or only with their assembly name. 79 | 80 | 81 | 82 | 83 | Embedded assemblies are compressed by default, and uncompressed when they are loaded. You can turn compression off with this option. 84 | 85 | 86 | 87 | 88 | As part of Costura, embedded assemblies are no longer included as part of the build. This cleanup can be turned off. 89 | 90 | 91 | 92 | 93 | The attach method no longer subscribes to the `AppDomain.AssemblyResolve` (.NET 4.x) and `AssemblyLoadContext.Resolving` (.NET 6.0+) events. 94 | 95 | 96 | 97 | 98 | Costura by default will load as part of the module initialization. This flag disables that behavior. Make sure you call CosturaUtility.Initialize() somewhere in your code. 99 | 100 | 101 | 102 | 103 | Costura will by default use assemblies with a name like 'resources.dll' as a satellite resource and prepend the output path. This flag disables that behavior. 104 | 105 | 106 | 107 | 108 | A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with | 109 | 110 | 111 | 112 | 113 | A list of assembly names to include from the default action of "embed all Copy Local references", delimited with |. 114 | 115 | 116 | 117 | 118 | A list of runtime assembly names to exclude from the default action of "embed all Copy Local references", delimited with | 119 | 120 | 121 | 122 | 123 | A list of runtime assembly names to include from the default action of "embed all Copy Local references", delimited with |. 124 | 125 | 126 | 127 | 128 | Obsolete, use UnmanagedWinX86Assemblies instead 129 | 130 | 131 | 132 | 133 | A list of unmanaged X86 (32 bit) assembly names to include, delimited with |. 134 | 135 | 136 | 137 | 138 | Obsolete, use UnmanagedWinX64Assemblies instead 139 | 140 | 141 | 142 | 143 | A list of unmanaged X64 (64 bit) assembly names to include, delimited with |. 144 | 145 | 146 | 147 | 148 | A list of unmanaged Arm64 (64 bit) assembly names to include, delimited with |. 149 | 150 | 151 | 152 | 153 | The order of preloaded assemblies, delimited with |. 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed. 162 | 163 | 164 | 165 | 166 | A comma-separated list of error codes that can be safely ignored in assembly verification. 167 | 168 | 169 | 170 | 171 | 'false' to turn off automatic generation of the XML Schema file. 172 | 173 | 174 | 175 | 176 | -------------------------------------------------------------------------------- /QuickLook.Plugin.SumatraPDFReader/Plugin.cs: -------------------------------------------------------------------------------- 1 | // Copyright © 2025 QL-Win Contributors 2 | // 3 | // This file is part of QuickLook program. 4 | // 5 | // This program is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | using QuickLook.Common.Helpers; 19 | using QuickLook.Common.NativeMethods; 20 | using QuickLook.Common.Plugin; 21 | using System; 22 | using System.IO; 23 | using System.Runtime.InteropServices; 24 | using System.Threading.Tasks; 25 | using System.Windows; 26 | using System.Windows.Controls; 27 | using System.Windows.Interop; 28 | using System.Windows.Media; 29 | 30 | namespace QuickLook.Plugin.SumatraPDFReader; 31 | 32 | public class Plugin : IViewer 33 | { 34 | public int Priority => 0; 35 | 36 | public void Init() 37 | { 38 | } 39 | 40 | public bool CanHandle(string path) 41 | { 42 | if (Directory.Exists(path)) 43 | return false; 44 | 45 | return path.EndsWith(".epub", StringComparison.OrdinalIgnoreCase) || 46 | path.EndsWith(".mobi", StringComparison.OrdinalIgnoreCase) || 47 | path.EndsWith(".cbz", StringComparison.OrdinalIgnoreCase) || 48 | path.EndsWith(".cbr", StringComparison.OrdinalIgnoreCase) || 49 | path.EndsWith(".fb2", StringComparison.OrdinalIgnoreCase) || 50 | path.EndsWith(".chm", StringComparison.OrdinalIgnoreCase) || 51 | path.EndsWith(".xps", StringComparison.OrdinalIgnoreCase) || 52 | path.EndsWith(".djvu", StringComparison.OrdinalIgnoreCase); 53 | } 54 | 55 | public void Prepare(string path, ContextObject context) 56 | { 57 | context.SetPreferredSizeFit(new Size(1200, 900), 0.9d); 58 | } 59 | 60 | public void View(string path, ContextObject context) 61 | { 62 | try 63 | { 64 | var viewer = new SumatraPanel(); 65 | viewer.PreviewFile(path, context); 66 | context.ViewerContent = viewer; 67 | viewer.Loaded += (_, _) => 68 | { 69 | // Fix for TextColor issue #2 #3 70 | // However, it's uncertain whether this fully resolves all related problems 71 | if (Window.GetWindow(viewer) is Window win) 72 | { 73 | win.DisableDwmBlur(); 74 | } 75 | }; 76 | } 77 | catch (Exception e) 78 | { 79 | context.ViewerContent = new Label() 80 | { 81 | HorizontalAlignment = HorizontalAlignment.Center, 82 | VerticalAlignment = VerticalAlignment.Center, 83 | Content = e.Message, 84 | }; 85 | } 86 | 87 | context.IsBusy = true; 88 | context.Title = Path.GetFileName(path); 89 | 90 | // Hide the resize effect of external process windows 91 | _ = Task.Run(async () => 92 | { 93 | await Task.Delay(800); 94 | context.IsBusy = false; 95 | }); 96 | } 97 | 98 | public void Cleanup() 99 | { 100 | } 101 | } 102 | 103 | file static class WindowExtension 104 | { 105 | public static void DisableDwmBlur(this Window window) 106 | { 107 | window.Background = (Brush)window.FindResource("MainWindowBackgroundNoTransparent"); 108 | 109 | if (Environment.OSVersion.Version >= new Version(10, 0, 21996)) 110 | { 111 | if (Environment.OSVersion.Version >= new Version(10, 0, 22523)) 112 | { 113 | var hwnd = new WindowInteropHelper(window).Handle; 114 | 115 | if (!OSThemeHelper.AppsUseDarkTheme()) 116 | { 117 | int isDarkThemeInt = 1; 118 | Dwmapi.DwmSetWindowAttribute(hwnd, (uint)Dwmapi.WindowAttribute.UseImmersiveDarkMode, ref isDarkThemeInt, Marshal.SizeOf(typeof(bool))); 119 | } 120 | 121 | int backdropType = (int)Dwmapi.SystembackdropType.Auto; 122 | Dwmapi.DwmSetWindowAttribute(hwnd, (uint)Dwmapi.WindowAttribute.SystembackdropType, ref backdropType, Marshal.SizeOf()); 123 | } 124 | else 125 | { 126 | var hwnd = new WindowInteropHelper(window).Handle; 127 | 128 | if (!OSThemeHelper.AppsUseDarkTheme()) 129 | { 130 | int isDarkThemeInt = 1; 131 | Dwmapi.DwmSetWindowAttribute(hwnd, (uint)Dwmapi.WindowAttribute.UseImmersiveDarkMode, ref isDarkThemeInt, Marshal.SizeOf(typeof(bool))); 132 | } 133 | 134 | int backdropType = 0; 135 | Dwmapi.DwmSetWindowAttribute(hwnd, (uint)Dwmapi.WindowAttribute.MicaEffect, ref backdropType, Marshal.SizeOf()); 136 | } 137 | } 138 | else if (Environment.OSVersion.Version >= new Version(10, 0)) 139 | { 140 | // Potential issues on Windows 10 are not maintained 141 | } 142 | else 143 | { 144 | // Other Windows Version 145 | } 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /QuickLook.Plugin.SumatraPDFReader/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | using System.Windows; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("QuickLook.Plugin.SumatraPDFReader")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("QuickLook.Plugin.SumatraPDFReader")] 13 | [assembly: AssemblyCopyright("Copyright © ema 2025")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | //In order to begin building localizable applications, set 23 | //CultureYouAreCodingWith in your .csproj file 24 | //inside a . For example, if you are using US english 25 | //in your source files, set the to en-US. Then uncomment 26 | //the NeutralResourceLanguage attribute below. Update the "en-US" in 27 | //the line below to match the UICulture setting in the project file. 28 | 29 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] 30 | 31 | [assembly: ThemeInfo( 32 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located 33 | //(used if a resource is not found in the page, 34 | // or application resource dictionaries) 35 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located 36 | //(used if a resource is not found in the page, 37 | // app, or any theme specific resource dictionaries) 38 | )] 39 | 40 | // Version information for an assembly consists of the following four values: 41 | // 42 | // Major Version 43 | // Minor Version 44 | // Build Number 45 | // Revision 46 | // 47 | // You can specify all the values or you can default the Build and Revision Numbers 48 | // by using the '*' as shown below: 49 | //[assembly: AssemblyVersion("1.0.*")] 50 | -------------------------------------------------------------------------------- /QuickLook.Plugin.SumatraPDFReader/QuickLook.Plugin.SumatraPDFReader.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | Library 4 | net462 5 | QuickLook.Plugin.SumatraPDFReader 6 | QuickLook.Plugin.SumatraPDFReader 7 | AnyCPU;x64 8 | true 9 | true 10 | latest 11 | true 12 | false 13 | false 14 | false 15 | full 16 | MinimumRecommendedRules.ruleset 17 | 18 | 19 | 20 | false 21 | ..\..\QuickLook\Build\Debug\QuickLook.Plugin\QuickLook.Plugin.SumatraPDFReader 22 | DEBUG;TRACE 23 | 24 | 25 | 26 | true 27 | ..\Build\Release\ 28 | TRACE 29 | 30 | 31 | 32 | 33 | PreserveNewest 34 | $(OutDir)\x64\SumatraPDF\ 35 | x64\SumatraPDF.exe 36 | 37 | 38 | PreserveNewest 39 | $(OutDir)\x86\SumatraPDF\ 40 | x86\SumatraPDF.exe 41 | 42 | 43 | PreserveNewest 44 | $(OutDir)\arm64\SumatraPDF\ 45 | arm64\SumatraPDF.exe 46 | 47 | 48 | PreserveNewest 49 | $(OutDir)\x64\SumatraPDF\ 50 | x64\SumatraPDF-settings.txt 51 | 52 | 53 | PreserveNewest 54 | $(OutDir)\x86\SumatraPDF\ 55 | x86\SumatraPDF-settings.txt 56 | 57 | 58 | PreserveNewest 59 | $(OutDir)\arm64\SumatraPDF\ 60 | arm64\SumatraPDF-settings.txt 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | Always 77 | 78 | 79 | 80 | 81 | 82 | all 83 | compile; runtime; build; native; contentfiles; analyzers; buildtransitive 84 | 85 | 86 | 87 | 88 | 89 | 90 | {85FDD6BA-871D-46C8-BD64-F6BB0CB5EA95} 91 | QuickLook.Common 92 | False 93 | 94 | 95 | 96 | 97 | 98 | Properties\GitVersion.cs 99 | 100 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /QuickLook.Plugin.SumatraPDFReader/Resources/SumatraPDF-settings-Darker.txt: -------------------------------------------------------------------------------- 1 | # All available settings in https://www.sumatrapdfreader.org/settings/settings3-3 2 | 3 | # SumatraPDFControl works only with update version of SumatraPDF.exe with enhanced plugin mode modifications from https://github.com/marcoscmonteiro/sumatrapdf 4 | # So, setting bellow signal to don't check for updates because we do not want SumatraPDF.exe updated with official version from https://www.sumatrapdfreader.org/ 5 | CheckForUpdates = false 6 | Theme = Darker -------------------------------------------------------------------------------- /QuickLook.Plugin.SumatraPDFReader/Resources/SumatraPDF-settings-Light.txt: -------------------------------------------------------------------------------- 1 | # All available settings in https://www.sumatrapdfreader.org/settings/settings3-3 2 | 3 | # SumatraPDFControl works only with update version of SumatraPDF.exe with enhanced plugin mode modifications from https://github.com/marcoscmonteiro/sumatrapdf 4 | # So, setting bellow signal to don't check for updates because we do not want SumatraPDF.exe updated with official version from https://www.sumatrapdfreader.org/ 5 | CheckForUpdates = false -------------------------------------------------------------------------------- /QuickLook.Plugin.SumatraPDFReader/SumatraPDFControl.Designer.cs: -------------------------------------------------------------------------------- 1 | // Copyright © 2025 QL-Win Contributors 2 | // 3 | // This file is part of QuickLook program. 4 | // 5 | // This program is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | using System; 19 | 20 | namespace QuickLook.Plugin.SumatraPDFReader; 21 | 22 | partial class SumatraPDFControl 23 | { 24 | /// 25 | /// Variável de designer necessária. 26 | /// 27 | private System.ComponentModel.IContainer components = null; 28 | 29 | /// 30 | /// Cleaning resources being used 31 | /// 32 | /// true if necessary to dispose managed resources. 33 | protected override void Dispose(bool disposing) 34 | { 35 | if (pSumatraWindowHandle != (IntPtr)0) 36 | { 37 | CloseDocument(); 38 | pSumatraWindowHandleList.Remove(pSumatraWindowHandle); 39 | } 40 | if (disposing && (components != null)) 41 | { 42 | components.Dispose(); 43 | } 44 | base.Dispose(disposing); 45 | } 46 | 47 | #region Código gerado pelo Designer de Componentes 48 | 49 | /// 50 | /// Método necessário para suporte ao Designer - não modifique 51 | /// o conteúdo deste método com o editor de código. 52 | /// 53 | private void InitializeComponent() 54 | { 55 | this.SuspendLayout(); 56 | // 57 | // SumatraPDFControl 58 | // 59 | this.BackColor = System.Drawing.SystemColors.ActiveBorder; 60 | this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; 61 | this.Cursor = System.Windows.Forms.Cursors.Default; 62 | this.Size = new System.Drawing.Size(460, 334); 63 | this.Resize += new System.EventHandler(this.SumatraPDFControl_Resize); 64 | this.ResumeLayout(false); 65 | 66 | } 67 | 68 | #endregion 69 | } 70 | -------------------------------------------------------------------------------- /QuickLook.Plugin.SumatraPDFReader/SumatraPDFControl.cs: -------------------------------------------------------------------------------- 1 | // Copyright © 2025 QL-Win Contributors 2 | // 3 | // This file is part of QuickLook program. 4 | // 5 | // This program is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | using System; 19 | using System.Collections.Generic; 20 | using System.ComponentModel; 21 | using System.Diagnostics; 22 | using System.IO; 23 | using System.Reflection; 24 | using System.Runtime.InteropServices; 25 | using System.Text; 26 | using System.Text.RegularExpressions; 27 | using System.Windows.Forms; 28 | 29 | namespace QuickLook.Plugin.SumatraPDFReader; 30 | 31 | /// 32 | /// Windows Forms Control which embeds modifed version of SumatraPDF to read and view Portable Document Files (PDF) 33 | /// 34 | /// 35 | /// This control allows you to open and read PDF files with most features present in great SumatraPDF reader (https://www.sumatrapdfreader.org/). 36 | /// It requires an specific compiled Sumatra code version (https://github.com/marcoscmonteiro/sumatrapdf) which enables SumatraPDF 37 | /// working in an enhanced plugin mode. 38 | /// It's forked from original SumatraPDF code (https://github.com/sumatrapdfreader/sumatrapdf) 39 | /// 40 | [Guid("E5FDA170-ACF6-4C4D-AAF9-C8F9C70EE09C")] 41 | public partial class SumatraPDFControl : Control 42 | { 43 | private struct COPYDATASTRUCT 44 | { 45 | public nint dwData; 46 | public int cbData; 47 | public nint lpData; 48 | } 49 | 50 | [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] 51 | private static extern nint FindWindowEx(nint parentHandle, nint childAfter, string lclassName, string windowTitle); 52 | 53 | [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] 54 | private static extern int MoveWindow(nint hWnd, int X, int Y, int nWidth, int nHeight, int bRepaint); 55 | 56 | [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] 57 | private static extern nint SendMessage(nint hWnd, uint Msg, nint wParam, nint lParam); 58 | 59 | [DllImport("user32.dll")] 60 | private static extern int SendNotifyMessage(nint hWnd, uint Msg, nint wParam, nint lParam); 61 | 62 | // Windows constants and default pointers 63 | private const int WM_COPYDATA = 0x004A; 64 | 65 | private const int WM_DESTROY = 0x0002; 66 | private const int WM_SETFOCUS = 0x0007; 67 | private const int WM_PARENTNOTIFY = 0x0210; 68 | private const int WM_LBUTTONDOWN = 0x0201; 69 | private const int WM_LBUTTONDBLCLK = 0x0203; 70 | private const int WM_RBUTTONDOWN = 0x0204; 71 | private const int WM_RBUTTONDBLCLK = 0x0206; 72 | private const int WM_KEYDOWN = 0x0100; 73 | private const int WM_KEYUP = 0x0101; 74 | private const int WM_CHAR = 0x0102; // for use by event KeyPress 75 | 76 | private readonly nint SUMATRAPLUGIN = 0x44646558; 77 | 78 | private enum SumatraPDFCommandEmum 79 | { 80 | CmdPrint, 81 | CmdCopySelection, 82 | CmdSelectAll, 83 | CmdGoToNextPage, 84 | CmdGoToPrevPage, 85 | CmdGoToFirstPage, 86 | CmdGoToLastPage, 87 | CmdRefresh 88 | } 89 | 90 | private Process SumatraProcess; 91 | private string sCurrentFile = string.Empty; 92 | private nint pSumatraWindowHandle; 93 | private nint SUMATRAMESSAGETYPE; 94 | 95 | private static List pSumatraWindowHandleList = []; 96 | 97 | private void SumatraPDFCopyDataMsg(string strMessage, params object[] parr) 98 | { 99 | // Without define current file commands cannot be send to sumatra 100 | if (sCurrentFile == string.Empty) return; 101 | 102 | if (SumatraWindowHandle == IntPtr.Zero && pSumatraWindowHandleList.Count == 0) return; 103 | nint SumatraCurrentHandle = SumatraWindowHandle == IntPtr.Zero ? pSumatraWindowHandleList[0] : SumatraWindowHandle; 104 | 105 | string DDEMessage = string.Empty; 106 | if (strMessage.StartsWith("[")) DDEMessage = String.Format(strMessage, parr); 107 | else 108 | { 109 | DDEMessage = "[" + strMessage + "("; //\"" + sCurrentFile + "\""; 110 | bool FirstParam = true; 111 | foreach (object p in parr) 112 | { 113 | if (!FirstParam) DDEMessage += ","; else FirstParam = false; 114 | DDEMessage += p.GetType().FullName switch 115 | { 116 | "System.String" => "\"" + p.ToString() + "\"", 117 | "System.Double" => ((double)p).ToString(new System.Globalization.CultureInfo("en-US")), 118 | _ => p.ToString(), 119 | }; 120 | } 121 | DDEMessage += ")]"; 122 | } 123 | 124 | COPYDATASTRUCT DataStruct = default; 125 | DDEMessage += "\0"; 126 | DataStruct.dwData = SUMATRAMESSAGETYPE; 127 | DataStruct.cbData = checked(DDEMessage.Length * Marshal.SystemDefaultCharSize); 128 | DataStruct.lpData = Marshal.StringToHGlobalAuto(DDEMessage); 129 | nint pDataStruct = Marshal.AllocHGlobal(Marshal.SizeOf(DataStruct)); 130 | Marshal.StructureToPtr(DataStruct, pDataStruct, fDeleteOld: false); 131 | SendMessage(SumatraCurrentHandle, WM_COPYDATA, (IntPtr)0, pDataStruct); 132 | Marshal.FreeHGlobal(DataStruct.lpData); 133 | Marshal.FreeHGlobal(pDataStruct); 134 | } 135 | 136 | private void SumatraPDFMsg(uint Msg, int Cmd = 0, bool Async = false) 137 | { 138 | if (SumatraWindowHandle != (nint)0) 139 | { 140 | if (!Async) SendMessage(SumatraWindowHandle, Msg, Cmd, 0); 141 | else SendNotifyMessage(SumatraWindowHandle, Msg, Cmd, 0); 142 | } 143 | } 144 | 145 | private void SumatraPDFFrameCmd(SumatraPDFCommandEmum cmd, bool Async = false) 146 | { 147 | SumatraPDFCopyDataMsg("SetProperty", "SendCommand" + (Async ? "Async" : string.Empty), cmd.ToString()); 148 | } 149 | 150 | private nint SumatraWindowHandle 151 | { 152 | get 153 | { 154 | if (pSumatraWindowHandle == IntPtr.Zero) 155 | { 156 | pSumatraWindowHandle = FindWindowEx(base.Handle, default, null, null); 157 | if (pSumatraWindowHandle != IntPtr.Zero) 158 | pSumatraWindowHandleList.Add(pSumatraWindowHandle); 159 | } 160 | return pSumatraWindowHandle; 161 | } 162 | } 163 | 164 | private nint ParseSumatraMsg(string sMsg, nint dwData) 165 | { 166 | string sMsg0 = sMsg.Substring(0, sMsg.Length - 1); 167 | int CallBackReturn = 0; 168 | 169 | // dwData = 0x4C5255 it's a message to internet browser when SumatraPDF is operating in plugin mode, so raise LinkClickedMessage event 170 | if (dwData == 0x4C5255) 171 | { 172 | LinkClick?.Invoke(this, new LinkClickedEventArgs(sMsg0)); 173 | return CallBackReturn; 174 | } 175 | else 176 | if (dwData != SUMATRAPLUGIN) sMsg0 = string.Format("[UnknownMessage(\"{0}\")]", sMsg0); 177 | 178 | Match m = Regex.Match(sMsg0, @"\[(?\w+)\((?.*)\)\]"); 179 | if (m.Success) 180 | { 181 | string mmsg = m.Result("${message}"); 182 | switch (mmsg) 183 | { 184 | case "PageChanged": 185 | case "Page": 186 | Match mPG = Regex.Match(m.Result("${args}"), @"(?.+)\,\s*\u0022(?.*)\u0022"); 187 | nPage = int.Parse(mPG.Result("${pageNo}")); 188 | sNamedDest = mPG.Result("${namedDest}"); 189 | if (mmsg.Contains("Changed")) 190 | PageChanged?.Invoke(this, new PageChangedEventArgs(nPage, sNamedDest)); 191 | break; 192 | 193 | case "ContextMenuOpening": 194 | case "TocContextMenuOpening": 195 | 196 | Match m2 = Regex.Match(m.Result("${args}"), @"(?.+)\,\s*(?.+)"); 197 | var cmoe = new ContextMenuOpeningEventArgs(int.Parse(m2.Result("${x}")), int.Parse(m2.Result("${y}"))); 198 | 199 | ContextMenuOpening?.Invoke(this, cmoe); 200 | 201 | if (ContextMenuStrip != null && !cmoe.Handled) 202 | { 203 | cmoe.Handled = true; 204 | if (!ContextMenuStrip.Visible) 205 | { 206 | ContextMenuStrip.LostFocus -= ContextMenuStrip_LostFocus; 207 | ContextMenuStrip.Show(this, cmoe.X, cmoe.Y); 208 | ContextMenuStrip.Focus(); 209 | ContextMenuStrip.LostFocus += ContextMenuStrip_LostFocus; 210 | } 211 | } 212 | CallBackReturn = cmoe.Handled ? 1 : 0; 213 | break; 214 | 215 | case "ZoomChanged": 216 | case "ZoomChangedMouseWeel": 217 | case "Zoom": 218 | 219 | Match mZoom = Regex.Match(m.Result("${args}"), @"(?.+)\,\s*(?.+)"); 220 | fZoom = float.Parse(mZoom.Result("${x}"), new System.Globalization.CultureInfo("en-US")); 221 | float ZoomVirtual0 = float.Parse(mZoom.Result("${y}"), new System.Globalization.CultureInfo("en-US")); 222 | if (ZoomVirtual0 < 0) fZoomVirtual = (ZoomVirtualEnum)ZoomVirtual0; else fZoomVirtual = ZoomVirtualEnum.None; 223 | if (mmsg.Contains("Changed")) 224 | ZoomChanged?.Invoke(this, new ZoomChangedEventArgs(fZoom, fZoomVirtual, (mmsg != "ZoomChanged"))); 225 | break; 226 | 227 | case "Rotation": 228 | case "RotationChanged": 229 | Match mRotation = Regex.Match(m.Result("${args}"), @"(?.+)"); 230 | eRotation = (RotationEnum)int.Parse(mRotation.Result("${rot}")); 231 | break; 232 | 233 | case "DisplayModeChanged": 234 | case "DisplayMode": 235 | eDisplayMode = (DisplayModeEnum)int.Parse(m.Result("${args}")); 236 | if (mmsg.Contains("Changed")) DisplayModeChanged?.Invoke(this, new DisplayModeChangedEventArgs(eDisplayMode)); 237 | break; 238 | 239 | case "EnableAccelerators": 240 | bKeyAccelerators = (int.Parse(m.Result("${args}")) == 1); 241 | break; 242 | 243 | case "StartupFinished": 244 | StartupFinished?.Invoke(this, new EventArgs()); 245 | StartupFinished?.Invoke(this, new EventArgs()); 246 | StartupFinished?.Invoke(this, new EventArgs()); 247 | break; 248 | 249 | case "FileOpened": 250 | GetPage(); 251 | SumatraPDFCopyDataMsg("SetProperty", "AllowEditAnnotations", "0"); 252 | FileOpened?.Invoke(this, new EventArgs()); 253 | break; 254 | 255 | case "ToolbarVisible": 256 | bToolbarVisible = (int.Parse(m.Result("${args}")) == 1); 257 | break; 258 | 259 | case "TocVisible": 260 | bTocVisible = (int.Parse(m.Result("${args}")) == 1); 261 | break; 262 | 263 | case "ScrollState": 264 | case "ScrollStateChanged": 265 | Match mSP = Regex.Match(m.Result("${args}"), @"(?.+)\,(?.+)\,\s*(?.+)"); 266 | pScrollState = new ScrollStateStruct( 267 | int.Parse(mSP.Result("${page}")), 268 | double.Parse(mSP.Result("${x}"), new System.Globalization.CultureInfo("en-US")), 269 | double.Parse(mSP.Result("${y}"), new System.Globalization.CultureInfo("en-US")) 270 | ); 271 | if (mmsg.Contains("Changed")) ScrollStateChanged?.Invoke(this, new ScrollStateEventArgs(pScrollState)); 272 | break; 273 | 274 | case "PageCount": 275 | nPageCount = int.Parse(m.Result("${args}")); 276 | break; 277 | 278 | default: 279 | CallBackReturn = RaiseDefaultSumatraEvent(sMsg0, dwData); 280 | break; 281 | } 282 | } 283 | 284 | return (nint)CallBackReturn; 285 | } 286 | 287 | /// 288 | /// Processes Windows Messages. 289 | /// 290 | /// 291 | /// This method has many customizations in order to process SumatraPDF messages. So, if there is need to override, remember to call base.WndProc. 292 | /// 293 | /// The Windows to process. 294 | protected override void WndProc(ref Message m) 295 | { 296 | base.WndProc(ref m); 297 | 298 | if (m.Msg == WM_SETFOCUS) 299 | { 300 | OnEnter(new EventArgs()); 301 | } 302 | else if (m.Msg == WM_PARENTNOTIFY && (m.WParam.ToInt32() == WM_LBUTTONDOWN || m.WParam.ToInt32() == WM_RBUTTONDOWN)) 303 | { 304 | if (!base.ContainsFocus) 305 | { 306 | OnEnter(new EventArgs()); 307 | } 308 | } 309 | else if (m.Msg == WM_DESTROY && !base.IsDisposed && !base.Disposing) 310 | { 311 | Dispose(); 312 | } 313 | else if (m.Msg == WM_COPYDATA) 314 | { 315 | object lParam = m.GetLParam(typeof(COPYDATASTRUCT)); 316 | COPYDATASTRUCT x = (lParam != null) ? ((COPYDATASTRUCT)lParam) : default; 317 | byte[] strb = new byte[checked(x.cbData)]; 318 | Marshal.Copy(x.lpData, strb, 0, x.cbData); 319 | string sMsg = Encoding.Default.GetString(strb); 320 | m.Result = ParseSumatraMsg(sMsg, x.dwData); 321 | } 322 | else if (m.Msg == WM_KEYDOWN) // Control maps as MouseDown event 323 | { 324 | m.Result = LastKeyDownEventArgs.Handled ? (nint)0 : (nint)1; 325 | } 326 | else if (m.Msg == WM_CHAR) // Control maps as KeyPress event 327 | { 328 | m.Result = LastKeyPressEventArgs.Handled ? (nint)0 : (nint)1; 329 | } 330 | else if (m.Msg == WM_KEYUP) // Control maps as MouseDown event 331 | { 332 | m.Result = LastKeyUpEventArgs.Handled ? (nint)0 : (nint)1; 333 | } 334 | else if (m.Msg == WM_RBUTTONDBLCLK || m.Msg == WM_LBUTTONDBLCLK) 335 | { 336 | nint xy = m.LParam; 337 | int x = unchecked((short)(long)xy); 338 | int y = unchecked((short)((long)xy >> 16)); 339 | 340 | OnMouseDoubleClick(new MouseEventArgs(m.Msg == WM_LBUTTONDBLCLK ? MouseButtons.Left : MouseButtons.Right, 2, x, y, 0)); 341 | } 342 | } 343 | 344 | // Hide but not destroy BackgroundImage. Because this image do not need to be substituted. 345 | /// 346 | /// SumatraPDF logo 347 | /// 348 | [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] 349 | public new System.Drawing.Image BackgroundImage 350 | { 351 | get => base.BackgroundImage; 352 | set { } 353 | } 354 | 355 | private KeyEventArgs LastKeyDownEventArgs; 356 | 357 | private void SumatraPDFControl_KeyDown(object sender, KeyEventArgs e) 358 | { 359 | this.KeyDown?.Invoke(this, e); 360 | LastKeyDownEventArgs = e; 361 | } 362 | 363 | private KeyEventArgs LastKeyUpEventArgs; 364 | 365 | private void SumatraPDFControl_KeyUp(object sender, KeyEventArgs e) 366 | { 367 | this.KeyUp?.Invoke(this, e); 368 | LastKeyUpEventArgs = e; 369 | } 370 | 371 | private KeyPressEventArgs LastKeyPressEventArgs; 372 | 373 | private void SumatraPDFControl_KeyPress(object sender, KeyPressEventArgs e) 374 | { 375 | this.KeyPress?.Invoke(this, e); 376 | // Do not allow SumatraPDF close current window when pressing 'q' key 377 | if (e.KeyChar == 'q' || e.KeyChar == 'Q') e.Handled = true; 378 | // Do not allow SumatraPDF reload current document when pressing 'r' key 379 | if (e.KeyChar == 'r' || e.KeyChar == 'R') e.Handled = true; 380 | // Do not allow SumatraPDF make an annotation when pressing 'a' key 381 | if (e.KeyChar == 'a' || e.KeyChar == 'A') e.Handled = true; 382 | 383 | LastKeyPressEventArgs = e; 384 | } 385 | 386 | private void SumatraPDFControl_Resize(object sender, EventArgs e) 387 | { 388 | if (SumatraWindowHandle != IntPtr.Zero) 389 | { 390 | MoveWindow(SumatraWindowHandle, 0, 0, base.Width, base.Height, 0); 391 | } 392 | } 393 | 394 | private void ContextMenuStrip_LostFocus(object sender, EventArgs e) 395 | { 396 | if (((ContextMenuStrip)sender).Visible) ((ContextMenuStrip)sender).Close(); 397 | } 398 | 399 | private void CloseDocument() 400 | { 401 | SumatraPDFMsg(WM_DESTROY); 402 | } 403 | 404 | private int RaiseDefaultSumatraEvent(string msg, nint dwData) 405 | { 406 | var e = new SumatraMessageEventArgs { CallBackReturn = 0, Msg = msg, Data = dwData }; 407 | SumatraMessage?.Invoke(this, e); 408 | return e.CallBackReturn; 409 | } 410 | 411 | private void RestartSumatra(string sFile, int page = 1) 412 | { 413 | if ((SumatraWindowHandle != IntPtr.Zero) & (SumatraProcess != null)) 414 | { 415 | CloseDocument(); 416 | SumatraProcess?.Kill(); 417 | pSumatraWindowHandleList.Remove(pSumatraWindowHandle); 418 | pSumatraWindowHandle = IntPtr.Zero; 419 | } 420 | 421 | string sumatraComplete = ResolveSumatraPDFPath(); 422 | string platform = (RuntimeInformation.OSArchitecture == Architecture.Arm64) 423 | ? "arm64" 424 | : (Environment.Is64BitProcess ? "x64" : "x86"); 425 | string commomErrMsg = "Download or reference the latest package version from NuGet.org site in https://www.nuget.org/packages/SumatraPDF.PluginMode." + platform.Substring(1); 426 | 427 | // Verify if SumatraPDF.exe is available 428 | if (!File.Exists(sumatraComplete)) 429 | { 430 | throw new Exception(@"SumatraPDF executable not found. " + commomErrMsg); 431 | } 432 | 433 | var PSInfo = new ProcessStartInfo 434 | { 435 | FileName = sumatraComplete, 436 | CreateNoWindow = true, 437 | UseShellExecute = true, 438 | WindowStyle = ProcessWindowStyle.Minimized, 439 | Arguments = 440 | "-plugin " + base.Handle.ToString() + 441 | //" -invert-colors" + 442 | //"-set-color-range #333333 #ffffff" + 443 | //" -appdata \"c:\\users\\marco\\Downloads\"" + 444 | " -page " + page.ToString() + 445 | " \"" + sFile + "\"" 446 | }; 447 | SumatraProcess = Process.Start(PSInfo); 448 | 449 | ChildProcessTracer.Default.AddChildProcess(SumatraProcess.Handle); 450 | } 451 | 452 | public string ResolveSumatraPDFPath() 453 | { 454 | string sumatraComplete; 455 | string assemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); 456 | string platform = (RuntimeInformation.OSArchitecture == Architecture.Arm64) 457 | ? "arm64" 458 | : (Environment.Is64BitProcess ? "x64" : "x86"); 459 | 460 | if (SumatraPDFPath == null || SumatraPDFPath == string.Empty) 461 | { 462 | SumatraPDFPath = Path.Combine(assemblyPath, platform); 463 | 464 | sumatraComplete = Path.Combine(SumatraPDFPath, SumatraPDFExe); 465 | if (!File.Exists(sumatraComplete)) 466 | { 467 | if (platform == "arm64") 468 | { 469 | sumatraComplete = Path.Combine(assemblyPath, "x64", SumatraPDFExe); 470 | } 471 | else if (platform == "x64") 472 | { 473 | sumatraComplete = Path.Combine(assemblyPath, "x86", SumatraPDFExe); 474 | } 475 | } 476 | } 477 | else 478 | { 479 | sumatraComplete = Path.Combine(SumatraPDFPath, SumatraPDFExe); 480 | } 481 | 482 | return sumatraComplete; 483 | } 484 | 485 | private void OpenFile() 486 | { 487 | SumatraPDFCopyDataMsg("OpenFile", sCurrentFile, Handle.ToString()); 488 | } 489 | 490 | /// 491 | /// Structure which represents Horizontal and Vertical Scroll position of current SumatraPDF displayed page. 492 | /// 493 | public struct ScrollStateStruct 494 | { 495 | /// 496 | /// ScrollStateStruct Constructor 497 | /// 498 | /// Current page 499 | /// Horizontal scroll position 500 | /// Vertical scroll position 501 | public ScrollStateStruct(int page, double x, double y) 502 | { 503 | Page = page; 504 | X = x; 505 | Y = y; 506 | } 507 | 508 | /// 509 | /// Horizontal scroll position 510 | /// 511 | public double X { get; } 512 | 513 | /// 514 | /// Vertical scroll position 515 | /// 516 | public double Y { get; } 517 | 518 | /// 519 | /// Current displayed page 520 | /// 521 | public int Page { get; } 522 | 523 | /// 524 | /// Converts struct to string 525 | /// 526 | /// Struct string representation 527 | public override string ToString() => $"Page: {Page}, X: {X}, Y: {Y}"; 528 | } 529 | 530 | /// 531 | /// Document display mode constants 532 | /// 533 | public enum DisplayModeEnum 534 | { 535 | /// 536 | /// The continuous form of single page, facing or book view depending on the document's desired page layout 537 | /// 538 | Automatic = 0, 539 | 540 | /// 541 | /// Single page display (not continuous) 542 | /// 543 | SinglePage, 544 | 545 | /// 546 | /// Dual page display (not continuous) 547 | /// 548 | Facing, 549 | 550 | /// 551 | /// Dual page display (not continuous) 552 | /// 553 | BookView, 554 | 555 | /// 556 | /// Single page display in continuous mode 557 | /// 558 | Continuous, 559 | 560 | /// 561 | /// Dual page display in continuous mode 562 | /// 563 | ContinuousFacing, 564 | 565 | /// 566 | /// Dual page display in continuous mode 567 | /// 568 | ContinuousBookView 569 | }; 570 | 571 | /// 572 | /// Document zoom virtual enum display constants (fit page, fit width, etc) represented by real zoom factor 573 | /// 574 | public enum ZoomVirtualEnum 575 | { 576 | /// 577 | /// Constant expressing that no other constants represents the real zoom factor 578 | /// 579 | None = 0, 580 | 581 | /// 582 | /// Constant to express a real zoom factor representing a complete page display 583 | /// 584 | FitPage = -1, 585 | 586 | /// 587 | /// Constant to express a real zoom factor representing a complete horizontal page display 588 | /// 589 | FitWidth = -2, 590 | 591 | /// 592 | /// Constant to express a real zoom factor representing a complete content page display 593 | /// 594 | FitContent = -3 595 | } 596 | 597 | /// 598 | /// Document rotation enum constants 599 | /// 600 | /// 601 | /// 602 | public enum RotationEnum 603 | { 604 | /// 605 | /// No rotation 606 | /// 607 | RotNone = 0, 608 | 609 | /// 610 | /// 90 degrees clockwise rotation 611 | /// 612 | Rot90 = 90, 613 | 614 | /// 615 | /// 180 degrees rotation 616 | /// 617 | Rot180 = 180, 618 | 619 | /// 620 | /// 270 degrees clockwise rotation 621 | /// 622 | Rot270 = 270 623 | } 624 | 625 | /// 626 | /// Argument class received by event 627 | /// 628 | public class PageChangedEventArgs : EventArgs 629 | { 630 | /// 631 | /// PageChangedEventArgs constructor 632 | /// 633 | public PageChangedEventArgs(int Page, string NamedDest) 634 | { 635 | this.Page = Page; 636 | this.NamedDest = NamedDest; 637 | } 638 | 639 | /// 640 | /// Document page 641 | /// 642 | public int Page { get; } 643 | 644 | /// 645 | /// Document NamedDest 646 | /// 647 | public string NamedDest { get; } 648 | } 649 | 650 | /// 651 | /// Argument class receiced by event 652 | /// 653 | public class ContextMenuOpeningEventArgs : EventArgs 654 | { 655 | /// 656 | /// ContextMenuOpeningEventArgs constructor 657 | /// 658 | public ContextMenuOpeningEventArgs(int X, int Y) 659 | { 660 | this.X = X; 661 | this.Y = Y; 662 | Handled = false; 663 | } 664 | 665 | /// 666 | /// X horizontal position, relative to SumatraPDF control, where context menu is about to open 667 | /// 668 | public int X { get; } 669 | 670 | /// 671 | /// Y vertical position, relative to SumatraPDF control, where context menu is about to open 672 | /// 673 | public int Y { get; } 674 | 675 | /// 676 | /// Indicates wether event will be handled or not (default false) 677 | /// 678 | /// 679 | /// if set to true default context menu will not be displayed 680 | /// 681 | public bool Handled { get; set; } 682 | } 683 | 684 | /// 685 | /// Argument class received by generic event 686 | /// 687 | public class SumatraMessageEventArgs : EventArgs 688 | { 689 | /// 690 | /// Indicates wether event will be handled or not (default false) 691 | /// 692 | /// 693 | /// if set to true event will not be handled by SumatraPDF 694 | /// 695 | public int CallBackReturn { get; set; } 696 | 697 | /// 698 | /// Message generated by SumatraPDF 699 | /// 700 | public string Msg { get; set; } 701 | 702 | /// 703 | /// Pointer to extended data message generated by SumatraPDF 704 | /// 705 | public nint Data { get; set; } 706 | } 707 | 708 | /// 709 | /// Argument class received by event 710 | /// 711 | public class ZoomChangedEventArgs : EventArgs 712 | { 713 | /// 714 | /// ZoomChangedEventArgs constructor 715 | /// 716 | public ZoomChangedEventArgs(float Zoom, ZoomVirtualEnum ZoomVirtual, bool MouseWheel) 717 | { 718 | this.Zoom = Zoom; 719 | this.ZoomVirtual = ZoomVirtual; 720 | this.MouseWheel = MouseWheel; 721 | } 722 | 723 | /// 724 | /// Document zoom real factor 725 | /// 726 | public float Zoom { get; } 727 | 728 | /// 729 | /// Document zoom virtual display mode 730 | /// 731 | public ZoomVirtualEnum ZoomVirtual { get; } 732 | 733 | /// 734 | /// Indicates wether mouse wheel was responsible for zoom changed event 735 | /// 736 | public bool MouseWheel { get; } 737 | } 738 | 739 | /// 740 | /// Argument class received by event 741 | /// 742 | public class LinkClickedEventArgs : EventArgs 743 | { 744 | /// 745 | /// LinkClickedEventArgs constructor 746 | /// 747 | public LinkClickedEventArgs(string LinkText) 748 | { 749 | this.LinkText = LinkText; 750 | } 751 | 752 | /// 753 | /// Document link text clicked 754 | /// 755 | public string LinkText { get; } 756 | } 757 | 758 | /// 759 | /// Argument class received by event 760 | /// 761 | public class DisplayModeChangedEventArgs : EventArgs 762 | { 763 | /// 764 | /// DisplayModeChangedEventArgs constructor 765 | /// 766 | public DisplayModeChangedEventArgs(DisplayModeEnum DisplayMode) 767 | { 768 | this.DisplayMode = DisplayMode; 769 | } 770 | 771 | /// 772 | /// Document display mode 773 | /// 774 | public DisplayModeEnum DisplayMode { get; } 775 | } 776 | 777 | /// 778 | /// Argument class received by event 779 | /// 780 | public class ScrollStateEventArgs : EventArgs 781 | { 782 | /// 783 | /// ScrollStateEventArgs constructor 784 | /// 785 | public ScrollStateEventArgs(ScrollStateStruct ScrollState) 786 | { 787 | this.ScrollState = ScrollState; 788 | } 789 | 790 | /// 791 | /// Document scroll state 792 | /// 793 | public ScrollStateStruct ScrollState { get; } 794 | } 795 | 796 | /// 797 | /// A generic SumatraPDF message not managed by other events. 798 | /// 799 | [Description("A generic SumatraPDF message not managed by other events"), Category("SumatraPDF")] 800 | public event EventHandler SumatraMessage; 801 | 802 | /// 803 | /// Occurs after SumatraPDF.exe terminates startup process. 804 | /// 805 | /// 806 | /// 807 | /// This event occurs only after a new SumatraPDF.exe execution. So, simply loading a new document reutilizing SumatraPDF.exe instance 808 | /// do not fire this event, but only event. 809 | /// 810 | /// 811 | /// Because SumatraPDF load documents asyncronously, some methods and properties requires end of startup process in order to function: 812 | /// eg.: or . So, use these methods or properties only after event or either . 813 | /// 814 | /// 815 | /// It is only recommended to carry out the initialization procedures when handling the event because the 816 | /// event is only fired when a new instance of SumatraPDF.exe is executed. 817 | /// 818 | /// 819 | /// 820 | [Description("Occurs after SumatraPDF.exe terminates startup process"), Category("SumatraPDF")] 821 | public event EventHandler StartupFinished; 822 | 823 | /// 824 | /// Occurs after a new document load by SumatraPDFControl 825 | /// 826 | /// 827 | /// It's recomended to initilize application variables on this event because some properties and methods does not respond correctly during SumatraPDF.exe startup process. This 828 | /// event garantees that startup process was ended. See event for more details. 829 | /// 830 | /// 831 | [Description("Occurs after a new document load by SumatraPDFControl"), Category("SumatraPDF")] 832 | public event EventHandler FileOpened; 833 | 834 | /// 835 | /// Occurs after changing current visible page 836 | /// 837 | [Description("Occurs after changing current visible page"), Category("SumatraPDF")] 838 | public event EventHandler PageChanged; 839 | 840 | /// 841 | /// Occurs before trying to open ContextMenu by right mouse clicking button. 842 | /// 843 | [Description("Occurs before trying to open ContextMenu by right mouse clicking button"), Category("SumatraPDF")] 844 | public event EventHandler ContextMenuOpening; 845 | 846 | /// 847 | /// Occurs after changing zoom factor. 848 | /// 849 | [Description("Occurs after changing zoom factor"), Category("SumatraPDF")] 850 | public event EventHandler ZoomChanged; 851 | 852 | /// 853 | /// Occurs after clicking a document link. 854 | /// 855 | [Description("Occurs after clicking a document link"), Category("SumatraPDF")] 856 | public event EventHandler LinkClick; 857 | 858 | /// 859 | /// Occurs after changing display mode. 860 | /// 861 | [Description("Occurs after changing display mode"), Category("SumatraPDF")] 862 | public event EventHandler DisplayModeChanged; 863 | 864 | /// 865 | /// Occurs after changing document scroll position (vertical and/or horizontal). 866 | /// 867 | [Description("Occurs after changing document scroll position (vertical and/or horizontal)"), Category("SumatraPDF")] 868 | public event EventHandler ScrollStateChanged; 869 | 870 | #pragma warning disable CS0108 // Member hides inherited member; missing new keyword 871 | 872 | /// 873 | /// Occurs when a character, space or backspace key is pressed while the control has focus. 874 | /// 875 | [Description("Occurs when a character, space or backspace key is pressed while the control has focus"), Category("SumatraPDF")] 876 | public event EventHandler KeyPress; 877 | 878 | /// 879 | /// Occurs when a key is pressed while the control has focus. 880 | /// 881 | [Description("Occurs when a key is pressed while the control has focus"), Category("SumatraPDF")] 882 | public event KeyEventHandler KeyDown; 883 | 884 | /// 885 | /// Occurs when a key is released while the control has focus. 886 | /// 887 | [Description("Occurs when a key is released while the control has focus"), Category("SumatraPDF")] 888 | public event KeyEventHandler KeyUp; 889 | 890 | #pragma warning restore CS0108 // Member hides inherited member; missing new keyword 891 | 892 | /// 893 | /// Gets or sets the ContextMenuStrip associated with this control. 894 | /// 895 | /// 896 | /// The ContextMenuStrip for this control, or null if there is no ContextMenuStrip. The default is null. 897 | /// 898 | [Description("Generic SumatraPDF message, not managed by other events ocurred")] 899 | public new ContextMenuStrip ContextMenuStrip { get; set; } 900 | 901 | /// 902 | /// Path where SumatraPDF executable is present. If not informed assumes same SumatraPDFControl.dll directory 903 | /// 904 | [Description("Path where SumatraPDF executable is present. If not informed assumes same SumatraPDFControl.dll directory"), 905 | Category("SumatraPDF")] 906 | public string SumatraPDFPath { get; set; } 907 | 908 | private string pSumatraPDFEXE; 909 | 910 | /// 911 | /// SumatraPDF executable file name. Usually SumatraPDF.exe (default) or SumatraPDF-dll.exe 912 | /// 913 | [Description("SumatraPDF executable file name. Usually SumatraPDF.exe (default) or SumatraPDF-dll.exe"), 914 | Category("SumatraPDF")] 915 | public string SumatraPDFExe 916 | { 917 | get => pSumatraPDFEXE; 918 | set => pSumatraPDFEXE = value; 919 | } 920 | 921 | private ScrollStateStruct pScrollState; 922 | 923 | /// 924 | /// Get or set current PDF scroll state (X and Y units from visible PDF page) 925 | /// 926 | [Browsable(false)] 927 | public ScrollStateStruct ScrollState 928 | { 929 | get 930 | { 931 | SumatraPDFCopyDataMsg("GetProperty", "ScrollState"); 932 | return pScrollState; 933 | } 934 | set => SumatraPDFCopyDataMsg("SetProperty", "ScrollState", value.ToString()); 935 | } 936 | 937 | private void GetZoom() 938 | { 939 | SumatraPDFCopyDataMsg("GetProperty", "Zoom"); 940 | } 941 | 942 | private void SetZoom(float value) 943 | { 944 | SumatraPDFCopyDataMsg("SetProperty", "Zoom", value.ToString(new System.Globalization.CultureInfo("en-US"))); 945 | } 946 | 947 | private float fZoom; 948 | 949 | /// 950 | /// Get or set current numeric PDF zoom scale. 951 | /// 952 | /// 953 | /// property to get or set zoom mode like fit width, fit page etc. 954 | /// 955 | [Browsable(false)] 956 | public float Zoom 957 | { 958 | get 959 | { 960 | GetZoom(); 961 | return fZoom; 962 | } 963 | set => SetZoom(value); 964 | } 965 | 966 | private ZoomVirtualEnum fZoomVirtual; 967 | 968 | /// 969 | /// Get or set currrent PDF virtual zoom mode (Fit width, Fit Page, Fit Content or None). 970 | /// 971 | /// 972 | /// property to get or set numeric scale 973 | /// 974 | [Browsable(false)] 975 | public ZoomVirtualEnum ZoomVirtual 976 | { 977 | get 978 | { 979 | GetZoom(); 980 | return fZoomVirtual; 981 | } 982 | set 983 | { 984 | float fZoomVirtual = (int)value; 985 | if (fZoomVirtual < 0) SetZoom(fZoomVirtual); 986 | } 987 | } 988 | 989 | private void GetDisplayMode() 990 | { 991 | SumatraPDFCopyDataMsg("GetProperty", "DisplayMode"); 992 | } 993 | 994 | private DisplayModeEnum eDisplayMode; 995 | 996 | /// 997 | /// Get or set mode to display PDF pages (SinglePage, Facing, BookView, Continuous, ContinuousFacing, ContinuousBookView, Automatic) 998 | /// 999 | [Browsable(false)] 1000 | public DisplayModeEnum DisplayMode 1001 | { 1002 | get 1003 | { 1004 | GetDisplayMode(); 1005 | return eDisplayMode; 1006 | } 1007 | set => SumatraPDFCopyDataMsg("SetProperty", "DisplayMode", ((int)value).ToString()); 1008 | } 1009 | 1010 | private void GetPage() 1011 | { 1012 | SumatraPDFCopyDataMsg("GetProperty", "Page"); 1013 | } 1014 | 1015 | private void SetPage(int Page) 1016 | { 1017 | SumatraPDFCopyDataMsg("SetProperty", "Page", Page.ToString()); 1018 | } 1019 | 1020 | private int nPage; 1021 | 1022 | /// 1023 | /// Get or set current PDF page viewing position 1024 | /// 1025 | [Browsable(false)] 1026 | public int Page 1027 | { 1028 | get 1029 | { 1030 | GetPage(); 1031 | return nPage; 1032 | } 1033 | set => SetPage(value); 1034 | } 1035 | 1036 | private int nPageCount; 1037 | 1038 | /// 1039 | /// Total pages count of loaded document 1040 | /// 1041 | public int PageCount 1042 | { 1043 | get 1044 | { 1045 | SumatraPDFCopyDataMsg("GetProperty", "PageCount"); 1046 | return nPageCount; 1047 | } 1048 | } 1049 | 1050 | private RotationEnum eRotation; 1051 | 1052 | /// 1053 | /// Get current PDF rotation (see RotateBy method to change rotation state) 1054 | /// 1055 | [Browsable(false)] 1056 | public RotationEnum Rotation 1057 | { 1058 | get 1059 | { 1060 | SumatraPDFCopyDataMsg("GetProperty", "Rotation"); 1061 | return eRotation; 1062 | } 1063 | } 1064 | 1065 | private string sNamedDest; 1066 | 1067 | /// 1068 | /// Get or set current PDF NamedDest viewing position 1069 | /// 1070 | [Browsable(false)] 1071 | public string NamedDest 1072 | { 1073 | get 1074 | { 1075 | GetPage(); 1076 | return sNamedDest; 1077 | } 1078 | set => SumatraPDFCopyDataMsg("SetProperty", "NamedDest", value); 1079 | } 1080 | 1081 | private bool bToolbarVisible; 1082 | 1083 | /// 1084 | /// Get or set if SumatraPDF default toolbar is visible 1085 | /// 1086 | [Browsable(false)] 1087 | public bool ToolBarVisible 1088 | { 1089 | get 1090 | { 1091 | SumatraPDFCopyDataMsg("GetProperty", "ToolbarVisible"); 1092 | return bToolbarVisible; 1093 | } 1094 | set => SumatraPDFCopyDataMsg("SetProperty", "ToolbarVisible", value ? "1" : "0"); 1095 | } 1096 | 1097 | private bool bTocVisible; 1098 | 1099 | /// 1100 | /// Get or set if SumatraPDF Table of contents (Toc) sidebar is visible (if document doesn't have Toc it always will be false) 1101 | /// 1102 | [Browsable(false)] 1103 | public bool TocVisible 1104 | { 1105 | get 1106 | { 1107 | SumatraPDFCopyDataMsg("GetProperty", "TocVisible"); 1108 | return bTocVisible; 1109 | } 1110 | set => SumatraPDFCopyDataMsg("SetProperty", "TocVisible", value ? "1" : "0"); 1111 | } 1112 | 1113 | private bool bKeyAccelerators; 1114 | 1115 | /// 1116 | /// Get or set if Keyboard accelerators (like CTRL+A, CTRL+P, etc.) are enable or not; 1117 | /// 1118 | /// 1119 | /// If keyboard accelerators are enable pressing keys will perform the following actions: 1120 | /// 1121 | /// 1122 | /// Key 1123 | /// Action 1124 | /// 1125 | /// CTRL+ASelect All 1126 | /// CTRL+CCopy Selection 1127 | /// CTRL+FFind 1128 | /// CTRL+GGoto Page 1129 | /// CTRL+PPrint Document 1130 | /// CTRL+YZoom: Custom 1131 | /// CTRL+0Zoom: Fit Page 1132 | /// CTRL+1Zoom: Actual Size 1133 | /// CTRL+2Zoom: Fit Width 1134 | /// CTRL+3Zoom: Fit Content 1135 | /// CTRL+6View: Single Page 1136 | /// CTRL+7View: Facing 1137 | /// CTRL+8View: Book 1138 | /// CTRL+PlusKeyZoom In 1139 | /// CTRL+SHIFT+PlusKeyView: Rotate Right 1140 | /// CTRL+InsertKeyCopy Selection 1141 | /// F3Find: Next 1142 | /// SHIFT+F3Find: Previous 1143 | /// CTRL+F3Find: Next Selection 1144 | /// CTRL+SHIFT+F3Find: Previous Selection 1145 | /// CTRL+MinusKeyZoom Out 1146 | /// CTRL+SHIFT+MinusKeyView: Rotate Left 1147 | /// ALT+LeftArrowNavigate: Back 1148 | /// ALT+RightArrowNavigate: Forward 1149 | /// 1150 | /// Disabling these accelerators allow raise event of these keys. 1151 | /// 1152 | [Browsable(false)] 1153 | public bool KeyAccelerators 1154 | { 1155 | get 1156 | { 1157 | SumatraPDFCopyDataMsg("GetProperty", "EnableAccelerators"); 1158 | return bKeyAccelerators; 1159 | } 1160 | set => SumatraPDFCopyDataMsg("SetProperty", "EnableAccelerators", value ? "1" : "0"); 1161 | } 1162 | 1163 | /// 1164 | /// Default constructor 1165 | /// 1166 | public SumatraPDFControl() 1167 | { 1168 | SumatraPDFExe = "SumatraPDF.exe"; 1169 | pSumatraWindowHandle = IntPtr.Zero; 1170 | InitializeComponent(); 1171 | SUMATRAMESSAGETYPE = SUMATRAPLUGIN; 1172 | base.KeyDown += new KeyEventHandler(SumatraPDFControl_KeyDown); 1173 | base.KeyUp += new KeyEventHandler(SumatraPDFControl_KeyUp); 1174 | base.KeyPress += new KeyPressEventHandler(SumatraPDFControl_KeyPress); 1175 | } 1176 | 1177 | /// 1178 | /// Reload current loaded document in order to reflect external changes made in it 1179 | /// 1180 | public void ReloadCurrentFile() 1181 | { 1182 | SumatraPDFFrameCmd(SumatraPDFCommandEmum.CmdRefresh); 1183 | } 1184 | 1185 | /// 1186 | /// Load sumatra supported file. Current file will be closed. 1187 | /// 1188 | /// File name with complete path 1189 | /// Initial page to show 1190 | /// Open a new SumatraPDF instance (other executable process) 1191 | /// 1192 | /// In case of multiple instances of SumatraPDFControl indicates if an pre-existing instance 1193 | /// will be used or not. If true new SumatraPDF executable will be started. The default is false. 1194 | /// 1195 | public void LoadFile(string PDFFile, int InitialPage = 1, bool NewSumatraInstance = false) 1196 | { 1197 | sCurrentFile = PDFFile; 1198 | this.Page = InitialPage; 1199 | NamedDest = string.Empty; 1200 | if (SumatraWindowHandle != IntPtr.Zero) 1201 | { 1202 | OpenFile(); 1203 | pSumatraWindowHandleList.Remove(SumatraWindowHandle); 1204 | pSumatraWindowHandle = IntPtr.Zero; 1205 | } 1206 | else 1207 | { 1208 | if (NewSumatraInstance || pSumatraWindowHandleList.Count == 0) RestartSumatra(PDFFile, InitialPage); 1209 | else OpenFile(); 1210 | } 1211 | SetPage(InitialPage); 1212 | } 1213 | 1214 | /// 1215 | /// Copy to clipboard window text selection 1216 | /// 1217 | public void CopySelection() 1218 | { 1219 | SumatraPDFFrameCmd(SumatraPDFCommandEmum.CmdCopySelection); 1220 | } 1221 | 1222 | /// 1223 | /// Select all document text 1224 | /// 1225 | public void SelectAll() 1226 | { 1227 | SumatraPDFFrameCmd(SumatraPDFCommandEmum.CmdSelectAll); 1228 | } 1229 | 1230 | /// 1231 | /// Do a text search on document from beginning 1232 | /// 1233 | /// 1234 | /// Text to search 1235 | /// Match case 1236 | public void TextSearch(string searchText, bool matchCase) 1237 | { 1238 | SumatraPDFCopyDataMsg("TextSearch", searchText, (matchCase ? 1 : 0)); 1239 | } 1240 | 1241 | /// 1242 | /// Do a text search on document after a first search by 1243 | /// 1244 | /// 1245 | /// True (default) if serching forward, false if backwards 1246 | public void TextSearchNext(bool forward = true) 1247 | { 1248 | SumatraPDFCopyDataMsg("TextSearchNext", (forward ? 1 : 0)); 1249 | } 1250 | 1251 | /// 1252 | /// Show dialog to print current document (in background) 1253 | /// 1254 | /// 1255 | /// After proceeding with print it occurs in background and SumatraPDF shows an interface to cancel the whole process. 1256 | /// The following only applies for printing as image: 1257 | /// Creates a new dummy page for each page with a large zoom factor, 1258 | /// and then uses StretchDIBits to copy this to the printer's dc. 1259 | /// 1260 | public void OpenPrintDialog() 1261 | { 1262 | SumatraPDFFrameCmd(SumatraPDFCommandEmum.CmdPrint, true); 1263 | } 1264 | 1265 | /// 1266 | /// Rotate current document 1267 | /// 1268 | /// Degrees to Rotation 1269 | public void RotateBy(RotationEnum Rotation) 1270 | { 1271 | SumatraPDFCopyDataMsg("SetProperty", "RotateBy", ((int)Rotation).ToString()); 1272 | } 1273 | 1274 | /// 1275 | /// Go to next document page 1276 | /// 1277 | public void GoToNextPage() 1278 | { 1279 | SumatraPDFFrameCmd(SumatraPDFCommandEmum.CmdGoToNextPage); 1280 | } 1281 | 1282 | /// 1283 | /// Go to previous document page 1284 | /// 1285 | public void GoToPrevPage() 1286 | { 1287 | SumatraPDFFrameCmd(SumatraPDFCommandEmum.CmdGoToPrevPage); 1288 | } 1289 | 1290 | /// 1291 | /// Go to first document page 1292 | /// 1293 | public void GoToFirstPage() 1294 | { 1295 | SumatraPDFFrameCmd(SumatraPDFCommandEmum.CmdGoToFirstPage); 1296 | } 1297 | 1298 | /// 1299 | /// Go to last document page 1300 | /// 1301 | public void GoToLastPage() 1302 | { 1303 | SumatraPDFFrameCmd(SumatraPDFCommandEmum.CmdGoToLastPage); 1304 | } 1305 | } 1306 | -------------------------------------------------------------------------------- /QuickLook.Plugin.SumatraPDFReader/SumatraPanel.cs: -------------------------------------------------------------------------------- 1 | // Copyright © 2025 QL-Win Contributors 2 | // 3 | // This file is part of QuickLook program. 4 | // 5 | // This program is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | using QuickLook.Common.Helpers; 19 | using QuickLook.Common.Plugin; 20 | using System; 21 | using System.IO; 22 | using System.Text; 23 | using System.Windows; 24 | using System.Windows.Controls; 25 | using System.Windows.Resources; 26 | 27 | namespace QuickLook.Plugin.SumatraPDFReader; 28 | 29 | public partial class SumatraPanel : UserControl 30 | { 31 | public SumatraPanel() 32 | { 33 | InitializeComponent(); 34 | presenter.Background = System.Windows.Media.Brushes.White; 35 | } 36 | 37 | public void PreviewFile(string path, ContextObject context) 38 | { 39 | var sumatraPDFControl = new SumatraPDFControl(); 40 | 41 | // Resolve settings file 42 | string sumatraPDFPath = Path.GetDirectoryName(sumatraPDFControl.ResolveSumatraPDFPath()); 43 | string settingsPath = Path.Combine(sumatraPDFPath, "SumatraPDF-settings.txt"); 44 | 45 | string theme = OSThemeHelper.AppsUseDarkTheme() ? "Darker" : "Light"; 46 | StreamResourceInfo info = Application.GetResourceStream(new Uri($"pack://application:,,,/QuickLook.Plugin.SumatraPDFReader;component/Resources/SumatraPDF-settings-{theme}.txt")); 47 | using Stream stream = info?.Stream; 48 | using StreamReader streamReader = new(stream, Encoding.UTF8); 49 | string s = streamReader.ReadToEnd(); 50 | 51 | File.WriteAllText(settingsPath, s); 52 | 53 | // Load file from SumatraPDF.exe 54 | sumatraPDFControl.LoadFile(path); 55 | presenter.Child = sumatraPDFControl; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /QuickLook.Plugin.SumatraPDFReader/SumatraPanel.xaml: -------------------------------------------------------------------------------- 1 |  10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![QuickLook icon](https://user-images.githubusercontent.com/1687847/29485863-8cd61b7c-84e2-11e7-97d5-eacc2ba10d28.png) 2 | 3 | # QuickLook.Plugin.SumatraPDFReader 4 | 5 | This plugin allows [QuickLook](https://github.com/QL-Win/QuickLook) to preview multi-format (EPUB, MOBI, CBZ, CBR, FB2, CHM, XPS, DjVu) from [SumatraPDF](https://github.com/sumatrapdfreader/sumatrapdf). 6 | 7 | SumatraPDF Reader is not a replacement of PDF Viewer for QuickLook. 8 | 9 | Alternative PDF Viewer: [QuickLook.Plugin.PdfViewer-Native](https://github.com/QL-Win/QuickLook.Plugin.PdfViewer-Native) 10 | 11 | ## Supported extensions 12 | 13 | The following file extensions are treated as SumatraPDF Reader supporting files. 14 | 15 | - epub 16 | - mobi 17 | - cbz 18 | - cbr 19 | - fb2 20 | - chm 21 | - xps 22 | - djvu 23 | 24 | ## Thanks 25 | 26 | https://github.com/sumatrapdfreader/sumatrapdf 27 | 28 | https://github.com/marcoscmonteiro/SumatraPDFControl 29 | 30 | ## Licenses 31 | 32 | ![GPL-v3](https://www.gnu.org/graphics/gplv3-127x51.png) 33 | 34 | This project references many other open-source projects. See [here](https://github.com/QL-Win/QuickLook/wiki/On-the-Shoulders-of-Giants) for the full list. 35 | 36 | All source codes are licensed under [GPL-3.0](https://opensource.org/licenses/GPL-3.0). 37 | 38 | If you want to make any modification on these source codes while keeping new codes not protected by GPL-3.0, please contact me for a sublicense instead. 39 | 40 | -------------------------------------------------------------------------------- /Scripts/pack-zip.cmd: -------------------------------------------------------------------------------- 1 | powershell.exe -NoProfile -ExecutionPolicy Bypass -File pack-zip.ps1 2 | @pause 3 | -------------------------------------------------------------------------------- /Scripts/pack-zip.ps1: -------------------------------------------------------------------------------- 1 | Remove-Item ..\QuickLook.Plugin.SumatraPDFReader.qlplugin -ErrorAction SilentlyContinue 2 | 3 | $files = Get-ChildItem -Path ..\Build\Release\ -Exclude *.pdb,*.xml 4 | Compress-Archive $files ..\QuickLook.Plugin.SumatraPDFReader.zip 5 | Move-Item ..\QuickLook.Plugin.SumatraPDFReader.zip ..\QuickLook.Plugin.SumatraPDFReader.qlplugin -------------------------------------------------------------------------------- /Scripts/update-version.ps1: -------------------------------------------------------------------------------- 1 | $tag = git describe --always --tags "--abbrev=0" 2 | $revision = git describe --always --tags 3 | 4 | $text = @" 5 | // This file is generated by update-version.ps1 6 | 7 | using System.Reflection; 8 | 9 | [assembly: AssemblyVersion("$tag")] 10 | [assembly: AssemblyInformationalVersion("$revision")] 11 | "@ 12 | 13 | $text | Out-File $PSScriptRoot\..\GitVersion.cs -Encoding utf8 14 | 15 | 16 | $xml = [xml](Get-Content $PSScriptRoot\..\QuickLook.Plugin.Metadata.Base.config) 17 | $xml.Metadata.Version="$revision" 18 | $xml.Save("$PSScriptRoot\..\QuickLook.Plugin.Metadata.config") -------------------------------------------------------------------------------- /Settings.XamlStyler: -------------------------------------------------------------------------------- 1 | { 2 | "AttributesTolerance": 2, 3 | "KeepFirstAttributeOnSameLine": true, 4 | "MaxAttributeCharactersPerLine": 0, 5 | "MaxAttributesPerLine": 1, 6 | "NewlineExemptionElements": "RadialGradientBrush, GradientStop, LinearGradientBrush, ScaleTransform, SkewTransform, RotateTransform, TranslateTransform, Trigger, Condition, Setter", 7 | "SeparateByGroups": false, 8 | "AttributeIndentation": 0, 9 | "AttributeIndentationStyle": 1, 10 | "RemoveDesignTimeReferences": false, 11 | "IgnoreDesignTimeReferencePrefix": false, 12 | "EnableAttributeReordering": true, 13 | "AttributeOrderingRuleGroups": [ 14 | "x:Class", 15 | "xmlns, xmlns:x", 16 | "xmlns:*", 17 | "x:Key, Key, x:Name, Name, x:Uid, Uid, Title", 18 | "Grid.Row, Grid.RowSpan, Grid.Column, Grid.ColumnSpan, Canvas.Left, Canvas.Top, Canvas.Right, Canvas.Bottom", 19 | "Width, Height, MinWidth, MinHeight, MaxWidth, MaxHeight", 20 | "Margin, Padding, HorizontalAlignment, VerticalAlignment, HorizontalContentAlignment, VerticalContentAlignment, Panel.ZIndex", 21 | "*:*, *", 22 | "PageSource, PageIndex, Offset, Color, TargetName, Property, Value, StartPoint, EndPoint", 23 | "mc:Ignorable, d:IsDataSource, d:LayoutOverrides, d:IsStaticText", 24 | "Storyboard.*, From, To, Duration" 25 | ], 26 | "FirstLineAttributes": "", 27 | "OrderAttributesByName": true, 28 | "PutEndingBracketOnNewLine": false, 29 | "RemoveEndingTagOfEmptyElement": true, 30 | "SpaceBeforeClosingSlash": true, 31 | "RootElementLineBreakRule": 0, 32 | "ReorderVSM": 2, 33 | "ReorderGridChildren": false, 34 | "ReorderCanvasChildren": false, 35 | "ReorderSetters": 0, 36 | "FormatMarkupExtension": true, 37 | "NoNewLineMarkupExtensions": "x:Bind, Binding", 38 | "ThicknessSeparator": 2, 39 | "ThicknessAttributes": "Margin, Padding, BorderThickness, ThumbnailClipMargin", 40 | "FormatOnSave": true, 41 | "CommentPadding": 2 42 | } -------------------------------------------------------------------------------- /SumatraPDF-settings.txt: -------------------------------------------------------------------------------- 1 | # All available settings in https://www.sumatrapdfreader.org/settings/settings3-3 2 | 3 | # SumatraPDFControl works only with update version of SumatraPDF.exe with enhanced plugin mode modifications from https://github.com/marcoscmonteiro/sumatrapdf 4 | # So, setting bellow signal to don't check for updates because we do not want SumatraPDF.exe updated with official version from https://www.sumatrapdfreader.org/ 5 | CheckForUpdates = false --------------------------------------------------------------------------------