├── .gitignore ├── .gitmodules ├── Demo ├── App.config ├── Demo.csproj ├── Program.cs ├── Properties │ └── AssemblyInfo.cs └── test.pdf ├── LICENSE ├── MuPDF.sln ├── MuPDFLib ├── !Include │ ├── Collection.h │ ├── Colorspace.h │ ├── Cookie.h │ ├── Device.h │ ├── Document.h │ ├── Geometry.h │ ├── MuException.h │ ├── MuPDF.h │ ├── ObjWrapper.h │ ├── Page.h │ ├── PdfObject.h │ ├── Pixmap.h │ ├── Stream.h │ ├── TextPage.h │ └── name-table.h ├── AssemblyInfo.cpp ├── Context.cpp ├── Context.h ├── Document │ ├── Document.cpp │ ├── Page.cpp │ ├── PdfObject.cpp │ ├── Stream.cpp │ └── mupdf_load_system_font.c ├── MuPDFLib.rc ├── MuPDFLib.snk ├── MuPDFLib.vcxproj ├── MuPDFLib.vcxproj.filters ├── Rendition │ ├── Colorspace.cpp │ ├── Device.cpp │ ├── Geometry.cpp │ ├── Pixmap.cpp │ └── TextPage.cpp ├── gen_libmupdf.def.py ├── libmupdf.def ├── modify_vcxprojs.py ├── resource.h ├── sync_name_table.py └── version.py └── readme.md /.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 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Aa][Rr][Mm]/ 27 | [Aa][Rr][Mm]64/ 28 | bld/ 29 | [Bb]in/ 30 | [Oo]bj/ 31 | [Ll]og/ 32 | [Ll]ogs/ 33 | 34 | # Visual Studio 2015/2017 cache/options directory 35 | .vs/ 36 | # Uncomment if you have tasks that create the project's static files in wwwroot 37 | #wwwroot/ 38 | 39 | # Visual Studio 2017 auto generated files 40 | Generated\ Files/ 41 | 42 | # MSTest test Results 43 | [Tt]est[Rr]esult*/ 44 | [Bb]uild[Ll]og.* 45 | 46 | # NUnit 47 | *.VisualState.xml 48 | TestResult.xml 49 | nunit-*.xml 50 | 51 | # Build Results of an ATL Project 52 | [Dd]ebugPS/ 53 | [Rr]eleasePS/ 54 | dlldata.c 55 | 56 | # Benchmark Results 57 | BenchmarkDotNet.Artifacts/ 58 | 59 | # .NET Core 60 | project.lock.json 61 | project.fragment.lock.json 62 | artifacts/ 63 | 64 | # StyleCop 65 | StyleCopReport.xml 66 | 67 | # Files built by Visual Studio 68 | *_i.c 69 | *_p.c 70 | *_h.h 71 | *.ilk 72 | *.meta 73 | *.obj 74 | *.iobj 75 | *.pch 76 | *.pdb 77 | *.ipdb 78 | *.pgc 79 | *.pgd 80 | *.rsp 81 | *.sbr 82 | *.tlb 83 | *.tli 84 | *.tlh 85 | *.tmp 86 | *.tmp_proj 87 | *_wpftmp.csproj 88 | *.log 89 | *.vspscc 90 | *.vssscc 91 | .builds 92 | *.pidb 93 | *.svclog 94 | *.scc 95 | 96 | # Chutzpah Test files 97 | _Chutzpah* 98 | 99 | # Visual C++ cache files 100 | ipch/ 101 | *.aps 102 | *.ncb 103 | *.opendb 104 | *.opensdf 105 | *.sdf 106 | *.cachefile 107 | *.VC.db 108 | *.VC.VC.opendb 109 | 110 | # Visual Studio profiler 111 | *.psess 112 | *.vsp 113 | *.vspx 114 | *.sap 115 | 116 | # Visual Studio Trace Files 117 | *.e2e 118 | 119 | # TFS 2012 Local Workspace 120 | $tf/ 121 | 122 | # Guidance Automation Toolkit 123 | *.gpState 124 | 125 | # ReSharper is a .NET coding add-in 126 | _ReSharper*/ 127 | *.[Rr]e[Ss]harper 128 | *.DotSettings.user 129 | 130 | # TeamCity is a build add-in 131 | _TeamCity* 132 | 133 | # DotCover is a Code Coverage Tool 134 | *.dotCover 135 | 136 | # AxoCover is a Code Coverage Tool 137 | .axoCover/* 138 | !.axoCover/settings.json 139 | 140 | # Visual Studio code coverage results 141 | *.coverage 142 | *.coveragexml 143 | 144 | # NCrunch 145 | _NCrunch_* 146 | .*crunch*.local.xml 147 | nCrunchTemp_* 148 | 149 | # MightyMoose 150 | *.mm.* 151 | AutoTest.Net/ 152 | 153 | # Web workbench (sass) 154 | .sass-cache/ 155 | 156 | # Installshield output folder 157 | [Ee]xpress/ 158 | 159 | # DocProject is a documentation generator add-in 160 | DocProject/buildhelp/ 161 | DocProject/Help/*.HxT 162 | DocProject/Help/*.HxC 163 | DocProject/Help/*.hhc 164 | DocProject/Help/*.hhk 165 | DocProject/Help/*.hhp 166 | DocProject/Help/Html2 167 | DocProject/Help/html 168 | 169 | # Click-Once directory 170 | publish/ 171 | 172 | # Publish Web Output 173 | *.[Pp]ublish.xml 174 | *.azurePubxml 175 | # Note: Comment the next line if you want to checkin your web deploy settings, 176 | # but database connection strings (with potential passwords) will be unencrypted 177 | *.pubxml 178 | *.publishproj 179 | 180 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 181 | # checkin your Azure Web App publish settings, but sensitive information contained 182 | # in these scripts will be unencrypted 183 | PublishScripts/ 184 | 185 | # NuGet Packages 186 | *.nupkg 187 | # NuGet Symbol Packages 188 | *.snupkg 189 | # The packages folder can be ignored because of Package Restore 190 | **/[Pp]ackages/* 191 | # except build/, which is used as an MSBuild target. 192 | !**/[Pp]ackages/build/ 193 | # Uncomment if necessary however generally it will be regenerated when needed 194 | #!**/[Pp]ackages/repositories.config 195 | # NuGet v3's project.json files produces more ignorable files 196 | *.nuget.props 197 | *.nuget.targets 198 | 199 | # Microsoft Azure Build Output 200 | csx/ 201 | *.build.csdef 202 | 203 | # Microsoft Azure Emulator 204 | ecf/ 205 | rcf/ 206 | 207 | # Windows Store app package directories and files 208 | AppPackages/ 209 | BundleArtifacts/ 210 | Package.StoreAssociation.xml 211 | _pkginfo.txt 212 | *.appx 213 | *.appxbundle 214 | *.appxupload 215 | 216 | # Visual Studio cache files 217 | # files ending in .cache can be ignored 218 | *.[Cc]ache 219 | # but keep track of directories ending in .cache 220 | !?*.[Cc]ache/ 221 | 222 | # Others 223 | ClientBin/ 224 | ~$* 225 | *~ 226 | *.dbmdl 227 | *.dbproj.schemaview 228 | *.jfm 229 | *.pfx 230 | *.publishsettings 231 | orleans.codegen.cs 232 | 233 | # Including strong name files can present a security risk 234 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 235 | #*.snk 236 | 237 | # Since there are multiple workflows, uncomment next line to ignore bower_components 238 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 239 | #bower_components/ 240 | 241 | # RIA/Silverlight projects 242 | Generated_Code/ 243 | 244 | # Backup & report files from converting an old project file 245 | # to a newer Visual Studio version. Backup files are not needed, 246 | # because we have git ;-) 247 | _UpgradeReport_Files/ 248 | Backup*/ 249 | UpgradeLog*.XML 250 | UpgradeLog*.htm 251 | ServiceFabricBackup/ 252 | *.rptproj.bak 253 | 254 | # SQL Server files 255 | *.mdf 256 | *.ldf 257 | *.ndf 258 | 259 | # Business Intelligence projects 260 | *.rdl.data 261 | *.bim.layout 262 | *.bim_*.settings 263 | *.rptproj.rsuser 264 | *- [Bb]ackup.rdl 265 | *- [Bb]ackup ([0-9]).rdl 266 | *- [Bb]ackup ([0-9][0-9]).rdl 267 | 268 | # Microsoft Fakes 269 | FakesAssemblies/ 270 | 271 | # GhostDoc plugin setting file 272 | *.GhostDoc.xml 273 | 274 | # Node.js Tools for Visual Studio 275 | .ntvs_analysis.dat 276 | node_modules/ 277 | 278 | # Visual Studio 6 build log 279 | *.plg 280 | 281 | # Visual Studio 6 workspace options file 282 | *.opt 283 | 284 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 285 | *.vbw 286 | 287 | # Visual Studio LightSwitch build output 288 | **/*.HTMLClient/GeneratedArtifacts 289 | **/*.DesktopClient/GeneratedArtifacts 290 | **/*.DesktopClient/ModelManifest.xml 291 | **/*.Server/GeneratedArtifacts 292 | **/*.Server/ModelManifest.xml 293 | _Pvt_Extensions 294 | 295 | # Paket dependency manager 296 | .paket/paket.exe 297 | paket-files/ 298 | 299 | # FAKE - F# Make 300 | .fake/ 301 | 302 | # CodeRush personal settings 303 | .cr/personal 304 | 305 | # Python Tools for Visual Studio (PTVS) 306 | __pycache__/ 307 | *.pyc 308 | 309 | # Cake - Uncomment if you are using it 310 | # tools/** 311 | # !tools/packages.config 312 | 313 | # Tabs Studio 314 | *.tss 315 | 316 | # Telerik's JustMock configuration file 317 | *.jmconfig 318 | 319 | # BizTalk build output 320 | *.btp.cs 321 | *.btm.cs 322 | *.odx.cs 323 | *.xsd.cs 324 | 325 | # OpenCover UI analysis results 326 | OpenCover/ 327 | 328 | # Azure Stream Analytics local run output 329 | ASALocalRun/ 330 | 331 | # MSBuild Binary and Structured Log 332 | *.binlog 333 | 334 | # NVidia Nsight GPU debugger configuration file 335 | *.nvuser 336 | 337 | # MFractors (Xamarin productivity tool) working folder 338 | .mfractor/ 339 | 340 | # Local History for Visual Studio 341 | .localhistory/ 342 | 343 | # BeatPulse healthcheck temp database 344 | healthchecksdb 345 | 346 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 347 | MigrationBackup/ 348 | 349 | # Ionide (cross platform F# VS Code tools) working folder 350 | .ionide/ 351 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "mupdf"] 2 | path = mupdf 3 | url = https://github.com/ArtifexSoftware/mupdf 4 | -------------------------------------------------------------------------------- /Demo/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Demo/Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | x86 7 | {1003AA2F-DE18-4812-BF1A-5AC519E05A3E} 8 | Exe 9 | Demo 10 | Demo 11 | v4.7.2 12 | 512 13 | true 14 | true 15 | 16 | 17 | true 18 | bin\x64\Debug\ 19 | DEBUG;TRACE 20 | full 21 | x64 22 | 7.3 23 | prompt 24 | true 25 | 26 | 27 | bin\x64\Release\ 28 | TRACE 29 | true 30 | pdbonly 31 | x64 32 | 7.3 33 | prompt 34 | true 35 | 36 | 37 | true 38 | bin\x86\Debug\ 39 | DEBUG;TRACE 40 | full 41 | x86 42 | 7.3 43 | prompt 44 | true 45 | 46 | 47 | bin\x86\Release\ 48 | TRACE 49 | true 50 | pdbonly 51 | x86 52 | 7.3 53 | prompt 54 | true 55 | 56 | 57 | false 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | PreserveNewest 75 | 76 | 77 | 78 | 79 | {7ac327e2-05d5-4acc-9400-c78c183de505} 80 | MuPDFLib 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /Demo/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Diagnostics; 5 | using System.Drawing; 6 | using System.Drawing.Imaging; 7 | using System.IO; 8 | using System.Runtime.InteropServices; 9 | using System.Text; 10 | using MuPDF; 11 | 12 | namespace Demo 13 | { 14 | static class Program 15 | { 16 | static void Main (string[] args) { 17 | HashSet visited = new HashSet(10); 18 | using (var cookie = new Cookie()) 19 | using (var pageInfo = new StreamWriter("pages.txt", false)) { // Creates the context 20 | try { 21 | using (var doc = Document.Open("test.pdf")) { 22 | Console.WriteLine("Page count: " + doc.PageCount); 23 | Console.WriteLine("Object count: " + doc.ObjectCount); 24 | 25 | // test dict modification with Unicode (Chinese) PDF string 26 | doc.Info.Set(PdfNames.Subject, "MuPDF \u4E2D\u6587 Test Document"); 27 | doc.Info.Set(PdfNames.Producer, "MuPDF#"); 28 | doc.Info.Set(PdfNames.ModDate, DateTime.Now); 29 | PrintPdfDictionary(doc.Info, pageInfo, visited); 30 | 31 | var pn = doc.PageCount; 32 | for (int i = 0; i < pn; i++) { 33 | Console.WriteLine("Rendering page " + (i + 1)); 34 | using (var p = doc.LoadPage(i)) { 35 | File.WriteAllBytes($"Contents{i + 1}.bin.txt", p.GetContentBytes()); 36 | var b = p.Bound; 37 | pageInfo.WriteLine("Page bound: " + b); 38 | PrintPdfDictionary(p.PdfObject, pageInfo, visited); 39 | using (var resources = p.PdfObject.Locate(PdfNames.Resources, PdfNames.XObject) as PdfDictionary) { 40 | if (resources != null) { 41 | foreach (var item in resources) { 42 | if (item.Value.UnderlyingObject is PdfDictionary d) { 43 | pageInfo.WriteLine(item.Key + " is image"); 44 | } 45 | } 46 | } 47 | else { 48 | pageInfo.WriteLine("No XObject detected"); 49 | } 50 | } 51 | pageInfo.WriteLine("Text in page:"); 52 | using (var tp = p.TextPage) { 53 | foreach (var block in tp) { 54 | foreach (var line in block) { 55 | pageInfo.WriteLine($"{line}({line.FirstCharacter.Font.Name}, {line.FirstCharacter.Size} {line.FirstCharacter.Font.Flags})"); 56 | foreach (var span in line.GetSpans()) { 57 | pageInfo.Write('\t'); 58 | pageInfo.WriteLine(span.ToString()); 59 | } 60 | } 61 | } 62 | } 63 | using (var bmp = RenderPage(doc, cookie, p, b)) { 64 | Console.WriteLine("Saving picture: " + (i + 1) + ".png"); 65 | bmp.Save((i + 1) + ".png"); // saves the bitmap to a file 66 | } 67 | } 68 | } 69 | } 70 | } 71 | catch (MuException ex) { 72 | Console.Error.WriteLine("Error occurred while rendering document!"); 73 | Console.Error.WriteLine("Error code: " + ex.Code); 74 | Console.Error.WriteLine(ex.ToString()); 75 | } 76 | } 77 | Console.WriteLine ("Program finished. Press any key to quit."); 78 | Console.ReadKey (true); 79 | } 80 | 81 | static void PrintPdfDictionary(PdfDictionary dict, StreamWriter writer, HashSet visited, int indent = 0) { 82 | int count = dict.Count; 83 | writer.WriteLine(dict.Type + ": " + count + " items"); 84 | for (int i = 0; i < count; i++) { 85 | var item = dict[i]; 86 | using (PdfObject o = item.Value.UnderlyingObject) { 87 | writer.Write(new string(' ', indent << 1)); 88 | writer.Write(item.Key + ": "); 89 | if (visited.Add(o) == false) { 90 | writer.WriteLine(item.Value.ToString()); 91 | continue; 92 | } 93 | switch (o.TypeKind) { 94 | case Kind.Array: 95 | PrintPdfArray(writer, o as PdfArray); 96 | continue; 97 | case Kind.Dictionary: 98 | PrintPdfDictionary(o as PdfDictionary, writer, visited, indent + 1); 99 | continue; 100 | } 101 | writer.WriteLine(o); 102 | } 103 | } 104 | } 105 | 106 | static void PrintPdfArray(StreamWriter writer, PdfArray array) { 107 | int count = array.Count; 108 | StringBuilder sb = new StringBuilder(20) 109 | .Append('['); 110 | for (int i = 0; i < count; i++) { 111 | var item = array[i]; 112 | if (i != 0) { 113 | sb.Append(' '); 114 | } 115 | sb.Append(item); 116 | } 117 | writer.WriteLine(sb.Append(']').ToString()); 118 | } 119 | 120 | static Bitmap RenderPage (Document document, Cookie cookie, Page page, Box pageBound) { 121 | int width = (int)(pageBound.Width); // gets the size of the page 122 | int height = (int)(pageBound.Height); 123 | // creates a pixmap the same size as the width and height of the page 124 | using (Pixmap 125 | #if UNSAFE 126 | pix = Pixmap.Create(ColorspaceKind.Rgb, width, height) 127 | #else 128 | // use BGR color space to save byte conversions 129 | pix = Pixmap.Create(ColorspaceKind.Bgr, width, height) 130 | #endif 131 | ) { 132 | // sets white color as the background color of the pixmap 133 | pix.SetBackgroundWhite(); 134 | // creates a drawing device 135 | using (var dev = Device.NewDraw(pix)) { 136 | // draws the page on the device created from the pixmap 137 | page.Run(dev, cookie); 138 | // ends the drawing procedure 139 | dev.Close(); 140 | } 141 | 142 | // creates a colorful bitmap of the same size of the pixmap 143 | Bitmap bmp = new Bitmap (width, height, PixelFormat.Format24bppRgb); 144 | var imageData = bmp.LockBits (new System.Drawing.Rectangle (0, 0, width, height), ImageLockMode.ReadWrite, bmp.PixelFormat); 145 | 146 | #if UNSAFE 147 | // note: unsafe conversion from pixmap to bitmap 148 | // without the overhead of P/Invokes, the following code can run faster than the safe-conversion code below 149 | unsafe { // converts the pixmap data to Bitmap data 150 | byte* ptrSrc = (byte*)pix.Samples; // gets the rendered data from the pixmap 151 | byte* ptrDest = (byte*)imageData.Scan0; 152 | for (int y = 0; y < height; y++) { 153 | byte* pl = ptrDest; 154 | byte* sl = ptrSrc; 155 | for (int x = 0; x < width; x++) { 156 | //Swap these here instead of in MuPDF because most pdf images will be rgb or cmyk. 157 | //Since we are going through the pixels one by one anyway swap here to save a conversion from rgb to bgr. 158 | pl[2] = sl[0]; //b-r 159 | pl[1] = sl[1]; //g-g 160 | pl[0] = sl[2]; //r-b 161 | pl += 3; 162 | sl += 3; 163 | } 164 | ptrDest += imageData.Stride; 165 | ptrSrc += width * 3; 166 | } 167 | } 168 | #else 169 | // note: Safe-conversion from pixmap to bitmap 170 | var source = pix.Samples; 171 | var target = imageData.Scan0; 172 | for (int y = 0; y < height; y++) { 173 | // copy memory line by line 174 | NativeMethods.RtlMoveMemory(target, source, width * 3); 175 | target = (IntPtr)(target.ToInt64() + imageData.Stride); 176 | source = (IntPtr)(source.ToInt64() + width * 3); 177 | } 178 | #endif 179 | bmp.UnlockBits(imageData); 180 | return bmp; 181 | } 182 | } 183 | static class NativeMethods 184 | { 185 | [DllImport("kernel32.dll")] 186 | public static extern void RtlMoveMemory(IntPtr dest, IntPtr src, int byteCount); 187 | } 188 | } 189 | } 190 | -------------------------------------------------------------------------------- /Demo/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 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("Demo")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Demo")] 13 | [assembly: AssemblyCopyright("Copyright © 2020")] 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 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("1003aa2f-de18-4812-bf1a-5ac519e05a3e")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Demo/test.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wmjordan/SharpMuPDF/3031269d36eb7fb2968b3c0965764a1037f7c22b/Demo/test.pdf -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU AFFERO GENERAL PUBLIC LICENSE 2 | Version 3, 19 November 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 Affero General Public License is a free, copyleft license for 11 | software and other kinds of works, specifically designed to ensure 12 | cooperation with the community in the case of network server software. 13 | 14 | The licenses for most software and other practical works are designed 15 | to take away your freedom to share and change the works. By contrast, 16 | our General Public Licenses are intended to guarantee your freedom to 17 | share and change all versions of a program--to make sure it remains free 18 | software for all its users. 19 | 20 | When we speak of free software, we are referring to freedom, not 21 | price. Our General Public Licenses are designed to make sure that you 22 | have the freedom to distribute copies of free software (and charge for 23 | them if you wish), that you receive source code or can get it if you 24 | want it, that you can change the software or use pieces of it in new 25 | free programs, and that you know you can do these things. 26 | 27 | Developers that use our General Public Licenses protect your rights 28 | with two steps: (1) assert copyright on the software, and (2) offer 29 | you this License which gives you legal permission to copy, distribute 30 | and/or modify the software. 31 | 32 | A secondary benefit of defending all users' freedom is that 33 | improvements made in alternate versions of the program, if they 34 | receive widespread use, become available for other developers to 35 | incorporate. Many developers of free software are heartened and 36 | encouraged by the resulting cooperation. However, in the case of 37 | software used on network servers, this result may fail to come about. 38 | The GNU General Public License permits making a modified version and 39 | letting the public access it on a server without ever releasing its 40 | source code to the public. 41 | 42 | The GNU Affero General Public License is designed specifically to 43 | ensure that, in such cases, the modified source code becomes available 44 | to the community. It requires the operator of a network server to 45 | provide the source code of the modified version running there to the 46 | users of that server. Therefore, public use of a modified version, on 47 | a publicly accessible server, gives the public access to the source 48 | code of the modified version. 49 | 50 | An older license, called the Affero General Public License and 51 | published by Affero, was designed to accomplish similar goals. This is 52 | a different license, not a version of the Affero GPL, but Affero has 53 | released a new version of the Affero GPL which permits relicensing under 54 | this license. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | TERMS AND CONDITIONS 60 | 61 | 0. Definitions. 62 | 63 | "This License" refers to version 3 of the GNU Affero General Public License. 64 | 65 | "Copyright" also means copyright-like laws that apply to other kinds of 66 | works, such as semiconductor masks. 67 | 68 | "The Program" refers to any copyrightable work licensed under this 69 | License. Each licensee is addressed as "you". "Licensees" and 70 | "recipients" may be individuals or organizations. 71 | 72 | To "modify" a work means to copy from or adapt all or part of the work 73 | in a fashion requiring copyright permission, other than the making of an 74 | exact copy. The resulting work is called a "modified version" of the 75 | earlier work or a work "based on" the earlier work. 76 | 77 | A "covered work" means either the unmodified Program or a work based 78 | on the Program. 79 | 80 | To "propagate" a work means to do anything with it that, without 81 | permission, would make you directly or secondarily liable for 82 | infringement under applicable copyright law, except executing it on a 83 | computer or modifying a private copy. Propagation includes copying, 84 | distribution (with or without modification), making available to the 85 | public, and in some countries other activities as well. 86 | 87 | To "convey" a work means any kind of propagation that enables other 88 | parties to make or receive copies. Mere interaction with a user through 89 | a computer network, with no transfer of a copy, is not conveying. 90 | 91 | An interactive user interface displays "Appropriate Legal Notices" 92 | to the extent that it includes a convenient and prominently visible 93 | feature that (1) displays an appropriate copyright notice, and (2) 94 | tells the user that there is no warranty for the work (except to the 95 | extent that warranties are provided), that licensees may convey the 96 | work under this License, and how to view a copy of this License. If 97 | the interface presents a list of user commands or options, such as a 98 | menu, a prominent item in the list meets this criterion. 99 | 100 | 1. Source Code. 101 | 102 | The "source code" for a work means the preferred form of the work 103 | for making modifications to it. "Object code" means any non-source 104 | form of a work. 105 | 106 | A "Standard Interface" means an interface that either is an official 107 | standard defined by a recognized standards body, or, in the case of 108 | interfaces specified for a particular programming language, one that 109 | is widely used among developers working in that language. 110 | 111 | The "System Libraries" of an executable work include anything, other 112 | than the work as a whole, that (a) is included in the normal form of 113 | packaging a Major Component, but which is not part of that Major 114 | Component, and (b) serves only to enable use of the work with that 115 | Major Component, or to implement a Standard Interface for which an 116 | implementation is available to the public in source code form. A 117 | "Major Component", in this context, means a major essential component 118 | (kernel, window system, and so on) of the specific operating system 119 | (if any) on which the executable work runs, or a compiler used to 120 | produce the work, or an object code interpreter used to run it. 121 | 122 | The "Corresponding Source" for a work in object code form means all 123 | the source code needed to generate, install, and (for an executable 124 | work) run the object code and to modify the work, including scripts to 125 | control those activities. However, it does not include the work's 126 | System Libraries, or general-purpose tools or generally available free 127 | programs which are used unmodified in performing those activities but 128 | which are not part of the work. For example, Corresponding Source 129 | includes interface definition files associated with source files for 130 | the work, and the source code for shared libraries and dynamically 131 | linked subprograms that the work is specifically designed to require, 132 | such as by intimate data communication or control flow between those 133 | subprograms and other parts of the work. 134 | 135 | The Corresponding Source need not include anything that users 136 | can regenerate automatically from other parts of the Corresponding 137 | Source. 138 | 139 | The Corresponding Source for a work in source code form is that 140 | same work. 141 | 142 | 2. Basic Permissions. 143 | 144 | All rights granted under this License are granted for the term of 145 | copyright on the Program, and are irrevocable provided the stated 146 | conditions are met. This License explicitly affirms your unlimited 147 | permission to run the unmodified Program. The output from running a 148 | covered work is covered by this License only if the output, given its 149 | content, constitutes a covered work. This License acknowledges your 150 | rights of fair use or other equivalent, as provided by copyright law. 151 | 152 | You may make, run and propagate covered works that you do not 153 | convey, without conditions so long as your license otherwise remains 154 | in force. You may convey covered works to others for the sole purpose 155 | of having them make modifications exclusively for you, or provide you 156 | with facilities for running those works, provided that you comply with 157 | the terms of this License in conveying all material for which you do 158 | not control copyright. Those thus making or running the covered works 159 | for you must do so exclusively on your behalf, under your direction 160 | and control, on terms that prohibit them from making any copies of 161 | your copyrighted material outside their relationship with you. 162 | 163 | Conveying under any other circumstances is permitted solely under 164 | the conditions stated below. Sublicensing is not allowed; section 10 165 | makes it unnecessary. 166 | 167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 168 | 169 | No covered work shall be deemed part of an effective technological 170 | measure under any applicable law fulfilling obligations under article 171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 172 | similar laws prohibiting or restricting circumvention of such 173 | measures. 174 | 175 | When you convey a covered work, you waive any legal power to forbid 176 | circumvention of technological measures to the extent such circumvention 177 | is effected by exercising rights under this License with respect to 178 | the covered work, and you disclaim any intention to limit operation or 179 | modification of the work as a means of enforcing, against the work's 180 | users, your or third parties' legal rights to forbid circumvention of 181 | technological measures. 182 | 183 | 4. Conveying Verbatim Copies. 184 | 185 | You may convey verbatim copies of the Program's source code as you 186 | receive it, in any medium, provided that you conspicuously and 187 | appropriately publish on each copy an appropriate copyright notice; 188 | keep intact all notices stating that this License and any 189 | non-permissive terms added in accord with section 7 apply to the code; 190 | keep intact all notices of the absence of any warranty; and give all 191 | recipients a copy of this License along with the Program. 192 | 193 | You may charge any price or no price for each copy that you convey, 194 | and you may offer support or warranty protection for a fee. 195 | 196 | 5. Conveying Modified Source Versions. 197 | 198 | You may convey a work based on the Program, or the modifications to 199 | produce it from the Program, in the form of source code under the 200 | terms of section 4, provided that you also meet all of these conditions: 201 | 202 | a) The work must carry prominent notices stating that you modified 203 | it, and giving a relevant date. 204 | 205 | b) The work must carry prominent notices stating that it is 206 | released under this License and any conditions added under section 207 | 7. This requirement modifies the requirement in section 4 to 208 | "keep intact all notices". 209 | 210 | c) You must license the entire work, as a whole, under this 211 | License to anyone who comes into possession of a copy. This 212 | License will therefore apply, along with any applicable section 7 213 | additional terms, to the whole of the work, and all its parts, 214 | regardless of how they are packaged. This License gives no 215 | permission to license the work in any other way, but it does not 216 | invalidate such permission if you have separately received it. 217 | 218 | d) If the work has interactive user interfaces, each must display 219 | Appropriate Legal Notices; however, if the Program has interactive 220 | interfaces that do not display Appropriate Legal Notices, your 221 | work need not make them do so. 222 | 223 | A compilation of a covered work with other separate and independent 224 | works, which are not by their nature extensions of the covered work, 225 | and which are not combined with it such as to form a larger program, 226 | in or on a volume of a storage or distribution medium, is called an 227 | "aggregate" if the compilation and its resulting copyright are not 228 | used to limit the access or legal rights of the compilation's users 229 | beyond what the individual works permit. Inclusion of a covered work 230 | in an aggregate does not cause this License to apply to the other 231 | parts of the aggregate. 232 | 233 | 6. Conveying Non-Source Forms. 234 | 235 | You may convey a covered work in object code form under the terms 236 | of sections 4 and 5, provided that you also convey the 237 | machine-readable Corresponding Source under the terms of this License, 238 | in one of these ways: 239 | 240 | a) Convey the object code in, or embodied in, a physical product 241 | (including a physical distribution medium), accompanied by the 242 | Corresponding Source fixed on a durable physical medium 243 | customarily used for software interchange. 244 | 245 | b) Convey the object code in, or embodied in, a physical product 246 | (including a physical distribution medium), accompanied by a 247 | written offer, valid for at least three years and valid for as 248 | long as you offer spare parts or customer support for that product 249 | model, to give anyone who possesses the object code either (1) a 250 | copy of the Corresponding Source for all the software in the 251 | product that is covered by this License, on a durable physical 252 | medium customarily used for software interchange, for a price no 253 | more than your reasonable cost of physically performing this 254 | conveying of source, or (2) access to copy the 255 | Corresponding Source from a network server at no charge. 256 | 257 | c) Convey individual copies of the object code with a copy of the 258 | written offer to provide the Corresponding Source. This 259 | alternative is allowed only occasionally and noncommercially, and 260 | only if you received the object code with such an offer, in accord 261 | with subsection 6b. 262 | 263 | d) Convey the object code by offering access from a designated 264 | place (gratis or for a charge), and offer equivalent access to the 265 | Corresponding Source in the same way through the same place at no 266 | further charge. You need not require recipients to copy the 267 | Corresponding Source along with the object code. If the place to 268 | copy the object code is a network server, the Corresponding Source 269 | may be on a different server (operated by you or a third party) 270 | that supports equivalent copying facilities, provided you maintain 271 | clear directions next to the object code saying where to find the 272 | Corresponding Source. Regardless of what server hosts the 273 | Corresponding Source, you remain obligated to ensure that it is 274 | available for as long as needed to satisfy these requirements. 275 | 276 | e) Convey the object code using peer-to-peer transmission, provided 277 | you inform other peers where the object code and Corresponding 278 | Source of the work are being offered to the general public at no 279 | charge under subsection 6d. 280 | 281 | A separable portion of the object code, whose source code is excluded 282 | from the Corresponding Source as a System Library, need not be 283 | included in conveying the object code work. 284 | 285 | A "User Product" is either (1) a "consumer product", which means any 286 | tangible personal property which is normally used for personal, family, 287 | or household purposes, or (2) anything designed or sold for incorporation 288 | into a dwelling. In determining whether a product is a consumer product, 289 | doubtful cases shall be resolved in favor of coverage. For a particular 290 | product received by a particular user, "normally used" refers to a 291 | typical or common use of that class of product, regardless of the status 292 | of the particular user or of the way in which the particular user 293 | actually uses, or expects or is expected to use, the product. A product 294 | is a consumer product regardless of whether the product has substantial 295 | commercial, industrial or non-consumer uses, unless such uses represent 296 | the only significant mode of use of the product. 297 | 298 | "Installation Information" for a User Product means any methods, 299 | procedures, authorization keys, or other information required to install 300 | and execute modified versions of a covered work in that User Product from 301 | a modified version of its Corresponding Source. The information must 302 | suffice to ensure that the continued functioning of the modified object 303 | code is in no case prevented or interfered with solely because 304 | modification has been made. 305 | 306 | If you convey an object code work under this section in, or with, or 307 | specifically for use in, a User Product, and the conveying occurs as 308 | part of a transaction in which the right of possession and use of the 309 | User Product is transferred to the recipient in perpetuity or for a 310 | fixed term (regardless of how the transaction is characterized), the 311 | Corresponding Source conveyed under this section must be accompanied 312 | by the Installation Information. But this requirement does not apply 313 | if neither you nor any third party retains the ability to install 314 | modified object code on the User Product (for example, the work has 315 | been installed in ROM). 316 | 317 | The requirement to provide Installation Information does not include a 318 | requirement to continue to provide support service, warranty, or updates 319 | for a work that has been modified or installed by the recipient, or for 320 | the User Product in which it has been modified or installed. Access to a 321 | network may be denied when the modification itself materially and 322 | adversely affects the operation of the network or violates the rules and 323 | protocols for communication across the network. 324 | 325 | Corresponding Source conveyed, and Installation Information provided, 326 | in accord with this section must be in a format that is publicly 327 | documented (and with an implementation available to the public in 328 | source code form), and must require no special password or key for 329 | unpacking, reading or copying. 330 | 331 | 7. Additional Terms. 332 | 333 | "Additional permissions" are terms that supplement the terms of this 334 | License by making exceptions from one or more of its conditions. 335 | Additional permissions that are applicable to the entire Program shall 336 | be treated as though they were included in this License, to the extent 337 | that they are valid under applicable law. If additional permissions 338 | apply only to part of the Program, that part may be used separately 339 | under those permissions, but the entire Program remains governed by 340 | this License without regard to the additional permissions. 341 | 342 | When you convey a copy of a covered work, you may at your option 343 | remove any additional permissions from that copy, or from any part of 344 | it. (Additional permissions may be written to require their own 345 | removal in certain cases when you modify the work.) You may place 346 | additional permissions on material, added by you to a covered work, 347 | for which you have or can give appropriate copyright permission. 348 | 349 | Notwithstanding any other provision of this License, for material you 350 | add to a covered work, you may (if authorized by the copyright holders of 351 | that material) supplement the terms of this License with terms: 352 | 353 | a) Disclaiming warranty or limiting liability differently from the 354 | terms of sections 15 and 16 of this License; or 355 | 356 | b) Requiring preservation of specified reasonable legal notices or 357 | author attributions in that material or in the Appropriate Legal 358 | Notices displayed by works containing it; or 359 | 360 | c) Prohibiting misrepresentation of the origin of that material, or 361 | requiring that modified versions of such material be marked in 362 | reasonable ways as different from the original version; or 363 | 364 | d) Limiting the use for publicity purposes of names of licensors or 365 | authors of the material; or 366 | 367 | e) Declining to grant rights under trademark law for use of some 368 | trade names, trademarks, or service marks; or 369 | 370 | f) Requiring indemnification of licensors and authors of that 371 | material by anyone who conveys the material (or modified versions of 372 | it) with contractual assumptions of liability to the recipient, for 373 | any liability that these contractual assumptions directly impose on 374 | those licensors and authors. 375 | 376 | All other non-permissive additional terms are considered "further 377 | restrictions" within the meaning of section 10. If the Program as you 378 | received it, or any part of it, contains a notice stating that it is 379 | governed by this License along with a term that is a further 380 | restriction, you may remove that term. If a license document contains 381 | a further restriction but permits relicensing or conveying under this 382 | License, you may add to a covered work material governed by the terms 383 | of that license document, provided that the further restriction does 384 | not survive such relicensing or conveying. 385 | 386 | If you add terms to a covered work in accord with this section, you 387 | must place, in the relevant source files, a statement of the 388 | additional terms that apply to those files, or a notice indicating 389 | where to find the applicable terms. 390 | 391 | Additional terms, permissive or non-permissive, may be stated in the 392 | form of a separately written license, or stated as exceptions; 393 | the above requirements apply either way. 394 | 395 | 8. Termination. 396 | 397 | You may not propagate or modify a covered work except as expressly 398 | provided under this License. Any attempt otherwise to propagate or 399 | modify it is void, and will automatically terminate your rights under 400 | this License (including any patent licenses granted under the third 401 | paragraph of section 11). 402 | 403 | However, if you cease all violation of this License, then your 404 | license from a particular copyright holder is reinstated (a) 405 | provisionally, unless and until the copyright holder explicitly and 406 | finally terminates your license, and (b) permanently, if the copyright 407 | holder fails to notify you of the violation by some reasonable means 408 | prior to 60 days after the cessation. 409 | 410 | Moreover, your license from a particular copyright holder is 411 | reinstated permanently if the copyright holder notifies you of the 412 | violation by some reasonable means, this is the first time you have 413 | received notice of violation of this License (for any work) from that 414 | copyright holder, and you cure the violation prior to 30 days after 415 | your receipt of the notice. 416 | 417 | Termination of your rights under this section does not terminate the 418 | licenses of parties who have received copies or rights from you under 419 | this License. If your rights have been terminated and not permanently 420 | reinstated, you do not qualify to receive new licenses for the same 421 | material under section 10. 422 | 423 | 9. Acceptance Not Required for Having Copies. 424 | 425 | You are not required to accept this License in order to receive or 426 | run a copy of the Program. Ancillary propagation of a covered work 427 | occurring solely as a consequence of using peer-to-peer transmission 428 | to receive a copy likewise does not require acceptance. However, 429 | nothing other than this License grants you permission to propagate or 430 | modify any covered work. These actions infringe copyright if you do 431 | not accept this License. Therefore, by modifying or propagating a 432 | covered work, you indicate your acceptance of this License to do so. 433 | 434 | 10. Automatic Licensing of Downstream Recipients. 435 | 436 | Each time you convey a covered work, the recipient automatically 437 | receives a license from the original licensors, to run, modify and 438 | propagate that work, subject to this License. You are not responsible 439 | for enforcing compliance by third parties with this License. 440 | 441 | An "entity transaction" is a transaction transferring control of an 442 | organization, or substantially all assets of one, or subdividing an 443 | organization, or merging organizations. If propagation of a covered 444 | work results from an entity transaction, each party to that 445 | transaction who receives a copy of the work also receives whatever 446 | licenses to the work the party's predecessor in interest had or could 447 | give under the previous paragraph, plus a right to possession of the 448 | Corresponding Source of the work from the predecessor in interest, if 449 | the predecessor has it or can get it with reasonable efforts. 450 | 451 | You may not impose any further restrictions on the exercise of the 452 | rights granted or affirmed under this License. For example, you may 453 | not impose a license fee, royalty, or other charge for exercise of 454 | rights granted under this License, and you may not initiate litigation 455 | (including a cross-claim or counterclaim in a lawsuit) alleging that 456 | any patent claim is infringed by making, using, selling, offering for 457 | sale, or importing the Program or any portion of it. 458 | 459 | 11. Patents. 460 | 461 | A "contributor" is a copyright holder who authorizes use under this 462 | License of the Program or a work on which the Program is based. The 463 | work thus licensed is called the contributor's "contributor version". 464 | 465 | A contributor's "essential patent claims" are all patent claims 466 | owned or controlled by the contributor, whether already acquired or 467 | hereafter acquired, that would be infringed by some manner, permitted 468 | by this License, of making, using, or selling its contributor version, 469 | but do not include claims that would be infringed only as a 470 | consequence of further modification of the contributor version. For 471 | purposes of this definition, "control" includes the right to grant 472 | patent sublicenses in a manner consistent with the requirements of 473 | this License. 474 | 475 | Each contributor grants you a non-exclusive, worldwide, royalty-free 476 | patent license under the contributor's essential patent claims, to 477 | make, use, sell, offer for sale, import and otherwise run, modify and 478 | propagate the contents of its contributor version. 479 | 480 | In the following three paragraphs, a "patent license" is any express 481 | agreement or commitment, however denominated, not to enforce a patent 482 | (such as an express permission to practice a patent or covenant not to 483 | sue for patent infringement). To "grant" such a patent license to a 484 | party means to make such an agreement or commitment not to enforce a 485 | patent against the party. 486 | 487 | If you convey a covered work, knowingly relying on a patent license, 488 | and the Corresponding Source of the work is not available for anyone 489 | to copy, free of charge and under the terms of this License, through a 490 | publicly available network server or other readily accessible means, 491 | then you must either (1) cause the Corresponding Source to be so 492 | available, or (2) arrange to deprive yourself of the benefit of the 493 | patent license for this particular work, or (3) arrange, in a manner 494 | consistent with the requirements of this License, to extend the patent 495 | license to downstream recipients. "Knowingly relying" means you have 496 | actual knowledge that, but for the patent license, your conveying the 497 | covered work in a country, or your recipient's use of the covered work 498 | in a country, would infringe one or more identifiable patents in that 499 | country that you have reason to believe are valid. 500 | 501 | If, pursuant to or in connection with a single transaction or 502 | arrangement, you convey, or propagate by procuring conveyance of, a 503 | covered work, and grant a patent license to some of the parties 504 | receiving the covered work authorizing them to use, propagate, modify 505 | or convey a specific copy of the covered work, then the patent license 506 | you grant is automatically extended to all recipients of the covered 507 | work and works based on it. 508 | 509 | A patent license is "discriminatory" if it does not include within 510 | the scope of its coverage, prohibits the exercise of, or is 511 | conditioned on the non-exercise of one or more of the rights that are 512 | specifically granted under this License. You may not convey a covered 513 | work if you are a party to an arrangement with a third party that is 514 | in the business of distributing software, under which you make payment 515 | to the third party based on the extent of your activity of conveying 516 | the work, and under which the third party grants, to any of the 517 | parties who would receive the covered work from you, a discriminatory 518 | patent license (a) in connection with copies of the covered work 519 | conveyed by you (or copies made from those copies), or (b) primarily 520 | for and in connection with specific products or compilations that 521 | contain the covered work, unless you entered into that arrangement, 522 | or that patent license was granted, prior to 28 March 2007. 523 | 524 | Nothing in this License shall be construed as excluding or limiting 525 | any implied license or other defenses to infringement that may 526 | otherwise be available to you under applicable patent law. 527 | 528 | 12. No Surrender of Others' Freedom. 529 | 530 | If conditions are imposed on you (whether by court order, agreement or 531 | otherwise) that contradict the conditions of this License, they do not 532 | excuse you from the conditions of this License. If you cannot convey a 533 | covered work so as to satisfy simultaneously your obligations under this 534 | License and any other pertinent obligations, then as a consequence you may 535 | not convey it at all. For example, if you agree to terms that obligate you 536 | to collect a royalty for further conveying from those to whom you convey 537 | the Program, the only way you could satisfy both those terms and this 538 | License would be to refrain entirely from conveying the Program. 539 | 540 | 13. Remote Network Interaction; Use with the GNU General Public License. 541 | 542 | Notwithstanding any other provision of this License, if you modify the 543 | Program, your modified version must prominently offer all users 544 | interacting with it remotely through a computer network (if your version 545 | supports such interaction) an opportunity to receive the Corresponding 546 | Source of your version by providing access to the Corresponding Source 547 | from a network server at no charge, through some standard or customary 548 | means of facilitating copying of software. This Corresponding Source 549 | shall include the Corresponding Source for any work covered by version 3 550 | of the GNU General Public License that is incorporated pursuant to the 551 | following paragraph. 552 | 553 | Notwithstanding any other provision of this License, you have 554 | permission to link or combine any covered work with a work licensed 555 | under version 3 of the GNU General Public License into a single 556 | combined work, and to convey the resulting work. The terms of this 557 | License will continue to apply to the part which is the covered work, 558 | but the work with which it is combined will remain governed by version 559 | 3 of the GNU General Public License. 560 | 561 | 14. Revised Versions of this License. 562 | 563 | The Free Software Foundation may publish revised and/or new versions of 564 | the GNU Affero General Public License from time to time. Such new versions 565 | will be similar in spirit to the present version, but may differ in detail to 566 | address new problems or concerns. 567 | 568 | Each version is given a distinguishing version number. If the 569 | Program specifies that a certain numbered version of the GNU Affero General 570 | Public License "or any later version" applies to it, you have the 571 | option of following the terms and conditions either of that numbered 572 | version or of any later version published by the Free Software 573 | Foundation. If the Program does not specify a version number of the 574 | GNU Affero General Public License, you may choose any version ever published 575 | by the Free Software Foundation. 576 | 577 | If the Program specifies that a proxy can decide which future 578 | versions of the GNU Affero General Public License can be used, that proxy's 579 | public statement of acceptance of a version permanently authorizes you 580 | to choose that version for the Program. 581 | 582 | Later license versions may give you additional or different 583 | permissions. However, no additional obligations are imposed on any 584 | author or copyright holder as a result of your choosing to follow a 585 | later version. 586 | 587 | 15. Disclaimer of Warranty. 588 | 589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 597 | 598 | 16. Limitation of Liability. 599 | 600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 608 | SUCH DAMAGES. 609 | 610 | 17. Interpretation of Sections 15 and 16. 611 | 612 | If the disclaimer of warranty and limitation of liability provided 613 | above cannot be given local legal effect according to their terms, 614 | reviewing courts shall apply local law that most closely approximates 615 | an absolute waiver of all civil liability in connection with the 616 | Program, unless a warranty or assumption of liability accompanies a 617 | copy of the Program in return for a fee. 618 | 619 | END OF TERMS AND CONDITIONS 620 | 621 | How to Apply These Terms to Your New Programs 622 | 623 | If you develop a new program, and you want it to be of the greatest 624 | possible use to the public, the best way to achieve this is to make it 625 | free software which everyone can redistribute and change under these terms. 626 | 627 | To do so, attach the following notices to the program. It is safest 628 | to attach them to the start of each source file to most effectively 629 | state the exclusion of warranty; and each file should have at least 630 | the "copyright" line and a pointer to where the full notice is found. 631 | 632 | 633 | Copyright (C) 634 | 635 | This program is free software: you can redistribute it and/or modify 636 | it under the terms of the GNU Affero General Public License as published 637 | by the Free Software Foundation, either version 3 of the License, or 638 | (at your option) any later version. 639 | 640 | This program is distributed in the hope that it will be useful, 641 | but WITHOUT ANY WARRANTY; without even the implied warranty of 642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 643 | GNU Affero General Public License for more details. 644 | 645 | You should have received a copy of the GNU Affero General Public License 646 | along with this program. If not, see . 647 | 648 | Also add information on how to contact you by electronic and paper mail. 649 | 650 | If your software can interact with users remotely through a computer 651 | network, you should also make sure that it provides a way for users to 652 | get its source. For example, if your program is a web application, its 653 | interface could display a "Source" link that leads users to an archive 654 | of the code. There are many ways you could offer source, and different 655 | solutions will be better for different programs; see section 13 for the 656 | specific requirements. 657 | 658 | You should also get your employer (if you work as a programmer) or school, 659 | if any, to sign a "copyright disclaimer" for the program, if necessary. 660 | For more information on this, and how to apply and follow the GNU AGPL, see 661 | . 662 | -------------------------------------------------------------------------------- /MuPDFLib/!Include/Collection.h: -------------------------------------------------------------------------------- 1 | using namespace System::Collections; 2 | 3 | #ifndef __COLLECTION 4 | #define __COLLECTION 5 | 6 | namespace MuPDF { 7 | 8 | #pragma once 9 | generic 10 | private ref class EmptyCollection { 11 | public: 12 | static initonly array^ Instance = gcnew array(0); 13 | static Generic::IEnumerator^ GetEnumerator() { 14 | return ((Generic::IEnumerable^)Instance)->GetEnumerator(); 15 | } 16 | }; 17 | 18 | generic 19 | public interface class IIndexableCollection { 20 | property int Count { 21 | int get(); 22 | } 23 | property T default[int] { 24 | T get(int index); 25 | } 26 | }; 27 | 28 | generic 29 | where TCollection : IIndexableCollection 30 | ref class IndexableEnumerator : System::Collections::Generic::IEnumerator { 31 | public: 32 | IndexableEnumerator(TCollection collection) : _collection(collection), _count(collection->Count), _index(-1) {} 33 | ~IndexableEnumerator() {} 34 | property TItem Current { 35 | virtual TItem get() { 36 | return _current; 37 | } 38 | }; 39 | 40 | property Object^ CurrentBase { 41 | virtual Object^ get() sealed = System::Collections::IEnumerator::Current::get{ 42 | return Current; 43 | } 44 | }; 45 | 46 | virtual bool MoveNext() { 47 | if (++_index < _count) { 48 | _current = _collection->default[_index]; 49 | return true; 50 | } 51 | return false; 52 | } 53 | 54 | virtual void Reset() { 55 | _index = -1; 56 | } 57 | 58 | private: 59 | TCollection _collection; 60 | TItem _current; 61 | int _index; 62 | const int _count; 63 | }; 64 | 65 | template 66 | private value struct Enumerator : Generic::IEnumerator { 67 | 68 | public: 69 | Enumerator(TUnmanaged* first, TUnmanaged* last) : _first(first), _last(last) {} 70 | 71 | property TManaged^ Current { 72 | virtual TManaged^ get() { 73 | return gcnew TManaged(_current); 74 | } 75 | }; 76 | 77 | property Object^ CurrentBase { 78 | virtual Object^ get() sealed = System::Collections::IEnumerator::Current::get{ 79 | return Current; 80 | } 81 | }; 82 | 83 | virtual bool MoveNext() { 84 | if (!_current) { 85 | _current = _first; 86 | return _first != NULL; 87 | } 88 | if (_current->next && _current != _last) { 89 | _current = _current->next; 90 | return true; 91 | } 92 | return false; 93 | } 94 | 95 | virtual void Reset() { 96 | _current = NULL; 97 | } 98 | 99 | private: 100 | TUnmanaged* _first; 101 | TUnmanaged* _last; 102 | TUnmanaged* _current; 103 | }; 104 | 105 | }; 106 | 107 | #endif // !__COLLECTION 108 | 109 | -------------------------------------------------------------------------------- /MuPDFLib/!Include/Colorspace.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "mupdf/fitz.h" 3 | #include "mupdf/pdf.h" 4 | #include "MuPDF.h" 5 | 6 | #ifndef __COLORSPACE 7 | #define __COLORSPACE 8 | 9 | namespace MuPDF { 10 | 11 | public enum class ColorspaceKind { 12 | None, 13 | Gray, 14 | Rgb, 15 | Bgr, 16 | Cmyk, 17 | Lab, 18 | }; 19 | 20 | public ref class Colorspace sealed { 21 | public: 22 | Colorspace(fz_colorspace* colorspace) : _colorspace(colorspace) {}; 23 | 24 | property bool IsIndexed { 25 | bool get() { 26 | return fz_colorspace_is_indexed(Context::Ptr, _colorspace); 27 | } 28 | } 29 | property bool IsDevice { 30 | bool get() { 31 | return fz_colorspace_is_device(Context::Ptr, _colorspace); 32 | } 33 | } 34 | property bool IsGray { 35 | bool get() { 36 | return fz_colorspace_is_gray(Context::Ptr, _colorspace); 37 | } 38 | } 39 | property bool IsRgb { 40 | bool get() { 41 | return fz_colorspace_is_rgb(Context::Ptr, _colorspace); 42 | } 43 | } 44 | property bool IsCmyk { 45 | bool get() { 46 | return fz_colorspace_is_cmyk(Context::Ptr, _colorspace); 47 | } 48 | } 49 | property ColorspaceKind Kind { 50 | ColorspaceKind get() { 51 | return static_cast(fz_colorspace_type(Context::Ptr, _colorspace)); 52 | } 53 | } 54 | property int NumberOfColorant { 55 | int get() { 56 | return fz_colorspace_n(Context::Ptr, _colorspace); 57 | } 58 | } 59 | internal: 60 | property fz_colorspace* Pointer { 61 | fz_colorspace* get() { 62 | return _colorspace; 63 | } 64 | } 65 | private: 66 | Colorspace() : Colorspace(NULL) {}; 67 | fz_colorspace* _colorspace; 68 | }; 69 | }; 70 | 71 | #endif // __COLORSPACE 72 | -------------------------------------------------------------------------------- /MuPDFLib/!Include/Cookie.h: -------------------------------------------------------------------------------- 1 | #include "mupdf/fitz.h" 2 | #include "mupdf/pdf.h" 3 | #include "MuPDF.h" 4 | 5 | #ifndef __COOKIE 6 | #define __COOKIE 7 | 8 | #pragma once 9 | namespace MuPDF { 10 | 11 | public ref class Cookie : IEquatable { 12 | public: 13 | Cookie() { 14 | _cookie = new fz_cookie(); 15 | } 16 | property bool IsCancellationPending { 17 | bool get() { return _cookie->abort; } 18 | } 19 | property int Progress { 20 | int get() { return _cookie->progress; } 21 | } 22 | property int ProgressMax { 23 | int get() { return (int)(_cookie->progress_max); } 24 | } 25 | property int Errors { 26 | int get() { return _cookie->errors; } 27 | } 28 | void Cancel() { 29 | _cookie->abort = 1; 30 | } 31 | ~Cookie() { 32 | delete _cookie; 33 | } 34 | 35 | Equatable(Cookie, _cookie) 36 | 37 | internal: 38 | Cookie(fz_cookie* cookie) { 39 | _cookie = cookie; 40 | }; 41 | 42 | property fz_cookie* Ptr { 43 | fz_cookie* get() { return _cookie; } 44 | } 45 | private: 46 | fz_cookie* _cookie; 47 | }; 48 | 49 | }; 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /MuPDFLib/!Include/Device.h: -------------------------------------------------------------------------------- 1 | #include "mupdf/fitz.h" 2 | #include "mupdf/pdf.h" 3 | #include "MuPDF.h" 4 | 5 | #ifndef __DEVICE 6 | #define __DEVICE 7 | #pragma once 8 | int CloseDevice(fz_context* ctx, fz_device* dev); 9 | 10 | using namespace System; 11 | 12 | namespace MuPDF { 13 | 14 | [FlagsAttribute] 15 | public enum class DeviceHints { 16 | DontInterpolateImages = 1, 17 | NoCache = 2, 18 | DontDecodeImages = 4 19 | }; 20 | 21 | public ref class Device : IDisposable { 22 | internal: 23 | Device(fz_device* device) : _device(device) {}; 24 | ~Device() { 25 | ReleaseHandle(); 26 | } 27 | 28 | property fz_device* Ptr { 29 | fz_device* get() { 30 | return _device; 31 | } 32 | } 33 | 34 | public: 35 | /// 36 | /// Creates a new draw device to render PDF page contents. 37 | /// 38 | /// The pixmap to render page contents. 39 | /// A draw device which paints content to the pixmap. 40 | static Device^ NewDraw(Pixmap^ pixmap) { 41 | return TryCreateDevice(fz_new_draw_device(Context::Ptr, fz_identity, pixmap->Ptr)); 42 | } 43 | static Device^ NewDraw(Pixmap^ pixmap, Matrix matrix) { 44 | return TryCreateDevice(fz_new_draw_device(Context::Ptr, matrix, pixmap->Ptr)); 45 | } 46 | static Device^ NewBox(Pixmap^ pixmap, Box box) { 47 | pin_ptr p = &box; 48 | return TryCreateDevice(fz_new_bbox_device(Context::Ptr, (fz_rect*)p)); 49 | } 50 | static Device^ NewStructureText(TextPage^ textPage) { 51 | return TryCreateDevice(fz_new_stext_device(Context::Ptr, textPage->Ptr, NULL)); 52 | } 53 | static Device^ NewStructureText(TextPage^ textPage, TextOptions^ options) { 54 | auto o = (fz_stext_options)options; 55 | return TryCreateDevice(fz_new_stext_device(Context::Ptr, textPage->Ptr, &o)); 56 | } 57 | void EnableDeviceHints(DeviceHints hints) { 58 | fz_enable_device_hints(Context::Ptr, _device, (int)hints); 59 | } 60 | void DisableDeviceHints(DeviceHints hints) { 61 | fz_enable_device_hints(Context::Ptr, _device, (int)hints); 62 | } 63 | void Close() { 64 | if (!CloseDevice(Context::Ptr, _device)) { 65 | throw MuException::FromContext(); 66 | } 67 | } 68 | 69 | private: 70 | fz_device* _device; 71 | 72 | void ReleaseHandle() { 73 | CloseDevice(Context::Ptr, _device); 74 | fz_drop_device(Context::Ptr, _device); 75 | _device = NULL; 76 | } 77 | 78 | static Device^ TryCreateDevice(fz_device* device) { 79 | if (device) { 80 | return gcnew Device(device); 81 | } 82 | throw MuException::FromContext(); 83 | } 84 | }; 85 | }; 86 | 87 | #endif -------------------------------------------------------------------------------- /MuPDFLib/!Include/Document.h: -------------------------------------------------------------------------------- 1 | #include "mupdf/fitz.h" 2 | #include "mupdf/pdf.h" 3 | #include "MuPDF.h" 4 | 5 | #ifndef __DOCUMENT 6 | #define __DOCUMENT 7 | 8 | #pragma once 9 | using namespace System; 10 | using namespace System::Collections::Generic; 11 | 12 | namespace MuPDF { 13 | 14 | ref class WriterOptions; 15 | enum class PageLabelStyle; 16 | 17 | public ref class Document sealed : IDisposable, IEquatable { 18 | public: 19 | property int PageCount { 20 | int get() { 21 | return _pageCount < 0 22 | ? (_pageCount = pdf_count_pages(Context::Ptr, _pdf)) 23 | : _pageCount; 24 | } 25 | } 26 | property int Version { 27 | int get() { return _pdf->version; } 28 | } 29 | property int ObjectCount { 30 | int get() { return pdf_count_objects(Context::Ptr, _pdf); } 31 | } 32 | property long FileSize { 33 | long get() { return _pdf->file_size; } 34 | } 35 | property long StartXref { 36 | long get() { return _pdf->startxref; } 37 | } 38 | property long XrefBase { 39 | long get() { return _pdf->xref_base; } 40 | } 41 | property int AssociatedFileCount { 42 | int get() { return pdf_count_document_associated_files(Context::Ptr, _pdf); } 43 | } 44 | property int IncrementalSectionCount { 45 | int get() { return _pdf->num_incremental_sections; } 46 | } 47 | property int XrefSectionCount { 48 | int get() { return _pdf->num_xref_sections; } 49 | } 50 | property bool NeedsPassword { 51 | bool get() { return fz_needs_password(Context::Ptr, _document); } 52 | } 53 | property bool WasRepaired { 54 | bool get() { return pdf_was_repaired(Context::Ptr, _pdf); } 55 | } 56 | property bool RepairAttempted { 57 | bool get() { return _pdf->repair_attempted; } 58 | } 59 | property bool PageTreeBroken { 60 | bool get() { return _pdf->page_tree_broken; } 61 | } 62 | property bool HasUnsavedChanges { 63 | bool get() { return pdf_has_unsaved_changes(Context::Ptr, _pdf); } 64 | } 65 | property bool Redacted { 66 | bool get() { return _pdf->redacted; } 67 | } 68 | property bool ResyncRequired { 69 | bool get() { return _pdf->resynth_required; } 70 | } 71 | property int OrphansCount { 72 | int get() { return _pdf->orphans_count; } 73 | } 74 | property String^ FilePath { 75 | String^ get() { return _path; } 76 | internal: void set(String^ value) { _path = value; } 77 | } 78 | property PdfDictionary^ Trailer { 79 | PdfDictionary^ get() { 80 | return gcnew PdfDictionary(_trailer); 81 | } 82 | } 83 | property PdfDictionary^ Root { 84 | PdfDictionary^ get() { 85 | return gcnew PdfDictionary(pdf_dict_get(Context::Ptr, _trailer, PDF_NAME(Root))); 86 | } 87 | } 88 | property PdfDocumentInfo^ Info { 89 | PdfDocumentInfo^ get() { 90 | return gcnew PdfDocumentInfo(pdf_dict_get(Context::Ptr, _trailer, PDF_NAME(Info))); 91 | } 92 | } 93 | property bool CanUndo { 94 | bool get() { return pdf_can_undo(Context::Ptr, _pdf); } 95 | } 96 | property bool CanRedo { 97 | bool get() { return pdf_can_redo(Context::Ptr, _pdf); } 98 | } 99 | property bool CanBeSavedIncrementally { 100 | bool get() { return pdf_can_be_saved_incrementally(Context::Ptr, _pdf); } 101 | } 102 | property bool IsDisposed { 103 | bool get() { return _document == NULL; } 104 | } 105 | 106 | static MuPDF::Document^ Open(String^ filePath); 107 | static MuPDF::Document^ Open(array^ memoryFile); 108 | 109 | /// 110 | /// Loads specific page from document. 111 | /// 112 | /// The page number (starts from 0). 113 | /// The loaded page. 114 | Page^ LoadPage(int pageNumber); 115 | int GetPageNumber(Page^ page) { 116 | return pdf_lookup_page_number(Context::Ptr, _pdf, page->PagePtr); 117 | } 118 | /// 119 | /// Insert a page previously created by NewPage into the pages tree of the document. 120 | /// 121 | /// The page to be inserted. 122 | /// The page number to insert at (pages numbered from 0). 0 <= n <= page_count inserts before page n. Negative numbers or INT_MAX are treated as page count, and insert at the end. 0 inserts at the start. All existing pages are after the insertion point are shuffled up. 123 | void InsertPage(Page^ page, int beforePageNumber) { 124 | pdf_insert_page(Context::Ptr, _pdf, beforePageNumber, page->PagePtr); 125 | RefreshPageCount(); 126 | } 127 | void AppendPage(Page^ page) { 128 | pdf_insert_page(Context::Ptr, _pdf, INT_MAX, page->PagePtr); 129 | RefreshPageCount(); 130 | } 131 | /// 132 | /// Removes specific page from document (page contents and resources are still preserved). 133 | /// 134 | /// The page number (starts from 0). 135 | void DeletePage(int pageNumber) { 136 | pdf_delete_page(Context::Ptr, _pdf, pageNumber); 137 | RefreshPageCount(); 138 | } 139 | /// 140 | /// Removes specific pages [start, end) from document. This does not remove the page contents or resources from the file. 141 | /// 142 | /// The first page number to be removed (starts from 0). 143 | /// The last page number remained (starts from 0). If end is negative or greater than the number of pages in the document, it will be taken to be the end of the document. 144 | void DeletePage(int start, int end) { 145 | pdf_delete_page_range(Context::Ptr, _pdf, start, end); 146 | RefreshPageCount(); 147 | } 148 | /// 149 | /// Rearrange pages with the given order and numbers in . 150 | /// 151 | /// The page numbers of the rearranged document. 152 | void RearrangePages(array^ pageNumbers) { 153 | pin_ptr n = &pageNumbers[0]; 154 | pdf_rearrange_pages(Context::Ptr, _pdf, pageNumbers->Length, n, pdf_clean_options_structure::PDF_CLEAN_STRUCTURE_DROP); 155 | } 156 | /// 157 | /// Graft a page (and its resources) from the document to the destination document of the graft. This involves a deep copy of the objects in question. 158 | /// 159 | /// The source document to copy from. 160 | /// The source page number (pages numbered from 0, with -1 meaning "at the end"). 161 | /// The position within the destination document at which the page should be inserted (pages numbered from 0, with - 1 meaning "at the end"). 162 | void GraftPageFrom(Document^ src, int pageFrom, int pageTo) { 163 | pdf_graft_page(Context::Ptr, _pdf, pageTo, src->_pdf, pageFrom); 164 | RefreshPageCount(); 165 | } 166 | void GraftPagesFrom(Document^ src, int pageFrom, int numberOfPages, int pageTo); 167 | void GraftPagesFrom(Document^ src, System::Collections::Generic::IEnumerable^ srcPages, int pageTo); 168 | 169 | /// 170 | /// Sets page label from page . 171 | /// 172 | /// The page index (numbered from 0). 173 | /// The label style. 174 | /// The prefix of the page label. 175 | /// The start number of the label. 176 | void SetPageLabel(int index, PageLabelStyle style, String^ prefix, int start); 177 | /// 178 | /// Deletes page label from page . 179 | /// 180 | /// The page index (numbered from 0). 181 | void DeletePageLabel(int index) { 182 | pdf_delete_page_labels(Context::Ptr, _pdf, index); 183 | } 184 | 185 | MuPDF::PdfObject^ GetAssociatedFile(int index) { 186 | return MuPDF::PdfObject::Wrap(pdf_document_associated_file(Context::Ptr, _pdf, index)); 187 | } 188 | 189 | void SyncOpenPages() { 190 | pdf_sync_open_pages(Context::Ptr, _pdf); 191 | } 192 | void Save(String^ filePath, WriterOptions^ options); 193 | void SaveSnapshot(String^ filePath); 194 | bool CheckPassword(String^ password); 195 | void CloseFile() { 196 | ReleaseHandle(); 197 | } 198 | void Reopen(); 199 | 200 | #pragma region Object creation 201 | PdfDictionary^ NewPage(Box mediaBox, int rotate, PdfDictionary^ resources, array^ contents); 202 | PdfDictionary^ NewDictionary(int capacity) { 203 | return gcnew PdfDictionary(pdf_new_dict(Context::Ptr, _pdf, capacity)); 204 | } 205 | PdfArray^ NewArray(int capacity) { 206 | return gcnew PdfArray(pdf_new_array(Context::Ptr, _pdf, capacity)); 207 | } 208 | PdfArray^ NewBox(Box box) { 209 | return gcnew PdfArray(pdf_new_rect(Context::Ptr, _pdf, box)); 210 | } 211 | PdfArray^ NewMatrix(Matrix matrix) { 212 | return gcnew PdfArray(pdf_new_matrix(Context::Ptr, _pdf, matrix)); 213 | } 214 | #pragma endregion 215 | 216 | #pragma region Undo-redo 217 | void EnableJournal() { 218 | pdf_enable_journal(Context::Ptr, _pdf); 219 | } 220 | void BeginOperation() { 221 | pdf_begin_implicit_operation(Context::Ptr, _pdf); 222 | } 223 | void CancelOperation() { 224 | pdf_abandon_operation(Context::Ptr, _pdf); 225 | } 226 | void EndOperation() { 227 | pdf_end_operation(Context::Ptr, _pdf); 228 | } 229 | void Undo() { 230 | pdf_undo(Context::Ptr, _pdf); 231 | } 232 | void Redo() { 233 | pdf_redo(Context::Ptr, _pdf); 234 | } 235 | #pragma endregion 236 | 237 | Equatable(Document, _document) 238 | 239 | internal: 240 | Document() { 241 | auto d = pdf_create_document(Context::Ptr); 242 | _document = (fz_document*)d; 243 | InitTrailer(); 244 | } 245 | Document(fz_document* document) : _document(document) { 246 | InitTrailer(); 247 | }; 248 | Document(fz_stream* stream); 249 | ~Document() { 250 | ReleaseHandle(); 251 | } 252 | property pdf_document* Ptr { 253 | pdf_document* get() { return _pdf; } 254 | } 255 | private: 256 | fz_document* _document; 257 | fz_stream* _stream; 258 | pdf_document* _pdf; 259 | pdf_obj* _trailer; 260 | String^ _path; 261 | int _pageCount; 262 | 263 | void InitTrailer(); 264 | 265 | void ReleaseHandle() { 266 | fz_context* ctx = Context::Ptr; 267 | fz_drop_document(ctx, _document); 268 | fz_drop_stream(ctx, _stream); 269 | _document = NULL; 270 | _pdf = NULL; 271 | _trailer = NULL; 272 | _stream = NULL; 273 | } 274 | 275 | void OpenStream(fz_stream* stream); 276 | 277 | void RefreshPageCount() { 278 | _pageCount = -1; 279 | } 280 | }; 281 | 282 | public enum class CompressionMode 283 | { 284 | None, 285 | ZLib, 286 | Broti 287 | }; 288 | public enum class GarbageCollectionMode 289 | { 290 | None, 291 | CollectGarbage, 292 | Renumber, 293 | DeDuplicate 294 | }; 295 | public enum class EncryptionMode 296 | { 297 | Keep, 298 | Remove, 299 | Rc4_40, 300 | Rc4_128, 301 | Aes_128, 302 | Aes_256, 303 | Unknown 304 | }; 305 | [FlagsAttribute] 306 | public enum class Permissions 307 | { 308 | None, 309 | Print = 1 << 2, 310 | Modify = 1 << 3, 311 | Copy = 1 << 4, 312 | Annotate = 1 << 5, 313 | Form = 1 << 8, 314 | Accessibility = 1 << 9, /* Deprecated In Pdf 2.0 (This Permission Is Always Granted) */ 315 | Assemble = 1 << 10, 316 | PrintHq = 1 << 11, 317 | }; 318 | public enum class PageLabelStyle 319 | { 320 | None, 321 | Decimal = 'D', 322 | UpperRoman = 'R', 323 | LowerRoman = 'r', 324 | UpperAlpha = 'A', 325 | LowerAlpha = 'a' 326 | }; 327 | 328 | public ref class WriterOptions sealed { 329 | public: 330 | /// 331 | /// Write just the changed objects. 332 | /// 333 | bool Incremental; 334 | /// 335 | /// Pretty-print dictionaries and arrays. 336 | /// 337 | bool Pretty; 338 | /// 339 | /// ASCII hex encode binary streams. 340 | /// 341 | bool Ascii; 342 | /// 343 | /// Compress streams. 344 | /// 345 | CompressionMode CompressionMode; 346 | /// 347 | /// Compress (or leave compressed) image streams. 348 | /// 349 | bool CompressImages; 350 | /// 351 | /// Compress (or leave compressed) font streams. 352 | /// 353 | bool CompressFonts; 354 | /// 355 | /// Decompress streams (except when compressing images/fonts). 356 | /// 357 | bool Decompress; 358 | /// 359 | /// Garbage collect objects before saving. 360 | /// 361 | GarbageCollectionMode Garbage; 362 | bool Linear; 363 | bool Clean; 364 | bool Sanitize; 365 | bool Appearance; 366 | EncryptionMode Encrypt; 367 | bool DoNotRegenerateId; 368 | /// 369 | /// Document encryption permissions. 370 | /// 371 | Permissions Permissions; 372 | array^ OwnerPassword; 373 | array^ UserPassword; 374 | bool Snapshot; 375 | bool PreserveMetadata; 376 | bool UseObjectStreams; 377 | /// 378 | /// 0: Default, 1: min, 100: max 379 | /// 380 | int CompressionEffort; 381 | /// 382 | /// Add labels to each object showing how it can be reached from the Root. 383 | /// 384 | bool AddLabels; 385 | internal: 386 | pdf_write_options ToNative(); 387 | }; 388 | 389 | } 390 | 391 | #endif // !__DOCUMENT 392 | -------------------------------------------------------------------------------- /MuPDFLib/!Include/Geometry.h: -------------------------------------------------------------------------------- 1 | #include "mupdf/fitz.h" 2 | #include "mupdf/pdf.h" 3 | #include 4 | #include 5 | 6 | #ifndef __GEOMETRY 7 | #define __GEOMETRY 8 | 9 | #pragma once 10 | using namespace System; 11 | 12 | namespace MuPDF { 13 | 14 | /// 15 | /// A point with float coordinates. 16 | /// 17 | public value struct Point : IEquatable { 18 | public: 19 | initonly float X, Y; 20 | Point(float x, float y) { X = x; Y = y; } 21 | 22 | virtual int GetHashCode() override { 23 | return (static_cast(X) << 16) | static_cast(Y) ^ (static_cast(X) >> 16); 24 | } 25 | virtual bool Equals(Object^ other) override { 26 | Point p; 27 | return other && other->GetType() == Point::typeid 28 | && (p = safe_cast(other)).X == X 29 | && Y == p.Y; 30 | } 31 | virtual bool Equals(Point other) { 32 | return *this == other; 33 | } 34 | static bool operator == (Point a, Point b) { 35 | return a.X == b.X && a.Y == b.Y; 36 | } 37 | static bool operator != (Point a, Point b) { 38 | return a.X != b.X || a.Y != b.Y; 39 | } 40 | static operator Point(fz_point p) { 41 | return Point(p.x, p.y); 42 | } 43 | virtual String^ ToString() override { 44 | return String::Concat(X, ",", Y); 45 | } 46 | }; 47 | 48 | value struct BBox; 49 | value struct Matrix; 50 | 51 | /// 52 | /// A rectangle with float coordinates. 53 | /// 54 | public value struct Box { 55 | public: 56 | initonly float X0, Y0, X1, Y1; 57 | static initonly Box Unit = { 0, 0, 1, 1 }; 58 | static initonly Box Invalid = { 0, 0, -1, -1 }; 59 | Box(float x0, float y0, float x1, float y1) : X0(x0), X1(x1), Y0(y0), Y1(y1) {}; 60 | property bool IsEmpty { 61 | bool get() { 62 | return X0 == X1 || Y0 == Y1; 63 | } 64 | } 65 | property float Width { 66 | float get() { 67 | return X1 > X0 ? X1 - X0 : 0; 68 | } 69 | } 70 | property float Height { 71 | float get() { 72 | return Y1 > Y0 ? Y1 - Y0 : 0; 73 | } 74 | } 75 | property float Top { float get() { return Y0; } } 76 | property float Left { float get() { return X0; } } 77 | property float Bottom { float get() { return Y1; } } 78 | property float Right { float get() { return X1; } } 79 | property bool IsInfinite { 80 | bool get() { 81 | return X0 == FZ_MIN_INF_RECT && X1 == FZ_MAX_INF_RECT && 82 | Y0 == FZ_MIN_INF_RECT && Y1 == FZ_MAX_INF_RECT; 83 | } 84 | } 85 | property bool IsValid { 86 | bool get() { return X0 <= X1 && Y0 <= Y1; } 87 | } 88 | property float Area { 89 | float get() { return IsValid ? (X1 - X0) * (Y1 - Y0) : 0; } 90 | } 91 | 92 | bool Contains(Point p) { 93 | return p.X >= X0 && p.X < X1 && p.Y >= Y0 && p.Y < Y1; 94 | } 95 | Box Union(Box other) { 96 | return *this | other; 97 | } 98 | Box Intersect(Box other) { 99 | return *this & other; 100 | } 101 | Box Translate(float offsetX, float offsetY) { 102 | if (IsInfinite) return *this; 103 | return { X0 + offsetX, Y0 + offsetY, X1 + offsetX, Y1 + offsetY }; 104 | } 105 | Box Transform(Matrix matrix); 106 | BBox Round(); 107 | virtual String^ ToString() override { 108 | return String::Concat("(", X0, ",", Y0, ")-(", X1, ",", Y1, ")"); 109 | } 110 | static explicit operator Box(BBox box); 111 | static operator Box(fz_rect rect) { 112 | return Box (rect.x0, rect.y0, rect.x1, rect.y1); 113 | } 114 | static Box operator & (Box a, Box b); 115 | static Box operator | (Box a, Box b); 116 | static operator fz_rect (Box b) { 117 | return { b.X0, b.Y0, b.X1, b.Y1 }; 118 | } 119 | }; 120 | 121 | /// 122 | /// A rectangle with integer coordinates. 123 | /// 124 | public value struct BBox { 125 | public: 126 | initonly int X0, Y0, X1, Y1; 127 | static initonly BBox Unit = { 0, 0, 1, 1 }; 128 | static initonly BBox Invalid = { 0, 0, -1, -1 }; 129 | BBox(int x0, int y0, int x1, int y1) : X0(x0), X1(x1), Y0(y0), Y1(y1) {}; 130 | property int Width { 131 | int get() { 132 | return abs(X1 - X0); 133 | } 134 | } 135 | property int Height { 136 | int get() { 137 | return abs(Y1 - Y0); 138 | } 139 | } 140 | property int Top { int get() { return Y0; } } 141 | property int Left { int get() { return X0; } } 142 | property int Bottom { int get() { return Y1; } } 143 | property int Right { int get() { return X1; } } 144 | property bool IsInfinite { 145 | bool get() { 146 | return X0 == FZ_MIN_INF_RECT && X1 == FZ_MAX_INF_RECT && 147 | Y0 == FZ_MIN_INF_RECT && Y1 == FZ_MAX_INF_RECT; 148 | } 149 | } 150 | property bool IsValid { 151 | bool get() { return X0 <= X1 && Y0 <= Y1; } 152 | } 153 | bool ContainsPoint(int x, int y) { 154 | return x >= X0 && x < X1 && y >= Y0 && y < Y1; 155 | } 156 | BBox Intersect(BBox other) { 157 | return *this & other; 158 | } 159 | BBox Union(BBox other) { 160 | return *this | other; 161 | } 162 | virtual String^ ToString() override { 163 | return String::Concat("(", X0, ",", Y0, ")-(", X1, ",", Y1, ")"); 164 | } 165 | static explicit operator BBox(Box box); 166 | static BBox operator & (BBox a, BBox b); 167 | static BBox operator | (BBox a, BBox b); 168 | static operator BBox(fz_irect rect) { 169 | return BBox(rect.x0, rect.y0, rect.x1, rect.y1); 170 | } 171 | static operator fz_irect (BBox b) { 172 | return { b.X0, b.Y0, b.X1, b.Y1 }; 173 | } 174 | }; 175 | 176 | public value struct Quad { 177 | public: 178 | initonly Point UpperLeft, UpperRight, LowerLeft, LowerRight; 179 | Quad(Point ul, Point ur, Point ll, Point lr) : UpperLeft(ul), UpperRight(ur), LowerLeft(ll), LowerRight(lr) {}; 180 | 181 | bool Contains(Point p) { 182 | return 183 | IsPointInsideTriangle(p, UpperLeft, UpperRight, LowerRight) || 184 | IsPointInsideTriangle(p, UpperLeft, LowerRight, LowerLeft); 185 | } 186 | bool Contains(Quad other) { 187 | return 188 | Contains(other.UpperLeft) && 189 | Contains(other.UpperRight) && 190 | Contains(other.LowerLeft) && 191 | Contains(other.LowerRight); 192 | } 193 | Quad Union(Quad other); 194 | Box ToBox(); 195 | 196 | virtual String^ ToString() override { 197 | return String::Concat("{(", UpperLeft.X, ",", UpperLeft.Y, "),(", UpperRight.X, ",", UpperRight.Y, "),(", LowerLeft.X, ",", LowerLeft.Y, "),(", LowerRight.X, ",", LowerRight.Y, ")}"); 198 | } 199 | static operator Quad(fz_quad quad) { 200 | return Quad(quad.ul, quad.ur, quad.ll, quad.lr); 201 | } 202 | static operator fz_quad(Quad quad) { 203 | pin_ptr p = &quad; 204 | return *(fz_quad*)p; 205 | } 206 | static operator Quad(fz_rect rect) { 207 | return Quad(Point(rect.x0, rect.y0), Point(rect.x1, rect.y0), Point(rect.x0, rect.y1), Point(rect.x1, rect.y1)); 208 | } 209 | static operator Quad(Box rect) { 210 | return Quad(Point(rect.X0, rect.Y0), Point(rect.X1, rect.Y0), Point(rect.X0, rect.Y1), Point(rect.X1, rect.Y1)); 211 | } 212 | 213 | static bool IsPointInsideTriangle(Point p, Point a, Point b, Point c); 214 | }; 215 | 216 | public value struct Matrix { 217 | public: 218 | initonly float A, B, C, D, E, F; 219 | static initonly Matrix Identity = Matrix(1, 0, 0, 1, 0, 0); 220 | static initonly Matrix VerticalFlip = Matrix(1, 0, 0, -1, 0, 0); 221 | static initonly Matrix HorizontalFlip = Matrix(-1, 0, 0, 1, 0, 0); 222 | 223 | Matrix(float a, float b, float c, float d, float e, float f) : A(a), B(b), C(c), D(d), E(e), F(f) {}; 224 | Matrix Concat(Matrix value); 225 | Matrix PreScale(float sx, float sy) { 226 | return Matrix(A * sx, B * sx, C * sy, D * sy, 0, 0); 227 | } 228 | Matrix PostScale(float sx, float sy) { 229 | return Matrix(A * sx, B * sx, C * sy, D * sy, E * sx, F * sy); 230 | } 231 | Matrix RotateTo(float theta); 232 | Matrix ShearTo(float h, float v); 233 | Matrix TranslateTo(float tx, float ty) { 234 | return Matrix(A, B, C, D, tx * A + ty * C + E, tx * B + ty * D + F); 235 | } 236 | static Matrix Rotate(float theta); 237 | static Matrix Scale(float x, float y) { 238 | return Matrix(x, 0, 0, y, 0, 0); 239 | } 240 | static Matrix Shear(float h, float v) { 241 | return Matrix(1, v, h, 1, 0, 0); 242 | } 243 | static Matrix Translate(float tx, float ty) { 244 | return Matrix(1, 0, 0, 1, tx, ty); 245 | } 246 | virtual String^ ToString() override { 247 | return String::Concat("[", A, ",", B, ",", C, ",", D, ",", E, ",", F, "]"); 248 | } 249 | static operator fz_matrix(Matrix matrix) { 250 | pin_ptr p = &matrix; 251 | return *(fz_matrix*)p; 252 | //return { matrix.A,matrix.B,matrix.C,matrix.D,matrix.E,matrix.F }; 253 | } 254 | }; 255 | }; 256 | 257 | #endif // !__GEOMETRY 258 | -------------------------------------------------------------------------------- /MuPDFLib/!Include/MuException.h: -------------------------------------------------------------------------------- 1 | #include "mupdf/fitz.h" 2 | #include "../Context.h" 3 | 4 | #ifndef __MUEXCEPTION 5 | #define __MUEXCEPTION 6 | 7 | #define MuTryReturn(ctx, op, var) var = NULL; fz_try(ctx) { var = op; } fz_catch(ctx) { } return var; 8 | #define MuTry(ctx, op) fz_try(ctx) { op; } fz_catch(ctx) { return 0; } return 1; 9 | 10 | #pragma once 11 | using namespace System; 12 | 13 | namespace MuPDF { 14 | public ref class MuException : ApplicationException { 15 | public: 16 | MuException() : ApplicationException(), _code(-1) {} 17 | MuException(String^ message) : ApplicationException(message), _code(-1) {}; 18 | MuException(String^ message, Exception^ innerException) : ApplicationException(message, innerException), _code(-1) {}; 19 | property int Code { 20 | int get() { 21 | return _code; 22 | } 23 | internal: void set(int code) { 24 | _code = code; 25 | } 26 | } 27 | 28 | internal: 29 | MuException(const char* message, int code) : ApplicationException(gcnew String(message)), _code(code) {}; 30 | static MuException^ FromContext() { 31 | int code; 32 | const char* msg = fz_convert_error(Context::Ptr, &code); 33 | return gcnew MuException(msg, code); 34 | } 35 | 36 | private: 37 | int _code; 38 | }; 39 | 40 | }; 41 | 42 | #endif // !__MUEXCEPTION 43 | -------------------------------------------------------------------------------- /MuPDFLib/!Include/MuPDF.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "MuException.h" 3 | #include "Collection.h" 4 | #include "ObjWrapper.h" 5 | #include "Geometry.h" 6 | #include "Cookie.h" 7 | #include "Colorspace.h" 8 | #include "../Context.h" 9 | #include "Pixmap.h" 10 | #include "TextPage.h" 11 | #include "Device.h" 12 | #include "PdfObject.h" 13 | #include "Page.h" 14 | #include "Document.h" 15 | #include "Stream.h" 16 | 17 | #ifndef DLLEXP 18 | #define DLLEXP extern "C" __declspec(dllexport) 19 | #endif // !DLLEXP 20 | 21 | -------------------------------------------------------------------------------- /MuPDFLib/!Include/ObjWrapper.h: -------------------------------------------------------------------------------- 1 | #ifndef __OBJWRAPPER 2 | #define __OBJWRAPPER 3 | 4 | #pragma once 5 | 6 | #define GcnewArray(TManage, var, Length) array^ var = gcnew array(Length); 7 | 8 | #define GcWrap(TManage, ptr) (ptr ? gcnew TManage(ptr) : nullptr) 9 | 10 | #define Unwrap(TManage) (TManage ? TManage->Ptr : NULL) 11 | 12 | #define Equatable(TManage, OPtr) \ 13 | public: \ 14 | static bool operator == (TManage^ x, TManage^ y) { \ 15 | return Object::ReferenceEquals(x, y) || x && y && x->OPtr == y->OPtr; \ 16 | } \ 17 | static bool operator != (TManage ^ x, TManage ^ y) { \ 18 | return !(x == y); \ 19 | } \ 20 | virtual bool Equals(TManage ^ other) { \ 21 | return other && OPtr == other->OPtr; \ 22 | } \ 23 | virtual bool Equals(Object^ obj) override { \ 24 | TManage ^ p; \ 25 | return (p = dynamic_cast(obj)) && OPtr == p->OPtr; \ 26 | } \ 27 | virtual int GetHashCode() override { \ 28 | return (int)(IntPtr)OPtr; \ 29 | } 30 | 31 | #endif // !__OBJWRAPPER 32 | -------------------------------------------------------------------------------- /MuPDFLib/!Include/Page.h: -------------------------------------------------------------------------------- 1 | #include "mupdf/fitz.h" 2 | #include "mupdf/pdf.h" 3 | #include "MuPDF.h" 4 | 5 | #ifndef __PAGE 6 | #define __PAGE 7 | 8 | #pragma once 9 | using namespace System; 10 | namespace MuPDF { 11 | 12 | public enum class PageBoxType { 13 | Media, 14 | Crop, 15 | Bleed, 16 | Trim, 17 | Art, 18 | Unknown 19 | }; 20 | 21 | public ref class Page sealed : IDisposable, IEquatable { 22 | public: 23 | property int PageNumber { 24 | int get() { return _pageNumber; } 25 | } 26 | 27 | /// 28 | /// Determine the page size in points, taking page rotation into account. The page size is taken to be the crop box if it exists (visible area after cropping), otherwise the media box will be used (possibly including printing marks). 29 | /// 30 | property Box Bound { 31 | Box get() { return pdf_bound_page(Context::Ptr, _pdfPage, FZ_CROP_BOX); } 32 | } 33 | property Box MediaBox { 34 | Box get() { return pdf_dict_get_rect(Context::Ptr, _pdfPage->obj, (pdf_obj*)PdfNames::MediaBox); } 35 | } 36 | property Box CropBox { 37 | Box get() { return pdf_dict_get_rect(Context::Ptr, _pdfPage->obj, (pdf_obj*)PdfNames::CropBox); } 38 | } 39 | property Box ArtBox { 40 | Box get() { return pdf_dict_get_rect(Context::Ptr, _pdfPage->obj, (pdf_obj*)PdfNames::ArtBox); } 41 | } 42 | property Box BleedBox { 43 | Box get() { return pdf_dict_get_rect(Context::Ptr, _pdfPage->obj, (pdf_obj*)PdfNames::BleedBox); } 44 | } 45 | property Box TrimBox { 46 | Box get() { return pdf_dict_get_rect(Context::Ptr, _pdfPage->obj, (pdf_obj*)PdfNames::TrimBox); } 47 | } 48 | property int Rotation { 49 | int get() { 50 | return pdf_dict_get_int(Context::Ptr, PagePtr, PDF_NAME(Rotate)); 51 | } 52 | } 53 | property float UserUnit { 54 | float get() { 55 | return pdf_dict_get_real_default(Context::Ptr, PagePtr, PDF_NAME(UserUnit), 1); 56 | } 57 | } 58 | property bool HasTransparency { 59 | bool get() { return pdf_page_has_transparency(Context::Ptr, _pdfPage); } 60 | } 61 | property int AssociatedFileCount { 62 | int get() { return pdf_count_page_associated_files(Context::Ptr, _pdfPage); } 63 | } 64 | property PdfDictionary^ PdfObject { 65 | PdfDictionary^ get() { 66 | return gcnew PdfDictionary(_pdfPage->obj); 67 | } 68 | } 69 | property PdfDictionary^ Resources { 70 | PdfDictionary^ get() { 71 | auto r = pdf_page_resources(Context::Ptr, _pdfPage); 72 | return r ? gcnew PdfDictionary(r) : nullptr; 73 | } 74 | } 75 | /// 76 | /// Gets the /Contents object, which can be a stream or an array, from the page dictionary 77 | /// 78 | property MuPDF::PdfObject^ Contents { 79 | MuPDF::PdfObject^ get() { 80 | auto c = pdf_page_contents(Context::Ptr, _pdfPage); 81 | return c ? MuPDF::PdfObject::Wrap(c) : nullptr; 82 | } 83 | } 84 | property MuPDF::TextPage^ TextPage { 85 | MuPDF::TextPage^ get() { 86 | return _textPage != nullptr ? _textPage : (_textPage = gcnew MuPDF::TextPage(fz_new_stext_page_from_page(Context::Ptr, _page, NULL))); 87 | } 88 | } 89 | 90 | Box BoundPageBox(PageBoxType boxType) { 91 | return pdf_bound_page(Context::Ptr, _pdfPage, (fz_box_type)boxType); 92 | } 93 | void SetPageBox(PageBoxType boxType, Box box) { 94 | pdf_set_page_box(Context::Ptr, _pdfPage, (fz_box_type)boxType, box); 95 | } 96 | PdfArray^ GetPageBox(PageBoxType boxType); 97 | array^ GetContentBytes() { 98 | auto c = pdf_page_contents(Context::Ptr, _pdfPage); 99 | if (c) { 100 | auto s = gcnew Stream(pdf_open_contents_stream(Context::Ptr, _pdfPage->doc, c)); 101 | return s->ReadAll(); 102 | } 103 | return nullptr; 104 | } 105 | 106 | /// 107 | /// Clip contents, links and annotations within this page. 108 | /// 109 | /// The preserved region within this page. 110 | void Clip(Box box) { 111 | auto r = (fz_rect)box; 112 | pdf_clip_page(Context::Ptr, _pdfPage, &r); 113 | } 114 | 115 | void SyncPage() { 116 | pdf_sync_page(Context::Ptr, _pdfPage); 117 | } 118 | /// 119 | /// Remove cached links and annotations within this page. 120 | /// 121 | void NukePage() { 122 | pdf_nuke_page(Context::Ptr, _pdfPage); 123 | } 124 | void SyncLinks() { 125 | pdf_sync_links(Context::Ptr, _pdfPage); 126 | } 127 | /// 128 | /// Remove cached links within this page. 129 | /// 130 | void NukeLinks() { 131 | pdf_nuke_links(Context::Ptr, _pdfPage); 132 | } 133 | void SyncAnnotations() { 134 | pdf_sync_annots(Context::Ptr, _pdfPage); 135 | } 136 | /// 137 | /// Remove cached annotations within this page. 138 | /// 139 | void NukeAnnotations() { 140 | pdf_nuke_annots(Context::Ptr, _pdfPage); 141 | } 142 | 143 | void Run(Device^ dev, Matrix ctm, Cookie^ cookie); 144 | void Run(Device^ dev, Cookie^ cookie) { 145 | Run(dev, Matrix::Identity, cookie); 146 | } 147 | void RunContents(Device^ dev, Matrix ctm, Cookie^ cookie); 148 | void RunContents(Device^ dev, Cookie^ cookie) { 149 | RunContents(dev, Matrix::Identity, cookie); 150 | } 151 | void RunAnnotations(Device^ dev, Matrix ctm, Cookie^ cookie); 152 | void RunAnnotations(Device^ dev, Cookie^ cookie) { 153 | RunAnnotations(dev, Matrix::Identity, cookie); 154 | } 155 | void RunWidgets(Device^ dev, Matrix ctm, Cookie^ cookie); 156 | void RunWidgets(Device^ dev, Cookie^ cookie) { 157 | RunWidgets(dev, Matrix::Identity, cookie); 158 | } 159 | void FlattenInheritablePageItems() { 160 | pdf_flatten_inheritable_page_items(Context::Ptr, _pdfPage->obj); 161 | } 162 | MuPDF::PdfObject^ GetAssociatedFile(int index) { 163 | return MuPDF::PdfObject::Wrap(pdf_page_associated_file(Context::Ptr, _pdfPage, index)); 164 | } 165 | void RefreshPageCache() { 166 | pdf_sync_page(Context::Ptr, _pdfPage); 167 | RefreshTextPage(); 168 | } 169 | void RefreshTextPage() { 170 | if (_textPage) { 171 | delete _textPage; 172 | _textPage = nullptr; 173 | } 174 | } 175 | 176 | Equatable(Page, _page) 177 | 178 | internal: 179 | Page(fz_page* page, int pageNumber) : _page(page) { 180 | _pdfPage = pdf_page_from_fz_page(Context::Ptr, page); 181 | _pageNumber = pageNumber; 182 | pdf_flatten_inheritable_page_items(Context::Ptr, _pdfPage->obj); 183 | }; 184 | ~Page() { 185 | ReleaseHandle(); 186 | } 187 | property pdf_obj* PagePtr { 188 | pdf_obj* get() { return _pdfPage->obj; } 189 | } 190 | protected: 191 | !Page() { 192 | ReleaseHandle(); 193 | } 194 | private: 195 | fz_page* _page; 196 | pdf_page* _pdfPage; 197 | int _pageNumber; 198 | MuPDF::TextPage^ _textPage; 199 | array^ _contents; 200 | 201 | void ReleaseHandle() { 202 | fz_drop_page(Context::Ptr, _page); 203 | if (_textPage) { 204 | delete _textPage; 205 | _textPage = nullptr; 206 | } 207 | _page = NULL; 208 | _pdfPage = NULL; 209 | } 210 | }; 211 | }; 212 | 213 | #endif // !__PAGE 214 | -------------------------------------------------------------------------------- /MuPDFLib/!Include/PdfObject.h: -------------------------------------------------------------------------------- 1 | #include "mupdf/fitz.h" 2 | #include "mupdf/pdf.h" 3 | #include "Collection.h" 4 | #include "Stream.h" 5 | 6 | #ifndef __PDFOBJECT 7 | #define __PDFOBJECT 8 | 9 | #pragma once 10 | 11 | using namespace System; 12 | using namespace System::Collections::Generic; 13 | using namespace System::Text; 14 | 15 | struct pdf_obj { 16 | short refs; 17 | unsigned char kind; 18 | unsigned char flags; 19 | }; 20 | 21 | 22 | namespace MuPDF { 23 | 24 | public enum class Kind { 25 | Null, 26 | Boolean, 27 | Name, 28 | Integer, 29 | Float, 30 | String, 31 | Array, 32 | Dictionary, 33 | Reference, 34 | Stream, 35 | Unknown 36 | }; 37 | 38 | /// 39 | /// Encapsulates the PDF obj used by MuPDF 40 | /// 41 | public ref class PdfObject : IDisposable, IEquatable { 42 | public: 43 | /// 44 | /// Gets or sets whether this object is dirty (modified). 45 | /// 46 | property bool IsDirty { 47 | bool get() { return pdf_obj_is_dirty(_ctx, _obj); } 48 | void set(bool value) { 49 | if (value) { 50 | pdf_dirty_obj(_ctx, _obj); 51 | } 52 | else { 53 | pdf_clean_obj(_ctx, _obj); 54 | } 55 | } 56 | } 57 | /// 58 | /// Provides direct object kind info. 59 | /// 60 | property Kind TypeKind { 61 | virtual Kind get(); 62 | } 63 | property bool IsIndirect { 64 | bool get() { return pdf_is_indirect(_ctx, _obj); } 65 | } 66 | property bool IsStream { 67 | bool get() { return pdf_is_stream(_ctx, _obj); } 68 | } 69 | property bool IsName { 70 | bool get() { return pdf_is_name(_ctx, _obj); } 71 | } 72 | property bool IsNull { 73 | bool get() { return pdf_is_null(_ctx, _obj); } 74 | } 75 | property bool IsBoolean { 76 | bool get() { return pdf_is_bool(_ctx, _obj); } 77 | } 78 | property bool IsInteger { 79 | bool get() { return pdf_is_int(_ctx, _obj); } 80 | } 81 | property bool IsFloat { 82 | bool get() { return pdf_is_real(_ctx, _obj); } 83 | } 84 | property bool IsNumber { 85 | bool get() { return pdf_is_number(_ctx, _obj); } 86 | } 87 | property bool IsString { 88 | bool get() { return pdf_is_string(_ctx, _obj); } 89 | } 90 | property bool IsArray { 91 | bool get() { return pdf_is_array(_ctx, _obj); } 92 | } 93 | property bool IsDictionary { 94 | bool get() { return pdf_is_dict(_ctx, _obj); } 95 | } 96 | property bool IsPredefined { 97 | bool get() { return _obj < PDF_LIMIT; } 98 | } 99 | property int IntegerValue { 100 | int get() { return pdf_to_int(_ctx, _obj); } 101 | } 102 | property int LongValue { 103 | int get() { return pdf_to_int64(_ctx, _obj); } 104 | } 105 | property float FloatValue { 106 | float get() { return pdf_to_real(_ctx, _obj); } 107 | } 108 | property PdfObject^ UnderlyingObject { 109 | PdfObject^ get() { 110 | return pdf_is_indirect(_ctx, _obj) 111 | ? Wrap(_obj, true) 112 | : this; 113 | } 114 | } 115 | void MarkDirty() { 116 | pdf_dirty_obj(_ctx, _obj); 117 | } 118 | 119 | static bool operator == (PdfObject^ x, PdfObject^ y) { 120 | return Object::ReferenceEquals(x, y) || x && y && pdf_objcmp(x->_ctx, x->Ptr, y->Ptr) == 0; 121 | } 122 | static bool operator != (PdfObject^ x, PdfObject^ y) { 123 | return !Object::ReferenceEquals(x, y) && x && y && pdf_objcmp(x->_ctx, x->Ptr, y->Ptr) != 0; 124 | } 125 | virtual bool Equals(PdfObject^ other); 126 | virtual bool Equals(Object^ obj) override { 127 | PdfObject^ p; 128 | return (p = dynamic_cast(obj)) && _obj == p->_obj; 129 | } 130 | virtual int GetHashCode() override { 131 | #pragma warning(push) 132 | #pragma warning(disable:4302 4311) 133 | return (int)_obj; 134 | #pragma warning(pop) 135 | } 136 | virtual String^ ToString() override { 137 | return TypeKind.ToString(); 138 | } 139 | internal: 140 | PdfObject(pdf_obj* obj) : _obj(obj) { 141 | if (obj >= PDF_LIMIT) { 142 | pdf_keep_obj(_ctx = Context::Ptr, obj); 143 | } 144 | } 145 | ~PdfObject() { 146 | ReleaseHandle(); 147 | } 148 | !PdfObject() { 149 | ReleaseHandle(); 150 | } 151 | property fz_context* Ctx { fz_context* get() { return _ctx; } } 152 | property pdf_obj* Ptr { pdf_obj* get() { return _obj; } } 153 | static PdfObject^ Wrap(pdf_obj* obj, bool resolve); 154 | static PdfObject^ Wrap(pdf_obj* obj) { 155 | return Wrap(obj, false); 156 | } 157 | private: 158 | pdf_obj* _obj; 159 | fz_context* _ctx; 160 | 161 | void ReleaseHandle() { 162 | if (_obj && _ctx) { 163 | pdf_drop_obj(_ctx, _obj); 164 | _obj = NULL; 165 | _ctx = NULL; 166 | } 167 | } 168 | }; 169 | 170 | public ref class PdfNull : PdfObject { 171 | public: 172 | property Kind TypeKind { 173 | virtual Kind get() override { return Kind::Null; } 174 | } 175 | static const PdfNull^ Instance = gcnew PdfNull(); 176 | virtual String^ ToString() override { return ""; } 177 | internal: 178 | PdfNull() : PdfObject(PDF_NULL) {} 179 | }; 180 | 181 | public ref class PdfBoolean : PdfObject { 182 | public: 183 | property Kind TypeKind { 184 | virtual Kind get() override { return Kind::Boolean; } 185 | } 186 | static const PdfBoolean^ True = gcnew PdfBoolean(true); 187 | static const PdfBoolean^ False = gcnew PdfBoolean(false); 188 | property bool Value { 189 | bool get() { return Ptr == PDF_TRUE; } 190 | } 191 | virtual String^ ToString() override { return Ptr == PDF_TRUE ? "" : ""; } 192 | internal: 193 | PdfBoolean(bool value) : PdfObject(value ? PDF_TRUE : PDF_FALSE) {} 194 | }; 195 | 196 | #define PDF_MAKE_NAME(STRING,NAME) NAME, 197 | public enum class PdfNames { 198 | Undefined, 199 | True, 200 | False, 201 | #include "name-table.h" 202 | AllPredefinedNames 203 | }; 204 | 205 | public ref class PdfName : PdfObject { 206 | public: 207 | property Kind TypeKind { 208 | virtual Kind get() override { return Kind::Name; } 209 | } 210 | property String^ Name { 211 | String^ get() { return gcnew String(pdf_to_name(Context::Ptr, Ptr)); } 212 | } 213 | static operator PdfName^(PdfNames value) { 214 | return gcnew PdfName((pdf_obj*)value); 215 | } 216 | virtual String^ ToString() override { return "/" + Name; } 217 | internal: 218 | PdfName(pdf_obj* obj) : PdfObject(obj) {}; 219 | }; 220 | 221 | public ref class PdfInteger : PdfObject { 222 | public: 223 | property Kind TypeKind { 224 | virtual Kind get() override { return Kind::Integer; } 225 | } 226 | property int Value { 227 | int get() { return pdf_to_int(Context::Ptr, Ptr); } 228 | void set(int value) { pdf_set_int(Context::Ptr, Ptr, value); } 229 | } 230 | property long LongValue { 231 | long get() { return pdf_to_int64(Context::Ptr, Ptr); } 232 | void set(long value) { pdf_set_int(Context::Ptr, Ptr, value); } 233 | } 234 | virtual String^ ToString() override { return LongValue.ToString(); } 235 | internal: 236 | PdfInteger(pdf_obj* obj) : PdfObject(obj) {}; 237 | }; 238 | 239 | public ref class PdfFloat : PdfObject { 240 | public: 241 | property Kind TypeKind { 242 | virtual Kind get() override { return Kind::Float; } 243 | } 244 | property float Value { 245 | float get() { return pdf_to_real(Context::Ptr, Ptr); } 246 | } 247 | virtual String^ ToString() override { return Value.ToString(); } 248 | internal: 249 | PdfFloat(pdf_obj* obj) : PdfObject(obj) {}; 250 | }; 251 | 252 | public ref class PdfString : PdfObject { 253 | public: 254 | property Kind TypeKind { 255 | virtual Kind get() override { return Kind::String; } 256 | } 257 | property String^ Value { 258 | String^ get(); 259 | } 260 | property int Length { 261 | int get() { return (int)(pdf_to_str_len(Context::Ptr, Ptr)); } 262 | } 263 | /// 264 | /// Gets underlying bytes in a PDF string. 265 | /// 266 | array^ GetBytes(); 267 | virtual String^ ToString() override { return Value; } 268 | internal: 269 | PdfString(pdf_obj* obj) : PdfObject(obj) {}; 270 | private: 271 | String^ _string; 272 | String^ DecodePdfString(); 273 | }; 274 | 275 | public ref class PdfContainer abstract : PdfObject { 276 | public: 277 | property int Count { 278 | virtual int get() abstract; 279 | } 280 | protected: 281 | pdf_obj* NewPdfString(String^ text); 282 | PdfContainer(pdf_obj* obj) : PdfObject(obj) {}; 283 | private: 284 | static Encoding^ AsciiEncoding = Encoding::ASCII; 285 | }; 286 | 287 | public ref class PdfDictionary : PdfContainer, System::Collections::Generic::IEnumerable>, IIndexableCollection> { 288 | public: 289 | property int Count { 290 | virtual int get() override { return pdf_dict_len(Context::Ptr, Ptr); } 291 | } 292 | property PdfName^ Type { 293 | PdfName^ get() { 294 | auto o = pdf_dict_get(Context::Ptr, Ptr, PDF_NAME(Type)); 295 | return pdf_is_name(Context::Ptr, o) ? gcnew PdfName(o) : nullptr; 296 | } 297 | } 298 | property Kind TypeKind { 299 | virtual Kind get() override { return Kind::Dictionary; } 300 | } 301 | PdfName^ GetKey(int index) { 302 | return gcnew PdfName(pdf_dict_get_key(Context::Ptr, Ptr, index)); 303 | } 304 | PdfObject^ GetValue(int index) { 305 | return PdfObject::Wrap(pdf_dict_get_val(Context::Ptr, Ptr, index)); 306 | } 307 | PdfObject^ GetValue(PdfNames key) { 308 | return PdfObject::Wrap(pdf_dict_get(Context::Ptr, Ptr, (pdf_obj*)key)); 309 | } 310 | PdfObject^ GetValue(PdfNames key, PdfNames abbrev) { 311 | return PdfObject::Wrap(pdf_dict_geta(Context::Ptr, Ptr, (pdf_obj*)key, (pdf_obj*)abbrev)); 312 | } 313 | PdfObject^ InheritableGet(PdfNames key) { 314 | return PdfObject::Wrap(pdf_dict_get_inheritable(Context::Ptr, Ptr, (pdf_obj*)key)); 315 | } 316 | PdfObject^ Locate(... array^ names); 317 | void Set(PdfNames key, PdfNames value) { 318 | pdf_dict_put_drop(Context::Ptr, Ptr, (pdf_obj*)key, (pdf_obj*)value); 319 | } 320 | void Set(PdfNames key, String^ value) { 321 | pdf_dict_put_drop(Context::Ptr, Ptr, (pdf_obj*)key, NewPdfString(value)); 322 | } 323 | void Set(PdfNames key, DateTime dateTime) { 324 | pdf_dict_put_date(Context::Ptr, Ptr, (pdf_obj*)key, dateTime.ToUniversalTime().Subtract(DateTime(1970, 1, 1)).TotalSeconds); 325 | } 326 | void Sort() { 327 | pdf_sort_dict(Context::Ptr, Ptr); 328 | } 329 | bool Remove(PdfNames key) { 330 | int i = pdf_dict_len(Context::Ptr, Ptr); 331 | pdf_dict_del(Context::Ptr, Ptr, (pdf_obj*)key); 332 | return i != pdf_dict_len(Context::Ptr, Ptr); 333 | } 334 | PdfDictionary^ DeepClone() { 335 | return gcnew PdfDictionary(pdf_deep_copy_obj(Context::Ptr, Ptr)); 336 | } 337 | virtual String^ ToString() override { 338 | PdfName^ type = Type; 339 | return type ? String::Concat("{", type->ToString(), "}") : "{}"; 340 | } 341 | virtual System::Collections::Generic::IEnumerator>^ GetEnumerator() sealed = System::Collections::Generic::IEnumerable>::GetEnumerator { 342 | return gcnew IndexableEnumerator>(this); 343 | } 344 | virtual System::Collections::IEnumerator^ GetEnumeratorBase() sealed = 345 | System::Collections::IEnumerable::GetEnumerator { 346 | return GetEnumerator(); 347 | } 348 | internal: 349 | PdfDictionary(pdf_obj* obj) : PdfContainer(obj) {}; 350 | public: 351 | property KeyValuePair default[int] { 352 | virtual KeyValuePair get(int index) { 353 | return KeyValuePair(GetKey(index), GetValue(index)); 354 | }; 355 | } 356 | property PdfObject^ default[PdfNames] { 357 | PdfObject^ get(PdfNames key) { return PdfObject::Wrap(pdf_dict_get(Context::Ptr, Ptr, (pdf_obj*)key)); } 358 | void set(PdfNames key, PdfObject^ value) { pdf_dict_put(Context::Ptr, Ptr, (pdf_obj*)key, value->Ptr); } 359 | } 360 | property PdfObject^ default[PdfName^] { 361 | PdfObject^ get(PdfName^ key) { return PdfObject::Wrap(pdf_dict_get(Context::Ptr, Ptr, key->Ptr)); } 362 | void set(PdfName^ key, PdfObject^ value) { pdf_dict_put(Context::Ptr, Ptr, key->Ptr, value->Ptr); } 363 | } 364 | }; 365 | 366 | public ref class PdfStream : PdfDictionary { 367 | public: 368 | property Kind TypeKind { 369 | virtual Kind get() override { return Kind::Stream; } 370 | } 371 | Stream^ Open() { 372 | return gcnew Stream(pdf_open_stream(Context::Ptr, Ptr)); 373 | } 374 | Stream^ OpenRaw() { 375 | return gcnew Stream(pdf_open_raw_stream(Context::Ptr, Ptr)); 376 | } 377 | array^ GetBytes() { 378 | Stream^ s = Open(); 379 | try { 380 | return s->ReadAll(); 381 | } 382 | finally { 383 | delete s; 384 | } 385 | } 386 | array^ GetRawBytes() { 387 | Stream^ s = OpenRaw(); 388 | try { 389 | return s->ReadAll(); 390 | } 391 | finally { 392 | delete s; 393 | } 394 | } 395 | 396 | /// 397 | /// Replaces bytes in the stream. The data must match /Filter, if is true. 398 | /// 399 | /// The data to be placed into the stream. 400 | /// Whether the data is compressed. If not compressed, /Filter and /DecodeParms will be removed. 401 | void SetBytes(array^ data, bool compress); 402 | ~PdfStream() { 403 | ReleaseHandle(); 404 | } 405 | !PdfStream() { 406 | ReleaseHandle(); 407 | } 408 | internal: 409 | PdfStream(pdf_obj* obj) : PdfDictionary(pdf_resolve_indirect_chain(Context::Ptr, obj)), _obj(obj) { 410 | pdf_keep_obj(_ctx = Context::Ptr, obj); 411 | }; 412 | private: 413 | fz_context* _ctx; 414 | pdf_obj* _obj; 415 | 416 | void ReleaseHandle() { 417 | if (_obj && _ctx) { 418 | pdf_drop_obj(_ctx, _obj); 419 | _obj = NULL; 420 | _ctx = NULL; 421 | } 422 | } 423 | }; 424 | 425 | public ref class PdfDocumentInfo : PdfDictionary { 426 | public: 427 | property String^ Title { 428 | String^ get() { return GetString(PdfNames::Title); } 429 | } 430 | property String^ Subject { 431 | String^ get() { return GetString(PdfNames::Subject); } 432 | } 433 | property String^ Producer { 434 | String^ get() { return GetString(PdfNames::Producer); } 435 | } 436 | property String^ Creator { 437 | String^ get() { return GetString(PdfNames::Creator); } 438 | } 439 | property String^ Author { 440 | String^ get() { return GetString(PdfNames::Author); } 441 | } 442 | property String^ Keywords { 443 | String^ get() { return GetString(PdfNames::Keywords); } 444 | } 445 | property String^ CreationDate { 446 | String^ get() { return GetString(PdfNames::CreationDate); } 447 | } 448 | property String^ ModificationDate { 449 | String^ get() { return GetString(PdfNames::ModDate); } 450 | } 451 | internal: 452 | PdfDocumentInfo(pdf_obj* obj) : PdfDictionary(obj) {}; 453 | private: 454 | String^ GetString(PdfNames key) { 455 | return GetValue(key)->ToString(); 456 | } 457 | }; 458 | 459 | public ref class PdfArray : PdfContainer, System::Collections::Generic::IEnumerable, IIndexableCollection { 460 | public: 461 | property int Count { 462 | virtual int get() override { return pdf_array_len(Context::Ptr, Ptr); } 463 | } 464 | property Kind TypeKind { 465 | virtual Kind get() override { return Kind::Array; } 466 | } 467 | PdfObject^ Get(int index) { 468 | return Wrap(pdf_array_get(Context::Ptr, Ptr, index)); 469 | } 470 | bool Contains(PdfObject^ obj) { 471 | return pdf_array_contains(Context::Ptr, Ptr, obj->Ptr); 472 | } 473 | int IndexOf(PdfObject^ obj) { 474 | return pdf_array_find(Context::Ptr, Ptr, obj->Ptr); 475 | } 476 | void Append(bool value) { 477 | pdf_array_push_bool(Context::Ptr, Ptr, value); 478 | } 479 | void Append(long value) { 480 | pdf_array_push_int(Context::Ptr, Ptr, value); 481 | } 482 | void Append(double value) { 483 | pdf_array_push_real(Context::Ptr, Ptr, value); 484 | } 485 | void Append(PdfNames value) { 486 | pdf_array_push_drop(Context::Ptr, Ptr, (pdf_obj*)value); 487 | } 488 | void Append(String^ value) { 489 | pdf_array_push_drop(Context::Ptr, Ptr, NewPdfString(value)); 490 | } 491 | void Append(PdfObject^ value) { 492 | pdf_array_push_drop(Context::Ptr, Ptr, value->Ptr); 493 | } 494 | void Set(int index, bool value) { 495 | pdf_array_put_bool(Context::Ptr, Ptr, index, value); 496 | } 497 | void Set(int index, long value) { 498 | pdf_array_put_int(Context::Ptr, Ptr, index, value); 499 | } 500 | void Set(int index, double value) { 501 | pdf_array_put_real(Context::Ptr, Ptr, index, value); 502 | } 503 | void Set(int index, PdfNames value) { 504 | pdf_array_put(Context::Ptr, Ptr, index, (pdf_obj*)value); 505 | } 506 | void Set(int index, String^ value) { 507 | pdf_array_put_drop(Context::Ptr, Ptr, index, NewPdfString(value)); 508 | } 509 | void Set(int index, PdfObject^ value) { 510 | pdf_array_put_drop(Context::Ptr, Ptr, index, value->Ptr); 511 | } 512 | void InsertAt(int index, PdfObject^ value) { 513 | pdf_array_insert_drop(Context::Ptr, Ptr, value->Ptr, index); 514 | } 515 | void RemoveAt(int index) { 516 | pdf_array_delete(Context::Ptr, Ptr, index); 517 | } 518 | PdfArray^ DeepClone() { 519 | return gcnew PdfArray(pdf_deep_copy_obj(Context::Ptr, Ptr)); 520 | } 521 | virtual String^ ToString() override { return String::Concat("[", Count.ToString(), "]"); } 522 | virtual System::Collections::Generic::IEnumerator^ GetEnumerator() sealed = System::Collections::Generic::IEnumerable::GetEnumerator{ 523 | return gcnew IndexableEnumerator(this); 524 | } 525 | virtual System::Collections::IEnumerator^ GetEnumeratorBase() sealed = System::Collections::IEnumerable::GetEnumerator { 526 | return GetEnumerator(); 527 | } 528 | internal: 529 | PdfArray(pdf_obj* obj) : PdfContainer(obj) {}; 530 | public: 531 | property PdfObject^ default[int] { 532 | virtual PdfObject^ get(int index) { return Wrap(pdf_array_get(Context::Ptr, Ptr, index)); } 533 | void set(int index, PdfObject^ value) { pdf_array_put_drop(Context::Ptr, Ptr, index, value->Ptr); } 534 | } 535 | }; 536 | 537 | public ref class PdfReference : PdfObject { 538 | public: 539 | property int Number { 540 | int get() { return pdf_to_num(Context::Ptr, Ptr); } 541 | } 542 | property int Generation { 543 | int get() { return pdf_to_gen(Context::Ptr, Ptr); } 544 | } 545 | property Kind TypeKind { 546 | virtual Kind get() override { return Kind::Reference; } 547 | } 548 | PdfObject^ Resolve() { 549 | return Wrap(Ptr, true); 550 | } 551 | virtual String^ ToString() override { 552 | return String::Concat(Number.ToString(), " ", Generation.ToString(), " R"); 553 | } 554 | internal: 555 | PdfReference(pdf_obj* obj) : PdfObject(obj) {}; 556 | }; 557 | 558 | }; 559 | 560 | #endif // !__PDFOBJECT 561 | -------------------------------------------------------------------------------- /MuPDFLib/!Include/Pixmap.h: -------------------------------------------------------------------------------- 1 | #include "mupdf/fitz.h" 2 | #include "mupdf/pdf.h" 3 | #include "MuPDF.h" 4 | 5 | #ifndef __PIXMAP 6 | #define __PIXMAP 7 | 8 | using namespace System; 9 | 10 | #pragma once 11 | 12 | namespace MuPDF { 13 | public ref class Pixmap sealed : IDisposable { 14 | public: 15 | property IntPtr Samples { 16 | IntPtr get() { return _samples; } 17 | } 18 | property int Stride { 19 | int get() { return _stride; } 20 | } 21 | property int Width { 22 | int get() { return _width; } 23 | } 24 | property int Height { 25 | int get() { return _height; } 26 | } 27 | property int Components { 28 | int get() { return _components; } 29 | } 30 | property int Colorants { 31 | int get() { return fz_pixmap_colorants(Context::Ptr, _pixmap); } 32 | } 33 | property MuPDF::BBox BBox { 34 | MuPDF::BBox get() { return fz_pixmap_bbox(Context::Ptr, _pixmap); } 35 | } 36 | /// 37 | /// Return the number of alpha planes in a Pixmap. Does not throw exceptions. 38 | /// 39 | property int Alpha { 40 | int get() { return fz_pixmap_alpha(Context::Ptr, _pixmap); } 41 | } 42 | 43 | static Pixmap^ Create(ColorspaceKind colorspace, int width, int height); 44 | 45 | static Pixmap^ Create(ColorspaceKind colorspace, MuPDF::BBox box); 46 | 47 | void SetBackgroundWhite() { 48 | Clear(0xFF); 49 | } 50 | void Clear(int value) { 51 | fz_clear_pixmap_with_value(Context::Ptr, _pixmap, value); 52 | } 53 | void Invert() { 54 | fz_invert_pixmap(Context::Ptr, _pixmap); 55 | } 56 | bool Tint(int black, int white); 57 | bool Tint(int color) { 58 | return Tint(0, color); 59 | } 60 | void Gamma(float gamma) { 61 | if (gamma == 1.0) { 62 | return; 63 | } 64 | fz_gamma_pixmap(Context::Ptr, _pixmap, gamma); 65 | } 66 | array^ GetSampleBytes() { 67 | if (_samples == IntPtr::Zero) { 68 | return nullptr; 69 | } 70 | GcnewArray(Byte, d, _width * _height * _components); 71 | System::Runtime::InteropServices::Marshal::Copy(_samples, d, 0, d->Length); 72 | return d; 73 | } 74 | internal: 75 | Pixmap(fz_pixmap* pixmap) : _pixmap(pixmap) { 76 | auto ctx = Context::Ptr; 77 | _width = fz_pixmap_width(ctx, pixmap); 78 | _height = fz_pixmap_height(ctx, pixmap); 79 | _components = fz_pixmap_components(ctx, pixmap); 80 | _stride = fz_pixmap_stride(ctx, pixmap); 81 | _samples = (IntPtr)(void*)fz_pixmap_samples(ctx, pixmap); 82 | }; 83 | ~Pixmap() { 84 | ReleaseHandle(); 85 | } 86 | property fz_pixmap* Ptr { 87 | fz_pixmap* get() { return _pixmap; } 88 | } 89 | private: 90 | fz_pixmap* _pixmap; 91 | int _width, _height, _stride, _components; 92 | IntPtr _samples; 93 | 94 | void ReleaseHandle() { 95 | fz_drop_pixmap(Context::Ptr, _pixmap); 96 | _pixmap = NULL; 97 | } 98 | }; 99 | 100 | }; 101 | 102 | #endif 103 | -------------------------------------------------------------------------------- /MuPDFLib/!Include/Stream.h: -------------------------------------------------------------------------------- 1 | #include "mupdf/fitz.h" 2 | #include "mupdf/pdf.h" 3 | #include "MuPDF.h" 4 | 5 | #ifndef __STREAM 6 | #define __STREAM 7 | 8 | #pragma once 9 | using namespace System; 10 | using namespace System::Runtime::InteropServices; 11 | 12 | namespace MuPDF { 13 | 14 | /// 15 | /// Encapsulates the file stream used by MuPDF 16 | /// 17 | public ref class Stream sealed : IDisposable { 18 | public: 19 | Stream(array^ data); 20 | Stream(String^ filePath); 21 | array^ ReadAll(int maxSize); 22 | array^ ReadAll() { 23 | return ReadAll(0x6400000); 24 | } 25 | Stream^ DecodeTiffFax(int width, int height, int k, bool endOfLine, bool encodeByteAlign, bool endOfBlock, bool blackIs1); 26 | internal: 27 | Stream(fz_stream* stream) : _stream(stream), _initDataLength(-1) { 28 | fz_keep_stream(Context::Ptr, stream); 29 | } 30 | ~Stream() { 31 | ReleaseHandle(); 32 | } 33 | property fz_stream* Ptr { 34 | fz_stream* get() { return _stream; } 35 | } 36 | private: 37 | fz_stream* _stream; 38 | GCHandle _data; 39 | int _initDataLength; 40 | 41 | void ReleaseHandle(); 42 | }; 43 | 44 | }; 45 | 46 | #endif -------------------------------------------------------------------------------- /MuPDFLib/!Include/TextPage.h: -------------------------------------------------------------------------------- 1 | #include "mupdf/fitz.h" 2 | #include "mupdf/pdf.h" 3 | #include "MuPDF.h" 4 | 5 | #ifndef __TEXTPAGE 6 | #define __TEXTPAGE 7 | 8 | using namespace System; 9 | using namespace System::Collections; 10 | using namespace System::Text; 11 | 12 | #pragma once 13 | namespace MuPDF { 14 | 15 | [FlagsAttribute()] 16 | public enum class TextOption { 17 | None, 18 | PreserveLigatures = 1, 19 | PreserveWhitespace = 2, 20 | PreserveImages = 4, 21 | InhibitSpaces = 8, 22 | Dehyphenate = 16, 23 | PreserveSpans = 32, 24 | MediaBoxClip = 64, 25 | UseCidForUnknownUnicode = 128, 26 | CollectStructure = 256, 27 | AccurateBBoxes = 512, 28 | CollectVectors = 1024, 29 | IgnoreActualtext = 2048, 30 | Segment = 4096, 31 | ParagraphBreak = 8192, 32 | TableHunt = 16384, 33 | CollectStyles = 32768, 34 | UseGidForUnknownUnicode = 65536, 35 | }; 36 | 37 | [FlagsAttribute] 38 | public enum class FontFlags { 39 | None, 40 | Mono, 41 | Serif = 1 << 1, 42 | Bold = 1 << 2, 43 | Italic = 1 << 3, 44 | UseSubstituteMetrics = 1 << 4, 45 | StretchToMatchPDFMetrics = 1 << 5, 46 | FakeBold = 1 << 6, 47 | FakeItalic = 1 << 7, 48 | HasOpenType = 1 << 8, 49 | InvalidBBox = 1 << 9, 50 | CJK = 1 << 10, 51 | Lang0 = 1 << 11, 52 | Lang1 = 1 << 12, 53 | Embed = 1 << 13, 54 | NeverEmbed = 1 << 14, 55 | }; 56 | 57 | public ref class TextOptions { 58 | public: 59 | TextOption Flags; 60 | /// 61 | /// Defines scale ratio for text rendition. Base resolution is 96 DPI. 62 | /// 63 | float Scale = 1; 64 | 65 | static operator fz_stext_options(TextOptions^ options); 66 | }; 67 | 68 | // in mupdf_load_system_font.c 69 | extern "C" static fz_font* load_windows_font(fz_context* ctx, const char* fontname, int bold, int italic, 70 | int needs_exact_metrics); 71 | extern "C" static void init_system_font_list(void); 72 | 73 | public ref class TextFont : IEquatable { 74 | public: 75 | property String^ Name { 76 | String^ get() { 77 | return _name && _font->name == _namePtr ? _name : (_name = gcnew String(_font->name)); 78 | } 79 | } 80 | property int GlyphCount { 81 | int get() { return _font->glyph_count; } 82 | } 83 | property int WidthCount { 84 | int get() { return _font->width_count; } 85 | } 86 | property short WidthDefault { 87 | short get() { return _font->width_default; } 88 | } 89 | property FontFlags Flags { 90 | FontFlags get() { return (FontFlags)*(int*)&(_font->flags); } 91 | } 92 | array^ GetFontNameBytes() { 93 | GcnewArray(Byte, b, 32); 94 | auto n = _font->name; 95 | System::Runtime::InteropServices::Marshal::Copy((System::IntPtr)(void*)n, b, 0, 32); 96 | return b; 97 | } 98 | array^ GetWidths() { 99 | GcnewArray(short, a, _font->width_count); 100 | System::Runtime::InteropServices::Marshal::Copy((System::IntPtr)(void*)_font->width_table, a, 0, _font->width_count); 101 | return a; 102 | } 103 | int GetCharacter(int cid) { 104 | return ft_char_index(_font->ft_face, cid); 105 | } 106 | /// 107 | /// Find the glyph id for a given unicode character within a font. 108 | /// 109 | /// The unicode character to encode. 110 | /// Returns the glyph id for the given unicode value, or 0 if unknown. 111 | int Encode(int unicode) { 112 | return fz_encode_character(Context::Ptr, _font, unicode); 113 | } 114 | /// 115 | /// Return the advance for a given glyph. 116 | /// 117 | /// The glyph id. 118 | /// True for vertical writing mode, false for horizontal mode. 119 | float Advance(int glyph, bool vertical) { 120 | return fz_advance_glyph(Context::Ptr, _font, glyph, vertical); 121 | } 122 | Equatable(TextFont, _font) 123 | 124 | internal: 125 | TextFont(fz_font* font) : _font(font), _namePtr(font->name) {}; 126 | 127 | private: 128 | fz_font* _font; 129 | String^ _name; 130 | char* _namePtr; 131 | }; 132 | 133 | public ref class TextChar : Generic::IEnumerable, IEquatable { 134 | public: 135 | /// 136 | /// Gets the Unicode code point for this character. 137 | /// 138 | property int Character { 139 | int get() { return _ch->c; } 140 | } 141 | /// 142 | /// Gets the sRGB Hex color (alpha in top 8 bits, then r, then g, then b in low bits). 143 | /// 144 | property int Color { 145 | int get() { return _ch->argb; } 146 | } 147 | property float Size { 148 | float get() { return _ch->size; } 149 | } 150 | /// 151 | /// Gets a pointer to the internal font, for font comparision without creating new TextFont instances. 152 | /// 153 | property IntPtr FontPtr { 154 | IntPtr get() { return (IntPtr)(void*)_ch->font; } 155 | } 156 | property TextChar^ Next { 157 | TextChar^ get() { return _ch->next ? gcnew TextChar(_ch->next) : nullptr; } 158 | } 159 | property Point Origin { 160 | Point get() { return _ch->origin; } 161 | } 162 | property MuPDF::Quad Quad { 163 | MuPDF::Quad get() { return _ch->quad; } 164 | } 165 | property TextFont^ Font { 166 | TextFont^ get() { return _Font ? _Font : gcnew TextFont(_ch->font); } 167 | } 168 | /// 169 | /// Compares whether other TextChar has the same font as the current one. 170 | /// 171 | /// Another TextChar 172 | bool HasSameFont(TextChar^ other) { 173 | return other && _ch->font == other->_ch->font; 174 | } 175 | /// 176 | /// Compares whether other TextChar has the same font, size and color as the current one. 177 | /// 178 | /// Another TextChar 179 | bool HasSameStyle(TextChar^ other) { 180 | return other && _ch->size == other->_ch->size && _ch->argb == other->_ch->argb && _ch->font == other->_ch->font; 181 | } 182 | String^ ToString() override { 183 | return Char::ConvertFromUtf32(_ch->c); 184 | } 185 | static operator Char(TextChar^ ch) { 186 | return ch->_ch->c; 187 | } 188 | internal: 189 | TextChar(fz_stext_char* ch) : _ch(ch) {} 190 | property fz_stext_char* Ptr { 191 | fz_stext_char* get() { return _ch; } 192 | } 193 | private: 194 | fz_stext_char* _ch; 195 | TextFont^ _Font; 196 | 197 | #pragma region IEnumerator 198 | public: 199 | virtual Generic::IEnumerator^ GetEnumerator() sealed = Generic::IEnumerable::GetEnumerator { 200 | return gcnew Enumerator(_ch, _ch->next); 201 | } 202 | 203 | virtual System::Collections::IEnumerator^ GetEnumeratorBase() sealed = System::Collections::IEnumerable::GetEnumerator { 204 | return GetEnumerator(); 205 | } 206 | #pragma endregion 207 | 208 | #pragma region IEquatable 209 | Equatable(TextChar, _ch) 210 | #pragma endregion 211 | 212 | }; 213 | 214 | public ref class TextSpan { 215 | public: 216 | initonly int Color; 217 | initonly float Size; 218 | initonly TextFont^ Font; 219 | initonly Point Origin; 220 | initonly Box Bound; 221 | initonly bool IsVertical; 222 | String^ ToString() override; 223 | internal: 224 | TextSpan(fz_stext_char* ch, int length, Box bound, bool vertical) : _ch(ch), _length(length), Font(gcnew TextFont(ch->font)), Size(ch->size), Color(ch->argb), Origin((Point)ch->origin), Bound(bound), IsVertical(vertical) { } 225 | private: 226 | fz_stext_char* _ch; 227 | int _length; 228 | }; 229 | 230 | public ref class TextLine : Generic::IEnumerable, IEquatable { 231 | public: 232 | property bool IsVertical { 233 | bool get() { return _line->wmode; } 234 | } 235 | property Box Bound { 236 | Box get() { return _line->bbox; } 237 | } 238 | property TextChar^ FirstCharacter { 239 | TextChar^ get() { return gcnew TextChar(_line->first_char); } 240 | } 241 | property TextChar^ LastCharacter { 242 | TextChar^ get() { return gcnew TextChar(_line->last_char); } 243 | } 244 | /// 245 | /// Gets the first font used in TextLine. 246 | /// 247 | property TextFont^ Font { 248 | TextFont^ get() { return gcnew TextFont(_line->first_char->font); } 249 | } 250 | Generic::IEnumerable^ GetSpans() { 251 | return gcnew TextLineSpanContainer(this); 252 | } 253 | String^ ToString() override; 254 | internal: 255 | TextLine(fz_stext_line* line) : _line(line) {} 256 | property fz_stext_line* Ptr { 257 | fz_stext_line* get() { return _line; } 258 | } 259 | private: 260 | fz_stext_line* _line; 261 | ref class TextLineSpanContainer : Generic::IEnumerable, Generic::IEnumerator { 262 | public: 263 | TextLineSpanContainer(TextLine^ line) : _Line(line), _start(_Line->_line->first_char) { } 264 | property TextSpan^ Current { 265 | virtual TextSpan^ get() sealed { return _Current; } 266 | } 267 | property Object^ CurrentBase { 268 | virtual Object^ get() sealed = System::Collections::IEnumerator::Current::get { 269 | return _Current; 270 | } 271 | } 272 | virtual bool MoveNext(); 273 | virtual void Reset() = System::Collections::IEnumerator::Reset; 274 | virtual Generic::IEnumerator^ GetEnumerator() sealed = Generic::IEnumerable::GetEnumerator { 275 | return this; 276 | } 277 | 278 | virtual System::Collections::IEnumerator^ GetEnumeratorBase() sealed = System::Collections::IEnumerable::GetEnumerator{ 279 | return GetEnumerator(); 280 | } 281 | 282 | private: 283 | ~TextLineSpanContainer() {} 284 | TextLine^ _Line; 285 | TextSpan^ _Current; 286 | fz_stext_char* _start; 287 | fz_stext_char* _active; 288 | }; 289 | 290 | #pragma region IEnumerator 291 | public: 292 | virtual Generic::IEnumerator^ GetEnumerator() sealed = Generic::IEnumerable::GetEnumerator { 293 | return gcnew Enumerator(_line->first_char, _line->last_char); 294 | } 295 | 296 | virtual System::Collections::IEnumerator^ GetEnumeratorBase() sealed = System::Collections::IEnumerable::GetEnumerator{ 297 | return GetEnumerator(); 298 | } 299 | #pragma endregion 300 | 301 | #pragma region IEquatable 302 | Equatable(TextLine, _line) 303 | #pragma endregion 304 | 305 | }; 306 | 307 | public enum class BlockType { 308 | Text = 0, 309 | Image = 1, 310 | Struct = 2, 311 | Vector = 3, 312 | Grid = 4 313 | }; 314 | 315 | public ref class TextBlock : Generic::IEnumerable, IEquatable { 316 | public: 317 | property BlockType Type { 318 | BlockType get() { return (BlockType)_block->type; } 319 | } 320 | property Box Bound { 321 | Box get() { return _block->bbox; } 322 | } 323 | virtual String^ ToString() override; 324 | 325 | internal: 326 | TextBlock(fz_stext_block* block) : _block(block) { 327 | } 328 | property fz_stext_block* Ptr { 329 | fz_stext_block* get() { return _block; } 330 | } 331 | private: 332 | fz_stext_block* _block; 333 | 334 | #pragma region IEnumerator 335 | public: 336 | virtual Generic::IEnumerator^ GetEnumerator() sealed = Generic::IEnumerable::GetEnumerator{ 337 | return _block->type == FZ_STEXT_BLOCK_TEXT 338 | ? gcnew Enumerator(_block->u.t.first_line, _block->u.t.last_line) 339 | : EmptyCollection::GetEnumerator(); 340 | } 341 | 342 | virtual System::Collections::IEnumerator^ GetEnumeratorBase() sealed = System::Collections::IEnumerable::GetEnumerator{ 343 | return GetEnumerator(); 344 | } 345 | #pragma endregion 346 | 347 | #pragma region IEquatable 348 | Equatable(TextBlock, _block) 349 | #pragma endregion 350 | 351 | }; 352 | 353 | public ref class TextPage : Generic::IEnumerable { 354 | public: 355 | property Box Bound { 356 | Box get() { return _page->mediabox; } 357 | } 358 | property TextBlock^ FirstBlock { 359 | TextBlock^ get() { return gcnew TextBlock(_page->first_block); } 360 | } 361 | property TextBlock^ LastBlock { 362 | TextBlock^ get() { return gcnew TextBlock(_page->last_block); } 363 | } 364 | String^ ToString() override { 365 | return Bound.ToString(); 366 | } 367 | internal: 368 | TextPage(fz_stext_page* page) : _page(page) {}; 369 | ~TextPage() { 370 | ReleaseHandle(); 371 | } 372 | property fz_stext_page* Ptr { 373 | fz_stext_page* get() { return _page; } 374 | } 375 | private: 376 | fz_stext_page* _page; 377 | 378 | void ReleaseHandle() { 379 | fz_drop_stext_page(Context::Ptr, _page); 380 | _page = NULL; 381 | } 382 | 383 | 384 | public: 385 | virtual Generic::IEnumerator^ GetEnumerator() sealed = Generic::IEnumerable::GetEnumerator { 386 | return gcnew Enumerator(_page->first_block, _page->last_block); 387 | } 388 | 389 | virtual System::Collections::IEnumerator^ GetEnumeratorBase() sealed = System::Collections::IEnumerable::GetEnumerator { 390 | return GetEnumerator(); 391 | } 392 | 393 | }; 394 | 395 | }; 396 | 397 | #endif // !__TEXTPAGE 398 | -------------------------------------------------------------------------------- /MuPDFLib/!Include/name-table.h: -------------------------------------------------------------------------------- 1 | // This file is automatically generated by sync_name_table.py from mupdf/include/mupdf/pdf/name-table.h 2 | 3 | PDF_MAKE_NAME("1.2", _1_2) 4 | PDF_MAKE_NAME("1.5", _1_5) 5 | PDF_MAKE_NAME("3D", _3D) 6 | PDF_MAKE_NAME("A", A) 7 | PDF_MAKE_NAME("A85", A85) 8 | PDF_MAKE_NAME("AA", AA) 9 | PDF_MAKE_NAME("AC", AC) 10 | PDF_MAKE_NAME("AESV2", AESV2) 11 | PDF_MAKE_NAME("AESV3", AESV3) 12 | PDF_MAKE_NAME("AF", AF) 13 | PDF_MAKE_NAME("AFRelationship", AFRelationship) 14 | PDF_MAKE_NAME("AHx", AHx) 15 | PDF_MAKE_NAME("AP", AP) 16 | PDF_MAKE_NAME("AS", AS) 17 | PDF_MAKE_NAME("ASCII85Decode", ASCII85Decode) 18 | PDF_MAKE_NAME("ASCIIHexDecode", ASCIIHexDecode) 19 | PDF_MAKE_NAME("AbsoluteColorimetric", AbsoluteColorimetric) 20 | PDF_MAKE_NAME("AcroForm", AcroForm) 21 | PDF_MAKE_NAME("Action", Action) 22 | PDF_MAKE_NAME("ActualText", ActualText) 23 | PDF_MAKE_NAME("Adobe.PPKLite", Adobe_PPKLite) 24 | PDF_MAKE_NAME("All", All) 25 | PDF_MAKE_NAME("AllOff", AllOff) 26 | PDF_MAKE_NAME("AllOn", AllOn) 27 | PDF_MAKE_NAME("Alpha", Alpha) 28 | PDF_MAKE_NAME("Alt", Alt) 29 | PDF_MAKE_NAME("Alternate", Alternate) 30 | PDF_MAKE_NAME("Alternative", Alternative) 31 | PDF_MAKE_NAME("Annot", Annot) 32 | PDF_MAKE_NAME("Annots", Annots) 33 | PDF_MAKE_NAME("AnyOff", AnyOff) 34 | PDF_MAKE_NAME("App", App) 35 | PDF_MAKE_NAME("Approved", Approved) 36 | PDF_MAKE_NAME("Art", Art) 37 | PDF_MAKE_NAME("ArtBox", ArtBox) 38 | PDF_MAKE_NAME("Artifact", Artifact) 39 | PDF_MAKE_NAME("AsIs", AsIs) 40 | PDF_MAKE_NAME("Ascent", Ascent) 41 | PDF_MAKE_NAME("Aside", Aside) 42 | PDF_MAKE_NAME("AuthEvent", AuthEvent) 43 | PDF_MAKE_NAME("Author", Author) 44 | PDF_MAKE_NAME("B", B) 45 | PDF_MAKE_NAME("BBox", BBox) 46 | PDF_MAKE_NAME("BC", BC) 47 | PDF_MAKE_NAME("BE", BE) 48 | PDF_MAKE_NAME("BG", BG) 49 | PDF_MAKE_NAME("BM", BM) 50 | PDF_MAKE_NAME("BPC", BPC) 51 | PDF_MAKE_NAME("BS", BS) 52 | PDF_MAKE_NAME("Background", Background) 53 | PDF_MAKE_NAME("BaseEncoding", BaseEncoding) 54 | PDF_MAKE_NAME("BaseFont", BaseFont) 55 | PDF_MAKE_NAME("BaseState", BaseState) 56 | PDF_MAKE_NAME("BibEntry", BibEntry) 57 | PDF_MAKE_NAME("BitsPerComponent", BitsPerComponent) 58 | PDF_MAKE_NAME("BitsPerCoordinate", BitsPerCoordinate) 59 | PDF_MAKE_NAME("BitsPerFlag", BitsPerFlag) 60 | PDF_MAKE_NAME("BitsPerSample", BitsPerSample) 61 | PDF_MAKE_NAME("BlackIs1", BlackIs1) 62 | PDF_MAKE_NAME("BlackPoint", BlackPoint) 63 | PDF_MAKE_NAME("BleedBox", BleedBox) 64 | PDF_MAKE_NAME("Blinds", Blinds) 65 | PDF_MAKE_NAME("BlockQuote", BlockQuote) 66 | PDF_MAKE_NAME("Border", Border) 67 | PDF_MAKE_NAME("Bounds", Bounds) 68 | PDF_MAKE_NAME("Box", Box) 69 | PDF_MAKE_NAME("Br", Br) 70 | PDF_MAKE_NAME("BrotliDecode", BrotliDecode) 71 | PDF_MAKE_NAME("Bt", Bt) 72 | PDF_MAKE_NAME("Btn", Btn) 73 | PDF_MAKE_NAME("Butt", Butt) 74 | PDF_MAKE_NAME("ByteRange", ByteRange) 75 | PDF_MAKE_NAME("C", C) 76 | PDF_MAKE_NAME("C0", C0) 77 | PDF_MAKE_NAME("C1", C1) 78 | PDF_MAKE_NAME("CA", CA) 79 | PDF_MAKE_NAME("CCF", CCF) 80 | PDF_MAKE_NAME("CCITTFaxDecode", CCITTFaxDecode) 81 | PDF_MAKE_NAME("CF", CF) 82 | PDF_MAKE_NAME("CFM", CFM) 83 | PDF_MAKE_NAME("CI", CI) 84 | PDF_MAKE_NAME("CIDFontType0", CIDFontType0) 85 | PDF_MAKE_NAME("CIDFontType0C", CIDFontType0C) 86 | PDF_MAKE_NAME("CIDFontType2", CIDFontType2) 87 | PDF_MAKE_NAME("CIDSystemInfo", CIDSystemInfo) 88 | PDF_MAKE_NAME("CIDToGIDMap", CIDToGIDMap) 89 | PDF_MAKE_NAME("CL", CL) 90 | PDF_MAKE_NAME("CMYK", CMYK) 91 | PDF_MAKE_NAME("CO", CO) 92 | PDF_MAKE_NAME("CP", CP) 93 | PDF_MAKE_NAME("CS", CS) 94 | PDF_MAKE_NAME("CalCMYK", CalCMYK) 95 | PDF_MAKE_NAME("CalGray", CalGray) 96 | PDF_MAKE_NAME("CalRGB", CalRGB) 97 | PDF_MAKE_NAME("Cap", Cap) 98 | PDF_MAKE_NAME("CapHeight", CapHeight) 99 | PDF_MAKE_NAME("Caption", Caption) 100 | PDF_MAKE_NAME("Caret", Caret) 101 | PDF_MAKE_NAME("Catalog", Catalog) 102 | PDF_MAKE_NAME("Cert", Cert) 103 | PDF_MAKE_NAME("Ch", Ch) 104 | PDF_MAKE_NAME("Changes", Changes) 105 | PDF_MAKE_NAME("CharProcs", CharProcs) 106 | PDF_MAKE_NAME("CheckSum", CheckSum) 107 | PDF_MAKE_NAME("Circle", Circle) 108 | PDF_MAKE_NAME("ClosedArrow", ClosedArrow) 109 | PDF_MAKE_NAME("Code", Code) 110 | PDF_MAKE_NAME("Collection", Collection) 111 | PDF_MAKE_NAME("ColorSpace", ColorSpace) 112 | PDF_MAKE_NAME("ColorTransform", ColorTransform) 113 | PDF_MAKE_NAME("Colorants", Colorants) 114 | PDF_MAKE_NAME("Colors", Colors) 115 | PDF_MAKE_NAME("Columns", Columns) 116 | PDF_MAKE_NAME("Confidential", Confidential) 117 | PDF_MAKE_NAME("Configs", Configs) 118 | PDF_MAKE_NAME("ContactInfo", ContactInfo) 119 | PDF_MAKE_NAME("Contents", Contents) 120 | PDF_MAKE_NAME("Coords", Coords) 121 | PDF_MAKE_NAME("Count", Count) 122 | PDF_MAKE_NAME("Cover", Cover) 123 | PDF_MAKE_NAME("CreationDate", CreationDate) 124 | PDF_MAKE_NAME("Creator", Creator) 125 | PDF_MAKE_NAME("CropBox", CropBox) 126 | PDF_MAKE_NAME("Crypt", Crypt) 127 | PDF_MAKE_NAME("D", D) 128 | PDF_MAKE_NAME("DA", DA) 129 | PDF_MAKE_NAME("DC", DC) 130 | PDF_MAKE_NAME("DCT", DCT) 131 | PDF_MAKE_NAME("DCTDecode", DCTDecode) 132 | PDF_MAKE_NAME("DL", DL) 133 | PDF_MAKE_NAME("DOS", DOS) 134 | PDF_MAKE_NAME("DP", DP) 135 | PDF_MAKE_NAME("DR", DR) 136 | PDF_MAKE_NAME("DS", DS) 137 | PDF_MAKE_NAME("DV", DV) 138 | PDF_MAKE_NAME("DW", DW) 139 | PDF_MAKE_NAME("DW2", DW2) 140 | PDF_MAKE_NAME("DamagedRowsBeforeError", DamagedRowsBeforeError) 141 | PDF_MAKE_NAME("Data", Data) 142 | PDF_MAKE_NAME("Date", Date) 143 | PDF_MAKE_NAME("Decode", Decode) 144 | PDF_MAKE_NAME("DecodeParms", DecodeParms) 145 | PDF_MAKE_NAME("Default", Default) 146 | PDF_MAKE_NAME("DefaultCMYK", DefaultCMYK) 147 | PDF_MAKE_NAME("DefaultGray", DefaultGray) 148 | PDF_MAKE_NAME("DefaultRGB", DefaultRGB) 149 | PDF_MAKE_NAME("Departmental", Departmental) 150 | PDF_MAKE_NAME("Desc", Desc) 151 | PDF_MAKE_NAME("DescendantFonts", DescendantFonts) 152 | PDF_MAKE_NAME("Descent", Descent) 153 | PDF_MAKE_NAME("Design", Design) 154 | PDF_MAKE_NAME("Dest", Dest) 155 | PDF_MAKE_NAME("DestOutputProfile", DestOutputProfile) 156 | PDF_MAKE_NAME("Dests", Dests) 157 | PDF_MAKE_NAME("DeviceCMYK", DeviceCMYK) 158 | PDF_MAKE_NAME("DeviceGray", DeviceGray) 159 | PDF_MAKE_NAME("DeviceN", DeviceN) 160 | PDF_MAKE_NAME("DeviceRGB", DeviceRGB) 161 | PDF_MAKE_NAME("Di", Di) 162 | PDF_MAKE_NAME("Diamond", Diamond) 163 | PDF_MAKE_NAME("Differences", Differences) 164 | PDF_MAKE_NAME("DigestLocation", DigestLocation) 165 | PDF_MAKE_NAME("DigestMethod", DigestMethod) 166 | PDF_MAKE_NAME("DigestValue", DigestValue) 167 | PDF_MAKE_NAME("Dissolve", Dissolve) 168 | PDF_MAKE_NAME("Div", Div) 169 | PDF_MAKE_NAME("Dm", Dm) 170 | PDF_MAKE_NAME("DocMDP", DocMDP) 171 | PDF_MAKE_NAME("Document", Document) 172 | PDF_MAKE_NAME("DocumentFragment", DocumentFragment) 173 | PDF_MAKE_NAME("Domain", Domain) 174 | PDF_MAKE_NAME("Draft", Draft) 175 | PDF_MAKE_NAME("Dur", Dur) 176 | PDF_MAKE_NAME("E", E) 177 | PDF_MAKE_NAME("EF", EF) 178 | PDF_MAKE_NAME("EarlyChange", EarlyChange) 179 | PDF_MAKE_NAME("Em", Em) 180 | PDF_MAKE_NAME("EmbeddedFile", EmbeddedFile) 181 | PDF_MAKE_NAME("EmbeddedFiles", EmbeddedFiles) 182 | PDF_MAKE_NAME("Encode", Encode) 183 | PDF_MAKE_NAME("EncodedByteAlign", EncodedByteAlign) 184 | PDF_MAKE_NAME("Encoding", Encoding) 185 | PDF_MAKE_NAME("Encrypt", Encrypt) 186 | PDF_MAKE_NAME("EncryptMetadata", EncryptMetadata) 187 | PDF_MAKE_NAME("EncryptedPayload", EncryptedPayload) 188 | PDF_MAKE_NAME("EndOfBlock", EndOfBlock) 189 | PDF_MAKE_NAME("EndOfLine", EndOfLine) 190 | PDF_MAKE_NAME("Exclude", Exclude) 191 | PDF_MAKE_NAME("Experimental", Experimental) 192 | PDF_MAKE_NAME("Expired", Expired) 193 | PDF_MAKE_NAME("ExtGState", ExtGState) 194 | PDF_MAKE_NAME("Extend", Extend) 195 | PDF_MAKE_NAME("F", F) 196 | PDF_MAKE_NAME("FENote", FENote) 197 | PDF_MAKE_NAME("FL", FL) 198 | PDF_MAKE_NAME("FRM", FRM) 199 | PDF_MAKE_NAME("FS", FS) 200 | PDF_MAKE_NAME("FT", FT) 201 | PDF_MAKE_NAME("Fade", Fade) 202 | PDF_MAKE_NAME("Ff", Ff) 203 | PDF_MAKE_NAME("FieldMDP", FieldMDP) 204 | PDF_MAKE_NAME("Fields", Fields) 205 | PDF_MAKE_NAME("Figure", Figure) 206 | PDF_MAKE_NAME("FileAttachment", FileAttachment) 207 | PDF_MAKE_NAME("FileSize", FileSize) 208 | PDF_MAKE_NAME("Filespec", Filespec) 209 | PDF_MAKE_NAME("Filter", Filter) 210 | PDF_MAKE_NAME("Final", Final) 211 | PDF_MAKE_NAME("Fingerprint", Fingerprint) 212 | PDF_MAKE_NAME("First", First) 213 | PDF_MAKE_NAME("FirstChar", FirstChar) 214 | PDF_MAKE_NAME("FirstPage", FirstPage) 215 | PDF_MAKE_NAME("Fit", Fit) 216 | PDF_MAKE_NAME("FitB", FitB) 217 | PDF_MAKE_NAME("FitBH", FitBH) 218 | PDF_MAKE_NAME("FitBV", FitBV) 219 | PDF_MAKE_NAME("FitH", FitH) 220 | PDF_MAKE_NAME("FitR", FitR) 221 | PDF_MAKE_NAME("FitV", FitV) 222 | PDF_MAKE_NAME("Fl", Fl) 223 | PDF_MAKE_NAME("Flags", Flags) 224 | PDF_MAKE_NAME("FlateDecode", FlateDecode) 225 | PDF_MAKE_NAME("Fly", Fly) 226 | PDF_MAKE_NAME("Font", Font) 227 | PDF_MAKE_NAME("FontBBox", FontBBox) 228 | PDF_MAKE_NAME("FontDescriptor", FontDescriptor) 229 | PDF_MAKE_NAME("FontFile", FontFile) 230 | PDF_MAKE_NAME("FontFile2", FontFile2) 231 | PDF_MAKE_NAME("FontFile3", FontFile3) 232 | PDF_MAKE_NAME("FontMatrix", FontMatrix) 233 | PDF_MAKE_NAME("FontName", FontName) 234 | PDF_MAKE_NAME("ForComment", ForComment) 235 | PDF_MAKE_NAME("ForPublicRelease", ForPublicRelease) 236 | PDF_MAKE_NAME("Form", Form) 237 | PDF_MAKE_NAME("FormData", FormData) 238 | PDF_MAKE_NAME("FormEx", FormEx) 239 | PDF_MAKE_NAME("FormType", FormType) 240 | PDF_MAKE_NAME("Formula", Formula) 241 | PDF_MAKE_NAME("FreeText", FreeText) 242 | PDF_MAKE_NAME("FreeTextCallout", FreeTextCallout) 243 | PDF_MAKE_NAME("FreeTextTypeWriter", FreeTextTypeWriter) 244 | PDF_MAKE_NAME("Function", Function) 245 | PDF_MAKE_NAME("FunctionType", FunctionType) 246 | PDF_MAKE_NAME("Functions", Functions) 247 | PDF_MAKE_NAME("G", G) 248 | PDF_MAKE_NAME("GTS_PDFX", GTS_PDFX) 249 | PDF_MAKE_NAME("Gamma", Gamma) 250 | PDF_MAKE_NAME("Glitter", Glitter) 251 | PDF_MAKE_NAME("GoTo", GoTo) 252 | PDF_MAKE_NAME("GoToR", GoToR) 253 | PDF_MAKE_NAME("Group", Group) 254 | PDF_MAKE_NAME("H", H) 255 | PDF_MAKE_NAME("H1", H1) 256 | PDF_MAKE_NAME("H2", H2) 257 | PDF_MAKE_NAME("H3", H3) 258 | PDF_MAKE_NAME("H4", H4) 259 | PDF_MAKE_NAME("H5", H5) 260 | PDF_MAKE_NAME("H6", H6) 261 | PDF_MAKE_NAME("Height", Height) 262 | PDF_MAKE_NAME("Helv", Helv) 263 | PDF_MAKE_NAME("Highlight", Highlight) 264 | PDF_MAKE_NAME("HistoryPos", HistoryPos) 265 | PDF_MAKE_NAME("I", I) 266 | PDF_MAKE_NAME("IC", IC) 267 | PDF_MAKE_NAME("ICCBased", ICCBased) 268 | PDF_MAKE_NAME("ID", ID) 269 | PDF_MAKE_NAME("IM", IM) 270 | PDF_MAKE_NAME("IRT", IRT) 271 | PDF_MAKE_NAME("IT", IT) 272 | PDF_MAKE_NAME("Identity", Identity) 273 | PDF_MAKE_NAME("Identity-H", Identity_H) 274 | PDF_MAKE_NAME("Identity-V", Identity_V) 275 | PDF_MAKE_NAME("Image", Image) 276 | PDF_MAKE_NAME("ImageB", ImageB) 277 | PDF_MAKE_NAME("ImageC", ImageC) 278 | PDF_MAKE_NAME("ImageI", ImageI) 279 | PDF_MAKE_NAME("ImageMask", ImageMask) 280 | PDF_MAKE_NAME("Include", Include) 281 | PDF_MAKE_NAME("Index", Index) 282 | PDF_MAKE_NAME("Indexed", Indexed) 283 | PDF_MAKE_NAME("Info", Info) 284 | PDF_MAKE_NAME("Ink", Ink) 285 | PDF_MAKE_NAME("InkList", InkList) 286 | PDF_MAKE_NAME("Intent", Intent) 287 | PDF_MAKE_NAME("Interpolate", Interpolate) 288 | PDF_MAKE_NAME("IsMap", IsMap) 289 | PDF_MAKE_NAME("ItalicAngle", ItalicAngle) 290 | PDF_MAKE_NAME("JBIG2Decode", JBIG2Decode) 291 | PDF_MAKE_NAME("JBIG2Globals", JBIG2Globals) 292 | PDF_MAKE_NAME("JPXDecode", JPXDecode) 293 | PDF_MAKE_NAME("JS", JS) 294 | PDF_MAKE_NAME("JavaScript", JavaScript) 295 | PDF_MAKE_NAME("K", K) 296 | PDF_MAKE_NAME("Keywords", Keywords) 297 | PDF_MAKE_NAME("Kids", Kids) 298 | PDF_MAKE_NAME("L", L) 299 | PDF_MAKE_NAME("LBody", LBody) 300 | PDF_MAKE_NAME("LC", LC) 301 | PDF_MAKE_NAME("LE", LE) 302 | PDF_MAKE_NAME("LI", LI) 303 | PDF_MAKE_NAME("LJ", LJ) 304 | PDF_MAKE_NAME("LL", LL) 305 | PDF_MAKE_NAME("LLE", LLE) 306 | PDF_MAKE_NAME("LLO", LLO) 307 | PDF_MAKE_NAME("LW", LW) 308 | PDF_MAKE_NAME("LZ", LZ) 309 | PDF_MAKE_NAME("LZW", LZW) 310 | PDF_MAKE_NAME("LZWDecode", LZWDecode) 311 | PDF_MAKE_NAME("Lab", Lab) 312 | PDF_MAKE_NAME("Label", Label) 313 | PDF_MAKE_NAME("Lang", Lang) 314 | PDF_MAKE_NAME("Last", Last) 315 | PDF_MAKE_NAME("LastChar", LastChar) 316 | PDF_MAKE_NAME("LastPage", LastPage) 317 | PDF_MAKE_NAME("Launch", Launch) 318 | PDF_MAKE_NAME("Layer", Layer) 319 | PDF_MAKE_NAME("Lbl", Lbl) 320 | PDF_MAKE_NAME("Length", Length) 321 | PDF_MAKE_NAME("Length1", Length1) 322 | PDF_MAKE_NAME("Length2", Length2) 323 | PDF_MAKE_NAME("Length3", Length3) 324 | PDF_MAKE_NAME("Limits", Limits) 325 | PDF_MAKE_NAME("Line", Line) 326 | PDF_MAKE_NAME("LineArrow", LineArrow) 327 | PDF_MAKE_NAME("LineDimension", LineDimension) 328 | PDF_MAKE_NAME("Linearized", Linearized) 329 | PDF_MAKE_NAME("Link", Link) 330 | PDF_MAKE_NAME("List", List) 331 | PDF_MAKE_NAME("Location", Location) 332 | PDF_MAKE_NAME("Lock", Lock) 333 | PDF_MAKE_NAME("Locked", Locked) 334 | PDF_MAKE_NAME("Luminosity", Luminosity) 335 | PDF_MAKE_NAME("M", M) 336 | PDF_MAKE_NAME("MCID", MCID) 337 | PDF_MAKE_NAME("MK", MK) 338 | PDF_MAKE_NAME("ML", ML) 339 | PDF_MAKE_NAME("MMType1", MMType1) 340 | PDF_MAKE_NAME("Mac", Mac) 341 | PDF_MAKE_NAME("Mask", Mask) 342 | PDF_MAKE_NAME("Matrix", Matrix) 343 | PDF_MAKE_NAME("Matte", Matte) 344 | PDF_MAKE_NAME("MaxLen", MaxLen) 345 | PDF_MAKE_NAME("MediaBox", MediaBox) 346 | PDF_MAKE_NAME("Metadata", Metadata) 347 | PDF_MAKE_NAME("MissingWidth", MissingWidth) 348 | PDF_MAKE_NAME("ModDate", ModDate) 349 | PDF_MAKE_NAME("Movie", Movie) 350 | PDF_MAKE_NAME("Msg", Msg) 351 | PDF_MAKE_NAME("Multiply", Multiply) 352 | PDF_MAKE_NAME("N", N) 353 | PDF_MAKE_NAME("Name", Name) 354 | PDF_MAKE_NAME("Named", Named) 355 | PDF_MAKE_NAME("Names", Names) 356 | PDF_MAKE_NAME("NewWindow", NewWindow) 357 | PDF_MAKE_NAME("Next", Next) 358 | PDF_MAKE_NAME("NextPage", NextPage) 359 | PDF_MAKE_NAME("NonEFontNoWarn", NonEFontNoWarn) 360 | PDF_MAKE_NAME("NonStruct", NonStruct) 361 | PDF_MAKE_NAME("None", None) 362 | PDF_MAKE_NAME("Normal", Normal) 363 | PDF_MAKE_NAME("NotApproved", NotApproved) 364 | PDF_MAKE_NAME("NotForPublicRelease", NotForPublicRelease) 365 | PDF_MAKE_NAME("Note", Note) 366 | PDF_MAKE_NAME("NumSections", NumSections) 367 | PDF_MAKE_NAME("Nums", Nums) 368 | PDF_MAKE_NAME("O", O) 369 | PDF_MAKE_NAME("OC", OC) 370 | PDF_MAKE_NAME("OCG", OCG) 371 | PDF_MAKE_NAME("OCGs", OCGs) 372 | PDF_MAKE_NAME("OCMD", OCMD) 373 | PDF_MAKE_NAME("OCProperties", OCProperties) 374 | PDF_MAKE_NAME("OE", OE) 375 | PDF_MAKE_NAME("OFF", OFF) 376 | PDF_MAKE_NAME("ON", ON) 377 | PDF_MAKE_NAME("OP", OP) 378 | PDF_MAKE_NAME("OPM", OPM) 379 | PDF_MAKE_NAME("OS", OS) 380 | PDF_MAKE_NAME("ObjStm", ObjStm) 381 | PDF_MAKE_NAME("Of", Of) 382 | PDF_MAKE_NAME("Off", Off) 383 | PDF_MAKE_NAME("Open", Open) 384 | PDF_MAKE_NAME("OpenArrow", OpenArrow) 385 | PDF_MAKE_NAME("OpenType", OpenType) 386 | PDF_MAKE_NAME("Opt", Opt) 387 | PDF_MAKE_NAME("Order", Order) 388 | PDF_MAKE_NAME("Ordering", Ordering) 389 | PDF_MAKE_NAME("Outlines", Outlines) 390 | PDF_MAKE_NAME("OutputCondition", OutputCondition) 391 | PDF_MAKE_NAME("OutputConditionIdentifier", OutputConditionIdentifier) 392 | PDF_MAKE_NAME("OutputIntent", OutputIntent) 393 | PDF_MAKE_NAME("OutputIntents", OutputIntents) 394 | PDF_MAKE_NAME("P", P) 395 | PDF_MAKE_NAME("PDF", PDF) 396 | PDF_MAKE_NAME("PS", PS) 397 | PDF_MAKE_NAME("Page", Page) 398 | PDF_MAKE_NAME("PageLabels", PageLabels) 399 | PDF_MAKE_NAME("PageMode", PageMode) 400 | PDF_MAKE_NAME("Pages", Pages) 401 | PDF_MAKE_NAME("PaintType", PaintType) 402 | PDF_MAKE_NAME("Params", Params) 403 | PDF_MAKE_NAME("Parent", Parent) 404 | PDF_MAKE_NAME("ParentTree", ParentTree) 405 | PDF_MAKE_NAME("Part", Part) 406 | PDF_MAKE_NAME("Pattern", Pattern) 407 | PDF_MAKE_NAME("PatternType", PatternType) 408 | PDF_MAKE_NAME("Perceptual", Perceptual) 409 | PDF_MAKE_NAME("Perms", Perms) 410 | PDF_MAKE_NAME("PieceInfo", PieceInfo) 411 | PDF_MAKE_NAME("PolyLine", PolyLine) 412 | PDF_MAKE_NAME("PolyLineDimension", PolyLineDimension) 413 | PDF_MAKE_NAME("Polygon", Polygon) 414 | PDF_MAKE_NAME("PolygonCloud", PolygonCloud) 415 | PDF_MAKE_NAME("PolygonDimension", PolygonDimension) 416 | PDF_MAKE_NAME("Popup", Popup) 417 | PDF_MAKE_NAME("PreRelease", PreRelease) 418 | PDF_MAKE_NAME("Predictor", Predictor) 419 | PDF_MAKE_NAME("Prev", Prev) 420 | PDF_MAKE_NAME("PrevPage", PrevPage) 421 | PDF_MAKE_NAME("Preview", Preview) 422 | PDF_MAKE_NAME("Print", Print) 423 | PDF_MAKE_NAME("PrinterMark", PrinterMark) 424 | PDF_MAKE_NAME("Private", Private) 425 | PDF_MAKE_NAME("ProcSet", ProcSet) 426 | PDF_MAKE_NAME("Producer", Producer) 427 | PDF_MAKE_NAME("Prop_AuthTime", Prop_AuthTime) 428 | PDF_MAKE_NAME("Prop_AuthType", Prop_AuthType) 429 | PDF_MAKE_NAME("Prop_Build", Prop_Build) 430 | PDF_MAKE_NAME("Properties", Properties) 431 | PDF_MAKE_NAME("PubSec", PubSec) 432 | PDF_MAKE_NAME("Push", Push) 433 | PDF_MAKE_NAME("Q", Q) 434 | PDF_MAKE_NAME("QuadPoints", QuadPoints) 435 | PDF_MAKE_NAME("Quote", Quote) 436 | PDF_MAKE_NAME("R", R) 437 | PDF_MAKE_NAME("RB", RB) 438 | PDF_MAKE_NAME("RBGroups", RBGroups) 439 | PDF_MAKE_NAME("RC", RC) 440 | PDF_MAKE_NAME("RClosedArrow", RClosedArrow) 441 | PDF_MAKE_NAME("RD", RD) 442 | PDF_MAKE_NAME("REx", REx) 443 | PDF_MAKE_NAME("RGB", RGB) 444 | PDF_MAKE_NAME("RI", RI) 445 | PDF_MAKE_NAME("RL", RL) 446 | PDF_MAKE_NAME("ROpenArrow", ROpenArrow) 447 | PDF_MAKE_NAME("RP", RP) 448 | PDF_MAKE_NAME("RT", RT) 449 | PDF_MAKE_NAME("RV", RV) 450 | PDF_MAKE_NAME("Range", Range) 451 | PDF_MAKE_NAME("Reason", Reason) 452 | PDF_MAKE_NAME("Rect", Rect) 453 | PDF_MAKE_NAME("Redact", Redact) 454 | PDF_MAKE_NAME("Ref", Ref) 455 | PDF_MAKE_NAME("Reference", Reference) 456 | PDF_MAKE_NAME("Registry", Registry) 457 | PDF_MAKE_NAME("RelativeColorimetric", RelativeColorimetric) 458 | PDF_MAKE_NAME("ResetForm", ResetForm) 459 | PDF_MAKE_NAME("Resources", Resources) 460 | PDF_MAKE_NAME("RoleMap", RoleMap) 461 | PDF_MAKE_NAME("Root", Root) 462 | PDF_MAKE_NAME("Rotate", Rotate) 463 | PDF_MAKE_NAME("Rows", Rows) 464 | PDF_MAKE_NAME("Ruby", Ruby) 465 | PDF_MAKE_NAME("RunLengthDecode", RunLengthDecode) 466 | PDF_MAKE_NAME("S", S) 467 | PDF_MAKE_NAME("SMask", SMask) 468 | PDF_MAKE_NAME("SMaskInData", SMaskInData) 469 | PDF_MAKE_NAME("Saturation", Saturation) 470 | PDF_MAKE_NAME("Schema", Schema) 471 | PDF_MAKE_NAME("Screen", Screen) 472 | PDF_MAKE_NAME("Sect", Sect) 473 | PDF_MAKE_NAME("Separation", Separation) 474 | PDF_MAKE_NAME("Shading", Shading) 475 | PDF_MAKE_NAME("ShadingType", ShadingType) 476 | PDF_MAKE_NAME("Si", Si) 477 | PDF_MAKE_NAME("Sig", Sig) 478 | PDF_MAKE_NAME("SigFlags", SigFlags) 479 | PDF_MAKE_NAME("SigQ", SigQ) 480 | PDF_MAKE_NAME("SigRef", SigRef) 481 | PDF_MAKE_NAME("Size", Size) 482 | PDF_MAKE_NAME("Slash", Slash) 483 | PDF_MAKE_NAME("Sold", Sold) 484 | PDF_MAKE_NAME("Sound", Sound) 485 | PDF_MAKE_NAME("Source", Source) 486 | PDF_MAKE_NAME("Span", Span) 487 | PDF_MAKE_NAME("Split", Split) 488 | PDF_MAKE_NAME("Square", Square) 489 | PDF_MAKE_NAME("Squiggly", Squiggly) 490 | PDF_MAKE_NAME("St", St) 491 | PDF_MAKE_NAME("Stamp", Stamp) 492 | PDF_MAKE_NAME("StampImage", StampImage) 493 | PDF_MAKE_NAME("StampSnapshot", StampSnapshot) 494 | PDF_MAKE_NAME("Standard", Standard) 495 | PDF_MAKE_NAME("StdCF", StdCF) 496 | PDF_MAKE_NAME("StemV", StemV) 497 | PDF_MAKE_NAME("StmF", StmF) 498 | PDF_MAKE_NAME("StrF", StrF) 499 | PDF_MAKE_NAME("StrikeOut", StrikeOut) 500 | PDF_MAKE_NAME("Strong", Strong) 501 | PDF_MAKE_NAME("StructParent", StructParent) 502 | PDF_MAKE_NAME("StructParents", StructParents) 503 | PDF_MAKE_NAME("StructTreeRoot", StructTreeRoot) 504 | PDF_MAKE_NAME("Sub", Sub) 505 | PDF_MAKE_NAME("SubFilter", SubFilter) 506 | PDF_MAKE_NAME("Subject", Subject) 507 | PDF_MAKE_NAME("Subtype", Subtype) 508 | PDF_MAKE_NAME("Subtype2", Subtype2) 509 | PDF_MAKE_NAME("Supplement", Supplement) 510 | PDF_MAKE_NAME("Symb", Symb) 511 | PDF_MAKE_NAME("T", T) 512 | PDF_MAKE_NAME("TBody", TBody) 513 | PDF_MAKE_NAME("TD", TD) 514 | PDF_MAKE_NAME("TFoot", TFoot) 515 | PDF_MAKE_NAME("TH", TH) 516 | PDF_MAKE_NAME("THead", THead) 517 | PDF_MAKE_NAME("TI", TI) 518 | PDF_MAKE_NAME("TOC", TOC) 519 | PDF_MAKE_NAME("TOCI", TOCI) 520 | PDF_MAKE_NAME("TR", TR) 521 | PDF_MAKE_NAME("TR2", TR2) 522 | PDF_MAKE_NAME("TU", TU) 523 | PDF_MAKE_NAME("Table", Table) 524 | PDF_MAKE_NAME("Text", Text) 525 | PDF_MAKE_NAME("Thumb", Thumb) 526 | PDF_MAKE_NAME("TilingType", TilingType) 527 | PDF_MAKE_NAME("Times", Times) 528 | PDF_MAKE_NAME("Title", Title) 529 | PDF_MAKE_NAME("ToUnicode", ToUnicode) 530 | PDF_MAKE_NAME("Top", Top) 531 | PDF_MAKE_NAME("TopSecret", TopSecret) 532 | PDF_MAKE_NAME("Trans", Trans) 533 | PDF_MAKE_NAME("TransformMethod", TransformMethod) 534 | PDF_MAKE_NAME("TransformParams", TransformParams) 535 | PDF_MAKE_NAME("Transparency", Transparency) 536 | PDF_MAKE_NAME("TrapNet", TrapNet) 537 | PDF_MAKE_NAME("TrimBox", TrimBox) 538 | PDF_MAKE_NAME("TrueType", TrueType) 539 | PDF_MAKE_NAME("TrustedMode", TrustedMode) 540 | PDF_MAKE_NAME("Tx", Tx) 541 | PDF_MAKE_NAME("Type", Type) 542 | PDF_MAKE_NAME("Type0", Type0) 543 | PDF_MAKE_NAME("Type1", Type1) 544 | PDF_MAKE_NAME("Type1C", Type1C) 545 | PDF_MAKE_NAME("Type3", Type3) 546 | PDF_MAKE_NAME("U", U) 547 | PDF_MAKE_NAME("UE", UE) 548 | PDF_MAKE_NAME("UF", UF) 549 | PDF_MAKE_NAME("URI", URI) 550 | PDF_MAKE_NAME("URL", URL) 551 | PDF_MAKE_NAME("Unchanged", Unchanged) 552 | PDF_MAKE_NAME("Uncover", Uncover) 553 | PDF_MAKE_NAME("Underline", Underline) 554 | PDF_MAKE_NAME("Unix", Unix) 555 | PDF_MAKE_NAME("Unspecified", Unspecified) 556 | PDF_MAKE_NAME("Usage", Usage) 557 | PDF_MAKE_NAME("UseBlackPtComp", UseBlackPtComp) 558 | PDF_MAKE_NAME("UseCMap", UseCMap) 559 | PDF_MAKE_NAME("UseOutlines", UseOutlines) 560 | PDF_MAKE_NAME("UserUnit", UserUnit) 561 | PDF_MAKE_NAME("V", V) 562 | PDF_MAKE_NAME("V2", V2) 563 | PDF_MAKE_NAME("VE", VE) 564 | PDF_MAKE_NAME("Version", Version) 565 | PDF_MAKE_NAME("Vertices", Vertices) 566 | PDF_MAKE_NAME("VerticesPerRow", VerticesPerRow) 567 | PDF_MAKE_NAME("View", View) 568 | PDF_MAKE_NAME("W", W) 569 | PDF_MAKE_NAME("W2", W2) 570 | PDF_MAKE_NAME("WMode", WMode) 571 | PDF_MAKE_NAME("WP", WP) 572 | PDF_MAKE_NAME("WT", WT) 573 | PDF_MAKE_NAME("Warichu", Warichu) 574 | PDF_MAKE_NAME("Watermark", Watermark) 575 | PDF_MAKE_NAME("WhitePoint", WhitePoint) 576 | PDF_MAKE_NAME("Widget", Widget) 577 | PDF_MAKE_NAME("Width", Width) 578 | PDF_MAKE_NAME("Widths", Widths) 579 | PDF_MAKE_NAME("WinAnsiEncoding", WinAnsiEncoding) 580 | PDF_MAKE_NAME("Wipe", Wipe) 581 | PDF_MAKE_NAME("XFA", XFA) 582 | PDF_MAKE_NAME("XHeight", XHeight) 583 | PDF_MAKE_NAME("XML", XML) 584 | PDF_MAKE_NAME("XObject", XObject) 585 | PDF_MAKE_NAME("XRef", XRef) 586 | PDF_MAKE_NAME("XRefStm", XRefStm) 587 | PDF_MAKE_NAME("XStep", XStep) 588 | PDF_MAKE_NAME("XYZ", XYZ) 589 | PDF_MAKE_NAME("YStep", YStep) 590 | PDF_MAKE_NAME("Yes", Yes) 591 | PDF_MAKE_NAME("ZaDb", ZaDb) 592 | PDF_MAKE_NAME("a", a) 593 | PDF_MAKE_NAME("adbe.pkcs7.detached", adbe_pkcs7_detached) 594 | PDF_MAKE_NAME("ca", ca) 595 | PDF_MAKE_NAME("n0", n0) 596 | PDF_MAKE_NAME("n1", n1) 597 | PDF_MAKE_NAME("n2", n2) 598 | PDF_MAKE_NAME("op", op) 599 | PDF_MAKE_NAME("r", r) 600 | -------------------------------------------------------------------------------- /MuPDFLib/AssemblyInfo.cpp: -------------------------------------------------------------------------------- 1 | 2 | using namespace System; 3 | using namespace System::Reflection; 4 | using namespace System::Runtime::CompilerServices; 5 | using namespace System::Runtime::InteropServices; 6 | using namespace System::Security::Permissions; 7 | 8 | [assembly:AssemblyTitleAttribute(L"MuPDFLib")] ; 9 | [assembly:AssemblyDescriptionAttribute(L"C++/CLI implemented MuPDF")] ; 10 | [assembly:AssemblyCompanyAttribute(L"wmjordan")] ; 11 | [assembly:AssemblyProductAttribute(L"MuPDFLib")] ; 12 | 13 | #define COPYRIGHT L"Copyright (c) wmjordan "__DATE__ 14 | 15 | [assembly:AssemblyCopyrightAttribute(COPYRIGHT)]; 16 | 17 | [assembly:AssemblyVersionAttribute("2.10.11.2")]; 18 | 19 | //[assembly:AssemblyVersion("2.0.*")] 20 | [assembly:AssemblyFileVersion("2.10.11.2")] 21 | 22 | [assembly:ComVisible(false)]; -------------------------------------------------------------------------------- /MuPDFLib/Context.cpp: -------------------------------------------------------------------------------- 1 | #include "MuPDF.h" 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace System::Threading; 7 | 8 | #pragma unmanaged 9 | DLLEXP fz_stream* OpenFile(fz_context* ctx, const wchar_t* filePath) { 10 | fz_stream* r; 11 | MuTryReturn(ctx, fz_open_file_w(ctx, filePath), r); 12 | } 13 | 14 | DLLEXP pdf_document* OpenPdfDocumentStream(fz_context* ctx, fz_stream* stream) { 15 | pdf_document* r; 16 | MuTryReturn(ctx, pdf_open_document_with_stream(ctx, stream), r); 17 | } 18 | 19 | DLLEXP int CloseDocumentWriter(fz_context* ctx, fz_document_writer* writer) { 20 | MuTry(ctx, fz_close_document_writer(ctx, writer)); 21 | } 22 | 23 | struct internal_state { 24 | /* Constructor. */ 25 | internal_state() { 26 | m_locks.user = this; 27 | m_locks.lock = lock; 28 | m_locks.unlock = unlock; 29 | m_ctx = nullptr; 30 | reinit(true); 31 | } 32 | 33 | void reinit(bool multithreaded) { 34 | fz_drop_context(m_ctx); 35 | m_multithreaded = multithreaded; 36 | m_ctx = fz_new_context(NULL /*alloc*/, (multithreaded) ? &m_locks : nullptr, FZ_STORE_DEFAULT); 37 | fz_register_document_handlers(m_ctx); 38 | } 39 | static void lock(void* user, int lock) { 40 | internal_state* self = (internal_state*)user; 41 | assert(self->m_multithreaded); 42 | self->m_mutexes[lock].lock(); 43 | } 44 | static void unlock(void* user, int lock) { 45 | internal_state* self = (internal_state*)user; 46 | assert(self->m_multithreaded); 47 | self->m_mutexes[lock].unlock(); 48 | } 49 | ~internal_state() { 50 | fz_drop_context(m_ctx); 51 | } 52 | 53 | bool m_multithreaded; 54 | fz_context* m_ctx; 55 | std::mutex m_mutex; /* Serialise access to m_ctx. fixme: not actually necessary. */ 56 | 57 | /* Provide thread support to mupdf. */ 58 | std::mutex m_mutexes[FZ_LOCK_MAX]; 59 | fz_locks_context m_locks; 60 | }; 61 | 62 | static internal_state s_state; 63 | 64 | #pragma managed 65 | 66 | MuPDF::Context^ MuPDF::Context::Instance::get() { 67 | if (_Instance) { 68 | return _Instance; 69 | } 70 | if (_MainInstance->_disposed) { 71 | return nullptr; 72 | } 73 | return _Instance = gcnew Context(fz_clone_context(s_state.m_ctx), true); 74 | } 75 | 76 | MuPDF::Colorspace^ MuPDF::Context::GetColorspace(ColorspaceKind kind) { 77 | return gcnew Colorspace(GetFzColorspace(kind)); 78 | } 79 | 80 | MuPDF::Context^ MuPDF::Context::MakeMainContext() { 81 | return gcnew Context(s_state.m_ctx, false); 82 | } 83 | 84 | void MuPDF::Context::ReleaseHandle() { 85 | if (_isCloned) { 86 | fz_drop_context(_context); 87 | _context = NULL; 88 | _disposed = true; 89 | return; 90 | } 91 | // HACK: 92 | // The following statement often causes AccessViolationException for unknown reason. 93 | // Since the main instance is a static one which is finalized only when the program exits, 94 | // we skip it and let the OS do the dirty job. 95 | // fz_drop_context(_context); 96 | _context = NULL; 97 | _disposed = true; 98 | } 99 | 100 | fz_colorspace* MuPDF::Context::GetFzColorspace(ColorspaceKind kind) { 101 | switch (kind) { 102 | case ColorspaceKind::Rgb: return fz_device_rgb(Ptr); 103 | case ColorspaceKind::Cmyk: return fz_device_cmyk(Ptr); 104 | case ColorspaceKind::Gray: return fz_device_gray(Ptr); 105 | case ColorspaceKind::Bgr: return fz_device_bgr(Ptr); 106 | case ColorspaceKind::Lab: return fz_device_lab(Ptr); 107 | } 108 | throw gcnew MuException("Invalid colorspace kind."); 109 | } 110 | 111 | -------------------------------------------------------------------------------- /MuPDFLib/Context.h: -------------------------------------------------------------------------------- 1 | #include "mupdf/fitz.h" 2 | #include "mupdf/pdf.h" 3 | 4 | using namespace System; 5 | using namespace System::Runtime::InteropServices; 6 | using namespace System::Threading; 7 | 8 | #ifndef __CONTEXT 9 | #define __CONTEXT 10 | 11 | namespace MuPDF { 12 | 13 | #pragma warning( push ) 14 | #pragma warning( disable : 4091 ) 15 | typedef ref class Document; 16 | typedef ref class Colorspace; 17 | typedef enum class ColorspaceKind; 18 | typedef ref class Pixmap; 19 | typedef value struct BBox; 20 | // in mupdf_load_system_font.c 21 | extern "C" void install_load_windows_font_funcs(fz_context* ctx); 22 | #pragma warning (pop) 23 | 24 | public ref class Context : IDisposable { 25 | public: 26 | ~Context() { 27 | ReleaseHandle(); 28 | } 29 | 30 | /// 31 | /// Gets or sets rendition anti-alias level. Valid values are ranged [0, 8]. 32 | /// 33 | static property int AntiAlias { 34 | int get() { return fz_aa_level(Ptr); } 35 | void set(int value) { fz_set_aa_level(Ptr, value); } 36 | } 37 | /// 38 | /// Gets or sets text rendition anti-alias level. Valid values are ranged [0, 8]. 39 | /// 40 | static property int TextAntiAlias { 41 | int get() { return fz_text_aa_level(Ptr); } 42 | void set(int value) { fz_set_text_aa_level(Ptr, value); } 43 | } 44 | 45 | static Colorspace^ GetColorspace(ColorspaceKind kind); 46 | 47 | internal: 48 | static property Context^ Instance { 49 | Context ^ get(); 50 | } 51 | 52 | static property fz_context* Ptr { 53 | fz_context* get() { return Instance->_context; } 54 | } 55 | 56 | static fz_colorspace* GetFzColorspace(ColorspaceKind kind); 57 | 58 | protected: 59 | !Context() { 60 | ReleaseHandle(); 61 | } 62 | 63 | private: 64 | fz_context* _context; 65 | bool _disposed; 66 | initonly bool _isCloned; 67 | 68 | static Context^ MakeMainContext(); 69 | static Context^ _MainInstance = MakeMainContext(); 70 | [System::ThreadStaticAttribute] 71 | static Context^ _Instance = _MainInstance; 72 | 73 | Context(fz_context* ctx, bool isCloned) : _context(ctx), _isCloned(isCloned) { 74 | if (!ctx) { 75 | throw gcnew InvalidOperationException("fz_context is null"); 76 | } 77 | install_load_windows_font_funcs(ctx); 78 | fz_register_document_handlers(ctx); 79 | } 80 | 81 | void ReleaseHandle(); 82 | }; 83 | 84 | }; 85 | 86 | #endif // !__CONTEXT 87 | -------------------------------------------------------------------------------- /MuPDFLib/Document/Document.cpp: -------------------------------------------------------------------------------- 1 | #include "Document.h" 2 | #include "MuException.h" 3 | #include 4 | using namespace System::Runtime::InteropServices; 5 | 6 | #pragma unmanaged 7 | static fz_document* OpenDocumentWithStream(fz_context* ctx, fz_stream* stream) { 8 | fz_document* s; 9 | MuTryReturn(ctx, fz_open_document_with_stream(ctx, ".pdf", stream), s); 10 | } 11 | 12 | static fz_page* LoadPage(fz_context* ctx, fz_document* doc, int pn) { 13 | fz_page* p; 14 | MuTryReturn(ctx, fz_load_page(ctx, doc, pn), p); 15 | } 16 | 17 | DLLEXP int PdfSaveDocument(fz_context* ctx, pdf_document* doc, const wchar_t* filePath, const pdf_write_options* options) { 18 | char* utf8path = NULL; 19 | fz_try(ctx) { 20 | utf8path = fz_utf8_from_wchar(ctx, filePath); 21 | pdf_save_document(ctx, doc, utf8path, options); 22 | } 23 | fz_always(ctx) { 24 | fz_free(ctx, utf8path); 25 | } 26 | fz_catch(ctx) { 27 | return 0; 28 | } 29 | return 1; 30 | } 31 | 32 | DLLEXP int PdfSaveSnapshot(fz_context* ctx, pdf_document* doc, const wchar_t* filePath) { 33 | char* utf8path = NULL; 34 | fz_try(ctx) { 35 | utf8path = fz_utf8_from_wchar(ctx, filePath); 36 | pdf_save_snapshot(ctx, doc, utf8path); 37 | } 38 | fz_always(ctx) { 39 | fz_free(ctx, utf8path); 40 | } 41 | fz_catch(ctx) { 42 | return 0; 43 | } 44 | return 1; 45 | } 46 | 47 | static int GraftPages(fz_context* ctx, int pageTo, int numberOfPages, pdf_document* dest, pdf_document* src, int pageFrom) 48 | { 49 | pdf_graft_map* map = pdf_new_graft_map(ctx, dest); 50 | fz_try(ctx) { 51 | if (pageTo < 0) { 52 | for (int i = 0; i < numberOfPages; i++) { 53 | pdf_graft_mapped_page(ctx, map, -1, src, pageFrom++); 54 | } 55 | } 56 | else { 57 | for (int i = 0; i < numberOfPages; i++) { 58 | pdf_graft_mapped_page(ctx, map, pageTo++, src, pageFrom++); 59 | } 60 | } 61 | } 62 | fz_always(ctx) 63 | pdf_drop_graft_map(ctx, map); 64 | fz_catch(ctx) 65 | return 0; 66 | return 1; 67 | } 68 | 69 | static int GraftPage(fz_context* ctx, pdf_graft_map* map, int pageTo, pdf_document* src, int pageFrom) { 70 | MuTry(ctx, pdf_graft_mapped_page(ctx, map, pageTo, src, pageFrom)); 71 | } 72 | 73 | #pragma managed 74 | 75 | MuPDF::Document^ MuPDF::Document::Open(String^ filePath) { 76 | Stream^ s = gcnew Stream(filePath); 77 | try { 78 | auto doc = gcnew Document(s->Ptr); 79 | doc->FilePath = filePath; 80 | return doc; 81 | } 82 | catch (Exception^) { 83 | delete s; 84 | throw; 85 | } 86 | } 87 | 88 | MuPDF::Document^ MuPDF::Document::Open(array^ memoryFile) 89 | { 90 | Stream^ s = gcnew Stream(memoryFile); 91 | try { 92 | auto doc = gcnew Document(s->Ptr); 93 | doc->FilePath = String::Empty; 94 | return doc; 95 | } 96 | catch (Exception^) { 97 | delete s; 98 | throw; 99 | } 100 | } 101 | 102 | MuPDF::Document::Document(fz_stream* stream) { 103 | OpenStream(stream); 104 | } 105 | 106 | void MuPDF::Document::OpenStream(fz_stream* stream) { 107 | fz_context* ctx = Context::Ptr; 108 | fz_document* doc = OpenDocumentWithStream(ctx, stream); 109 | if (doc) { 110 | _document = doc; 111 | _stream = stream; 112 | InitTrailer(); 113 | return; 114 | } 115 | else { 116 | fz_drop_stream(ctx, stream); 117 | } 118 | throw MuException::FromContext(); 119 | } 120 | 121 | void MuPDF::Document::InitTrailer() { 122 | fz_context* ctx = Context::Ptr; 123 | _pdf = pdf_document_from_fz_document(ctx, _document); 124 | if (!_pdf) { 125 | throw gcnew MuException("Document is not PDF."); 126 | } 127 | _trailer = pdf_trailer(ctx, _pdf); 128 | if (!_trailer) { 129 | throw gcnew MuException("Missing document trailer."); 130 | } 131 | _pageCount = fz_count_pages(ctx, _document); 132 | } 133 | 134 | MuPDF::Page^ MuPDF::Document::LoadPage(int pageNumber) { 135 | fz_page* p = ::LoadPage(Context::Ptr, _document, pageNumber); 136 | if (p) { 137 | return gcnew Page(p, pageNumber); 138 | } 139 | throw MuException::FromContext(); 140 | } 141 | 142 | MuPDF::PdfDictionary^ MuPDF::Document::NewPage(Box mediaBox, int rotate, PdfDictionary^ resources, array^ contents) { 143 | pin_ptr c = &contents[0]; 144 | auto b = fz_new_buffer_from_copied_data(Context::Ptr, c, contents->Length); 145 | return gcnew PdfDictionary(pdf_add_page(Context::Ptr, _pdf, mediaBox, rotate, resources ? resources->Ptr : NULL, b)); 146 | } 147 | 148 | void MuPDF::Document::GraftPagesFrom(Document^ srcDoc, int pageFrom, int numberOfPages, int pageTo) { 149 | if (!::GraftPages(Context::Ptr, pageTo, numberOfPages, _pdf, srcDoc->_pdf, pageFrom)) { 150 | throw MuException::FromContext(); 151 | } 152 | RefreshPageCount(); 153 | } 154 | 155 | void MuPDF::Document::GraftPagesFrom(Document^ srcDoc, System::Collections::Generic::IEnumerable^ srcPages, int pageTo) 156 | { 157 | auto ctx = Context::Ptr; 158 | pdf_graft_map* map = pdf_new_graft_map(ctx, _pdf); 159 | auto src = srcDoc->_pdf; 160 | MuException^ err = nullptr; 161 | if (pageTo < 0) { 162 | for each(int num in srcPages) { 163 | if (!::GraftPage(ctx, map, -1, src, num)) { 164 | err = MuException::FromContext(); 165 | goto RETURN; 166 | } 167 | } 168 | } 169 | else { 170 | for each(int num in srcPages) { 171 | if (!::GraftPage(ctx, map, pageTo++, src, num)) { 172 | err = MuException::FromContext(); 173 | goto RETURN; 174 | } 175 | } 176 | } 177 | RETURN: 178 | RefreshPageCount(); 179 | pdf_drop_graft_map(ctx, map); 180 | if (err) { 181 | throw MuException::FromContext(); 182 | } 183 | } 184 | 185 | void MuPDF::Document::SetPageLabel(int index, PageLabelStyle style, String^ prefix, int start) 186 | { 187 | IntPtr p_prefix = Marshal::StringToHGlobalAnsi(prefix); 188 | char* p = static_cast(p_prefix.ToPointer()); 189 | pdf_set_page_labels(Context::Ptr, _pdf, index, (pdf_page_label_style)style, p, start); 190 | Marshal::FreeHGlobal(p_prefix); 191 | } 192 | 193 | void MuPDF::Document::Save(String^ filePath, WriterOptions^ options) { 194 | pin_ptr p = PtrToStringChars(filePath); 195 | pdf_write_options w = options ? options->ToNative() : pdf_write_options(); 196 | auto r = PdfSaveDocument(Context::Ptr, _pdf, (const wchar_t*)p, (const pdf_write_options*)&w); 197 | if (!r) { 198 | throw MuException::FromContext(); 199 | } 200 | } 201 | 202 | void MuPDF::Document::SaveSnapshot(String^ filePath) { 203 | pin_ptr p = PtrToStringChars(filePath); 204 | auto r = PdfSaveSnapshot(Context::Ptr, _pdf, (const wchar_t*)p); 205 | if (!r) { 206 | throw MuException::FromContext(); 207 | } 208 | } 209 | 210 | bool MuPDF::Document::CheckPassword(String^ password) { 211 | const char* c = (char*)(void*)System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(password); 212 | int r = fz_authenticate_password(Context::Ptr, _document, c); 213 | delete c; 214 | return r; 215 | } 216 | 217 | void MuPDF::Document::Reopen() { 218 | if (!_path) { 219 | throw gcnew System::InvalidOperationException("Could not reopen a document without path"); 220 | } 221 | Stream^ s = gcnew Stream(_path); 222 | try { 223 | OpenStream(s->Ptr); 224 | } 225 | catch (Exception^) { 226 | delete s; 227 | throw; 228 | } 229 | } 230 | 231 | pdf_write_options MuPDF::WriterOptions::ToNative() { 232 | pdf_write_options r{}; 233 | r.do_incremental = Incremental; 234 | r.do_pretty = Pretty; 235 | r.do_ascii = Ascii; 236 | r.do_compress = (int)CompressionMode; 237 | r.do_compress_images = CompressImages; 238 | r.do_compress_fonts = CompressFonts; 239 | r.do_decompress = Decompress; 240 | r.do_garbage = (int)Garbage; 241 | r.do_linear = Linear; 242 | r.do_clean = Clean; 243 | r.do_sanitize = Sanitize; 244 | r.do_appearance = Appearance; 245 | r.do_encrypt = (int)Encrypt; 246 | r.dont_regenerate_id = DoNotRegenerateId; 247 | r.do_snapshot = Snapshot; 248 | r.do_preserve_metadata = PreserveMetadata; 249 | r.do_use_objstms = UseObjectStreams; 250 | r.compression_effort = CompressionEffort; 251 | r.permissions = (int)Permissions; 252 | r.do_labels = AddLabels; 253 | if (OwnerPassword) { 254 | System::Runtime::InteropServices::Marshal::Copy(OwnerPassword, 0, (IntPtr)(void*)&r.opwd_utf8, OwnerPassword->Length); 255 | } 256 | if (UserPassword) { 257 | System::Runtime::InteropServices::Marshal::Copy(UserPassword, 0, (IntPtr)(void*)&r.upwd_utf8, UserPassword->Length); 258 | } 259 | return r; 260 | } 261 | -------------------------------------------------------------------------------- /MuPDFLib/Document/Page.cpp: -------------------------------------------------------------------------------- 1 | #include "Page.h" 2 | 3 | #pragma unmanaged 4 | DLLEXP int RunPage(fz_context* ctx, fz_page* page, fz_device* dev, fz_matrix ctm, fz_cookie* cookie) { 5 | MuTry(ctx, fz_run_page(ctx, page, dev, ctm, cookie)); 6 | } 7 | DLLEXP int RunPageContents(fz_context* ctx, fz_page* page, fz_device* dev, fz_matrix ctm, fz_cookie* cookie) { 8 | MuTry(ctx, fz_run_page_contents(ctx, page, dev, ctm, cookie)) 9 | } 10 | DLLEXP int RunPageAnnotations(fz_context* ctx, fz_page* page, fz_device* dev, fz_matrix ctm, fz_cookie* cookie) { 11 | MuTry(ctx, fz_run_page_annots(ctx, page, dev, ctm, cookie)) 12 | } 13 | DLLEXP int RunPageWidgets(fz_context* ctx, fz_page* page, fz_device* dev, fz_matrix ctm, fz_cookie* cookie) { 14 | MuTry(ctx, fz_run_page_widgets(ctx, page, dev, ctm, cookie)) 15 | } 16 | 17 | #pragma managed 18 | MuPDF::PdfArray^ MuPDF::Page::GetPageBox(PageBoxType boxType) { 19 | pdf_obj* box; 20 | switch (boxType) { 21 | case MuPDF::PageBoxType::Media: 22 | box = pdf_dict_get_inheritable(Context::Ptr, PagePtr, PDF_NAME(MediaBox)); 23 | break; 24 | case MuPDF::PageBoxType::Crop: 25 | box = pdf_dict_get_inheritable(Context::Ptr, PagePtr, PDF_NAME(CropBox)); 26 | break; 27 | case MuPDF::PageBoxType::Bleed: 28 | box = pdf_dict_get_inheritable(Context::Ptr, PagePtr, PDF_NAME(BleedBox)); 29 | break; 30 | case MuPDF::PageBoxType::Trim: 31 | box = pdf_dict_get_inheritable(Context::Ptr, PagePtr, PDF_NAME(TrimBox)); 32 | break; 33 | case MuPDF::PageBoxType::Art: 34 | box = pdf_dict_get_inheritable(Context::Ptr, PagePtr, PDF_NAME(ArtBox)); 35 | break; 36 | default: 37 | return nullptr; 38 | } 39 | return GcWrap(PdfArray, box); 40 | } 41 | 42 | void MuPDF::Page::Run(Device^ dev, Matrix ctm, Cookie^ cookie) { 43 | if (!RunPage(Context::Ptr, _page, dev->Ptr, ctm, Unwrap(cookie))) { 44 | throw MuException::FromContext(); 45 | } 46 | } 47 | 48 | void MuPDF::Page::RunContents(Device^ dev, Matrix ctm, Cookie^ cookie) { 49 | if (!RunPageContents(Context::Ptr, _page, dev->Ptr, ctm, Unwrap(cookie))) { 50 | throw MuException::FromContext(); 51 | } 52 | } 53 | 54 | void MuPDF::Page::RunAnnotations(Device^ dev, Matrix ctm, Cookie^ cookie) { 55 | if (!RunPageAnnotations(Context::Ptr, _page, dev->Ptr, ctm, Unwrap(cookie))) { 56 | throw MuException::FromContext(); 57 | } 58 | } 59 | 60 | void MuPDF::Page::RunWidgets(Device^ dev, Matrix ctm, Cookie^ cookie) { 61 | if (!RunPageWidgets(Context::Ptr, _page, dev->Ptr, ctm, Unwrap(cookie))) { 62 | throw MuException::FromContext(); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /MuPDFLib/Document/PdfObject.cpp: -------------------------------------------------------------------------------- 1 | #include "PdfObject.h" 2 | #include "MuException.h" 3 | #include "Vcclr.h" 4 | 5 | #pragma region pdf-object.c 6 | 7 | typedef enum pdf_objkind_e { 8 | PDF_INT = 'i', 9 | PDF_REAL = 'f', 10 | PDF_STRING = 's', 11 | PDF_NAME = 'n', 12 | PDF_ARRAY = 'a', 13 | PDF_DICT = 'd', 14 | PDF_INDIRECT = 'r' 15 | } pdf_objkind; 16 | 17 | #pragma endregion 18 | 19 | using namespace System; 20 | using namespace System::Runtime::InteropServices; 21 | using namespace MuPDF; 22 | 23 | // hack: this method hacks into mupdf/pdf-object.c and provides direct type kind info of a PdfObject 24 | Kind PdfObject::TypeKind::get() { 25 | if (_obj == PDF_NULL) { 26 | return Kind::Null; 27 | } 28 | if (_obj == PDF_TRUE || _obj == PDF_FALSE) { 29 | return Kind::Boolean; 30 | } 31 | if (_obj < PDF_LIMIT) { 32 | return Kind::Name; 33 | } 34 | switch (_obj->kind) { 35 | case PDF_INT: return Kind::Integer; 36 | case PDF_REAL: return Kind::Float; 37 | case PDF_STRING: return Kind::String; 38 | case PDF_NAME: return Kind::Name; 39 | case PDF_ARRAY: return Kind::Array; 40 | case PDF_DICT: return pdf_is_stream(_ctx, _obj) ? Kind::Stream : Kind::Dictionary; 41 | case PDF_INDIRECT: return Kind::Reference; 42 | } 43 | return Kind::Unknown; 44 | }; 45 | 46 | PdfObject^ PdfObject::Wrap(pdf_obj* obj, bool resolve) { 47 | if (obj == PDF_NULL) { 48 | return (PdfObject^)PdfNull::Instance; 49 | } 50 | if (obj == PDF_TRUE) { 51 | return (PdfObject^)PdfBoolean::True; 52 | } 53 | if (obj == PDF_FALSE) { 54 | return (PdfObject^)PdfBoolean::False; 55 | } 56 | if (obj < PDF_LIMIT) { 57 | return gcnew PdfName(obj); 58 | } 59 | switch (obj->kind) { 60 | case PDF_INT: return gcnew PdfInteger(obj); 61 | case PDF_REAL: return gcnew PdfFloat(obj); 62 | case PDF_STRING: return gcnew PdfString(obj); 63 | case PDF_NAME: return gcnew PdfName(obj); 64 | case PDF_ARRAY: return gcnew PdfArray(obj); 65 | case PDF_DICT: return gcnew PdfDictionary(obj); 66 | case PDF_INDIRECT: 67 | return resolve 68 | ? pdf_is_stream(Context::Ptr, obj) ? gcnew PdfStream(obj) : Wrap(pdf_resolve_indirect(Context::Ptr, obj)) 69 | : gcnew PdfReference(obj); 70 | } 71 | throw gcnew MuException("Unexpected object kind: " + obj->kind.ToString()); 72 | } 73 | 74 | bool PdfObject::Equals(PdfObject^ other) { 75 | return other && pdf_objcmp(_ctx, Ptr, other->Ptr) == 0; 76 | } 77 | 78 | pdf_obj* PdfContainer::NewPdfString(String^ text) { 79 | array^ b; 80 | pin_ptr pb; 81 | for each (auto ch in text) { 82 | if (ch > 127) { 83 | int l = (text->Length + 1) << 1; 84 | b = gcnew array(l); 85 | b[0] = 0xFF; 86 | b[1] = 0xFE; 87 | pin_ptr ps = PtrToStringChars(text); 88 | pb = &b[2]; 89 | memcpy(pb, ps, l - 2); 90 | goto MAKE_STRING; 91 | } 92 | } 93 | b = AsciiEncoding->GetBytes(text); 94 | MAKE_STRING: 95 | pb = &b[0]; 96 | return pdf_new_string(Ctx, (const char*)(void*)pb, b->Length); 97 | } 98 | 99 | PdfObject^ PdfDictionary::Locate(...array^ names) { 100 | auto ctx = Ctx; 101 | auto obj = Ptr; 102 | int length = names->Length; 103 | if (length == 0) { 104 | goto RETURN_NULL; 105 | } 106 | int i; 107 | for (i = 0; i < length - 1; i++) { 108 | obj = pdf_dict_get(ctx, obj, (pdf_obj*)names[i]); 109 | if (!obj) { 110 | goto RETURN_NULL; 111 | } 112 | obj = pdf_resolve_indirect_chain(ctx, obj); 113 | if (pdf_is_dict(ctx, obj) == false) { 114 | goto RETURN_NULL; 115 | } 116 | } 117 | return Wrap(pdf_dict_get(ctx, obj, (pdf_obj*)names[i]), true); 118 | RETURN_NULL: 119 | return (PdfObject^)PdfNull::Instance; 120 | } 121 | 122 | array^ PdfString::GetBytes() { 123 | size_t l; 124 | auto b = pdf_to_string(Ctx, Ptr, &l); 125 | if (l > INT_MAX) { 126 | throw gcnew System::InsufficientMemoryException("String length larger than INT_MAX"); 127 | } 128 | array^ r = gcnew array((int)(l)); 129 | memcpy(&r, b, l); 130 | return r; 131 | } 132 | 133 | String^ PdfString::DecodePdfString() { 134 | size_t l; 135 | auto b = pdf_to_string(Ctx, Ptr, &l); 136 | if (l > INT_MAX) { 137 | throw gcnew System::InsufficientMemoryException("String length larger than INT_MAX"); 138 | } 139 | if (b[0] == (char)254 && b[1] == (char)255) { 140 | return gcnew String(b, 2, (int)(l - 2), Encoding::BigEndianUnicode); 141 | } 142 | if (b[0] == (char)255 && b[1] == (char)254) { 143 | return gcnew String(b, 2, (int)(l - 2), Encoding::Unicode); 144 | } 145 | // PDFENCODE 146 | auto chars = new Char[l]; 147 | for (size_t i = 0; i < l; i++) { 148 | chars[i] = fz_unicode_from_pdf_doc_encoding[b[i]]; 149 | } 150 | return gcnew String(chars, 0, (int)(l)); 151 | } 152 | String^ PdfString::Value::get() { 153 | return _string ? _string : (_string = DecodePdfString()); 154 | } 155 | 156 | void PdfStream::SetBytes(array^ data, bool isCompressed) { 157 | auto ctx = Ctx; 158 | pin_ptr d = &data[0]; 159 | fz_buffer* b = fz_new_buffer_from_copied_data(ctx, d, data->Length); 160 | pdf_update_stream(ctx, pdf_pin_document(ctx, Ptr), Ptr, b, isCompressed); 161 | fz_free(ctx, b); 162 | } 163 | -------------------------------------------------------------------------------- /MuPDFLib/Document/Stream.cpp: -------------------------------------------------------------------------------- 1 | #include "Stream.h" 2 | #include "MuException.h" 3 | #include "ObjWrapper.h" 4 | #include "Vcclr.h" 5 | 6 | using namespace IO; 7 | using namespace Runtime::InteropServices; 8 | 9 | #pragma unmanaged 10 | static fz_stream* OpenStream(fz_context* ctx, const wchar_t* filePath) { 11 | fz_stream* s; 12 | MuTryReturn(ctx, fz_open_file_w(ctx, filePath), s) 13 | } 14 | 15 | static fz_stream* OpenStream(fz_context* ctx, const unsigned char* buffer, int length) { 16 | fz_stream* s; 17 | MuTryReturn(ctx, fz_open_memory(ctx, buffer, length), s) 18 | } 19 | 20 | static fz_stream* DecodeTiffFax(fz_context* ctx, fz_stream* s, int width, int height, int k, int endOfLine, int encodedByteAlign, int endOfBlock, int blackIs1) { 21 | fz_stream* r; 22 | MuTryReturn(ctx, fz_open_faxd(ctx, s, k, endOfLine, encodedByteAlign, width, height, endOfBlock, blackIs1), r); 23 | } 24 | 25 | #pragma managed 26 | MuPDF::Stream::Stream(String^ filePath) { 27 | pin_ptr p = PtrToStringChars(filePath); 28 | fz_stream* s = OpenStream(Context::Ptr, (const wchar_t*)p); 29 | if (s) { 30 | _stream = s; 31 | _initDataLength = -1; 32 | return; 33 | } 34 | throw MuException::FromContext(); 35 | } 36 | 37 | array^ MuPDF::Stream::ReadAll(int maxSize) { 38 | if (_data.IsAllocated) { 39 | GcnewArray(Byte, b, maxSize > _initDataLength ? _initDataLength : maxSize); 40 | pin_ptr p = &b[0]; 41 | fz_read(Context::Ptr, _stream, p, b->Length); 42 | return b; 43 | } 44 | 45 | MemoryStream^ ms = gcnew MemoryStream(4096); 46 | BinaryWriter^ bw = gcnew BinaryWriter(ms); 47 | size_t l; 48 | try { 49 | GcnewArray(Byte, b, 4096); 50 | pin_ptr p = &b[0]; 51 | while ((l = fz_read(Context::Ptr, _stream, p, 4096)) > 0) { 52 | bw->Write(b, 0, (int)(l)); 53 | if (ms->Length >= 0x06400000 && ms->Length > maxSize) { 54 | throw gcnew IOException("Compression bomb detected."); 55 | } 56 | } 57 | ms->Flush(); 58 | return ms->ToArray(); 59 | } 60 | catch (const Exception^) { 61 | throw; 62 | } 63 | finally { 64 | if (ms) { delete ms; } 65 | if (bw) { delete bw; } 66 | } 67 | } 68 | 69 | MuPDF::Stream^ MuPDF::Stream::DecodeTiffFax(int width, int height, int k, bool endOfLine, bool encodeByteAlign, bool endOfBlock, bool blackIs1) { 70 | auto s = ::DecodeTiffFax(Context::Ptr, _stream, width, height, k, endOfLine, encodeByteAlign, endOfBlock, blackIs1); 71 | if (s != NULL) { 72 | return gcnew MuPDF::Stream(s); 73 | } 74 | throw MuException::FromContext(); 75 | } 76 | 77 | MuPDF::Stream::Stream(array^ data) { 78 | _data = GCHandle::Alloc(data, GCHandleType::Pinned); 79 | fz_stream* s = OpenStream(Context::Ptr, (const unsigned char*)(void*)(_data.AddrOfPinnedObject()), data->Length); 80 | if (s) { 81 | _stream = s; 82 | _initDataLength = data->Length; 83 | return; 84 | } 85 | throw MuException::FromContext(); 86 | } 87 | 88 | void MuPDF::Stream::ReleaseHandle() { 89 | fz_drop_stream(Context::Ptr, _stream); 90 | if (_data.IsAllocated) { 91 | _data.Free(); 92 | } 93 | _stream = NULL; 94 | } 95 | -------------------------------------------------------------------------------- /MuPDFLib/MuPDFLib.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wmjordan/SharpMuPDF/3031269d36eb7fb2968b3c0965764a1037f7c22b/MuPDFLib/MuPDFLib.rc -------------------------------------------------------------------------------- /MuPDFLib/MuPDFLib.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wmjordan/SharpMuPDF/3031269d36eb7fb2968b3c0965764a1037f7c22b/MuPDFLib/MuPDFLib.snk -------------------------------------------------------------------------------- /MuPDFLib/MuPDFLib.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 23 | {5f615f91-dff8-4f05-bf48-6222b7d86519} 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 16.0 69 | Win32Proj 70 | {7ac327e2-05d5-4acc-9400-c78c183de505} 71 | MuPDFLib 72 | 10.0 73 | 7.0 74 | 4.0 75 | 76 | 77 | 78 | DynamicLibrary 79 | true 80 | v143 81 | Unicode 82 | true 83 | 84 | 85 | DynamicLibrary 86 | false 87 | v143 88 | Unicode 89 | true 90 | true 91 | 92 | 93 | DynamicLibrary 94 | true 95 | v143 96 | Unicode 97 | true 98 | 99 | 100 | DynamicLibrary 101 | false 102 | v143 103 | true 104 | Unicode 105 | true 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | true 127 | MuPDFLib 128 | $(ProjectDir)MuPDFLib.snk 129 | 130 | 131 | false 132 | MuPDFLib 133 | $(ProjectDir)MuPDFLib.snk 134 | true 135 | 136 | 137 | true 138 | MuPDFLib 139 | 140 | 141 | false 142 | MuPDFLib 143 | true 144 | 145 | 146 | 147 | Level3 148 | true 149 | FZ_DLL;WIN32;_DEBUG;MUPDFLIB_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 150 | true 151 | ../mupdf/include;!Include;%(AdditionalIncludeDirectories) 152 | 153 | 154 | Windows 155 | true 156 | false 157 | libmupdf.def 158 | 159 | 160 | Python "$(ProjectDir)gen_libmupdf.def.py" 161 | 162 | 163 | 164 | 165 | Level3 166 | true 167 | true 168 | true 169 | FZ_DLL;WIN32;NDEBUG;MUPDFLIB_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 170 | true 171 | ../mupdf/include;!Include;%(AdditionalIncludeDirectories) 172 | 173 | 174 | Windows 175 | true 176 | true 177 | true 178 | false 179 | libmupdf.def 180 | 181 | 182 | Python "$(ProjectDir)gen_libmupdf.def.py" 183 | Python "$(ProjectDir)sync_name_table.py" 184 | Python "$(ProjectDir)version.py" 185 | 186 | 187 | 188 | 189 | Level3 190 | true 191 | FZ_DLL;_DEBUG;MUPDFLIB_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 192 | true 193 | ../mupdf/include;!Include;%(AdditionalIncludeDirectories) 194 | 195 | 196 | Windows 197 | true 198 | false 199 | libmupdf.def 200 | 201 | 202 | Python "$(ProjectDir)gen_libmupdf.def.py" 203 | 204 | 205 | 206 | 207 | 208 | Level3 209 | true 210 | true 211 | true 212 | FZ_DLL;NDEBUG;MUPDFLIB_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 213 | true 214 | ../mupdf/include;!Include;%(AdditionalIncludeDirectories) 215 | 216 | 217 | Windows 218 | true 219 | true 220 | true 221 | false 222 | libmupdf.def 223 | 224 | 225 | Python "$(ProjectDir)gen_libmupdf.def.py" 226 | Python "$(ProjectDir)sync_name_table.py" 227 | Python "$(ProjectDir)version.py" 228 | 229 | 230 | 231 | 232 | 233 | -------------------------------------------------------------------------------- /MuPDFLib/MuPDFLib.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 6 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 7 | 8 | 9 | {cff1e727-1f49-4fe2-81f6-9c51dc9945ef} 10 | 11 | 12 | {6731a656-be12-448b-a675-3f03fcf9d394} 13 | 14 | 15 | {89f1a1a3-e1f4-4a18-b67f-48f578532657} 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | Rendition 28 | 29 | 30 | Rendition 31 | 32 | 33 | Document 34 | 35 | 36 | Document 37 | 38 | 39 | 40 | Rendition 41 | 42 | 43 | Document 44 | 45 | 46 | Document 47 | 48 | 49 | Rendition 50 | 51 | 52 | Rendition 53 | 54 | 55 | 56 | 57 | Common 58 | 59 | 60 | Rendition 61 | 62 | 63 | Rendition 64 | 65 | 66 | Document 67 | 68 | 69 | Document 70 | 71 | 72 | Rendition 73 | 74 | 75 | Document 76 | 77 | 78 | Rendition 79 | 80 | 81 | Document 82 | 83 | 84 | 85 | Document 86 | 87 | 88 | Rendition 89 | 90 | 91 | Common 92 | 93 | 94 | Common 95 | 96 | 97 | Common 98 | 99 | 100 | 101 | 102 | 103 | 104 | Resource Files 105 | 106 | 107 | -------------------------------------------------------------------------------- /MuPDFLib/Rendition/Colorspace.cpp: -------------------------------------------------------------------------------- 1 | #include "Colorspace.h" 2 | -------------------------------------------------------------------------------- /MuPDFLib/Rendition/Device.cpp: -------------------------------------------------------------------------------- 1 | #include "Device.h" 2 | 3 | #pragma unmanaged 4 | int CloseDevice(fz_context* ctx, fz_device* dev) { 5 | MuTry(ctx, fz_close_device(ctx, dev)); 6 | } 7 | -------------------------------------------------------------------------------- /MuPDFLib/Rendition/Geometry.cpp: -------------------------------------------------------------------------------- 1 | #include "Geometry.h" 2 | 3 | MuPDF::Box MuPDF::Box::Transform(Matrix matrix) { 4 | return fz_transform_rect(*this, matrix); 5 | } 6 | 7 | MuPDF::BBox MuPDF::Box::Round() { 8 | return (BBox)*this; 9 | } 10 | 11 | MuPDF::Box::operator Box(BBox box) { 12 | return { (float)box.X0, (float)box.Y0, (float)box.X1, (float)box.Y1 }; 13 | } 14 | 15 | MuPDF::Box MuPDF::Box::operator&(Box a, Box b) { 16 | if (b.IsInfinite) return a; 17 | if (a.IsInfinite) return b; 18 | return { a.X0 < b.X0 ? b.X0 : a.X0, 19 | a.Y0 < b.Y0 ? b.Y0 : a.Y0, 20 | a.X1 > b.X1 ? b.X1 : a.X1, 21 | a.Y1 > b.Y1 ? b.Y1 : a.Y1 22 | }; 23 | } 24 | 25 | MuPDF::Box MuPDF::Box::operator|(Box a, Box b) { 26 | /* Check for empty box before infinite box */ 27 | if (!b.IsValid) return a; 28 | if (!a.IsValid) return b; 29 | if (a.IsInfinite) return a; 30 | if (b.IsInfinite) return b; 31 | return { a.X0 > b.X0 ? b.X0 : a.X0, 32 | a.Y0 > b.Y0 ? b.Y0 : a.Y0, 33 | a.X1 < b.X1 ? b.X1 : a.X1, 34 | a.Y1 < b.Y1 ? b.Y1 : a.Y1 }; 35 | } 36 | 37 | MuPDF::BBox MuPDF::BBox::operator|(BBox a, BBox b) { 38 | /* Check for empty box before infinite box */ 39 | if (!b.IsValid) return a; 40 | if (!a.IsValid) return b; 41 | if (a.IsInfinite) return a; 42 | if (b.IsInfinite) return b; 43 | return { a.X0 > b.X0 ? b.X0 : a.X0, 44 | a.Y0 > b.Y0 ? b.Y0 : a.Y0, 45 | a.X1 < b.X1 ? b.X1 : a.X1, 46 | a.Y1 < b.Y1 ? b.Y1 : a.Y1 }; 47 | } 48 | 49 | MuPDF::BBox::operator BBox(Box box) { 50 | const static float t = 0.001f; 51 | return { (int)floor(box.X0 + t), (int)floor(box.Y0 + t), (int)ceil(box.X1 - t), (int)ceil(box.Y1 - t) }; 52 | } 53 | 54 | MuPDF::BBox MuPDF::BBox::operator&(BBox a, BBox b) { 55 | if (b.IsInfinite) return a; 56 | if (a.IsInfinite) return b; 57 | return { a.X0 < b.X0 ? b.X0 : a.X0, 58 | a.Y0 < b.Y0 ? b.Y0 : a.Y0, 59 | a.X1 > b.X1 ? b.X1 : a.X1, 60 | a.Y1 > b.Y1 ? b.Y1 : a.Y1 61 | }; 62 | } 63 | 64 | MuPDF::Matrix MuPDF::Matrix::Concat(Matrix value) { 65 | return Matrix( 66 | A * value.A + B * value.C, 67 | A * value.B + B * value.D, 68 | C * value.A + D * value.C, 69 | C * value.B + D * value.D, 70 | E * value.A + F * value.C + value.E, 71 | E * value.B + F * value.D + value.F); 72 | } 73 | 74 | MuPDF::Matrix MuPDF::Matrix::RotateTo(float theta) { 75 | while (theta < 0) 76 | theta += 360; 77 | while (theta >= 360) 78 | theta -= 360; 79 | 80 | if (fabs(0 - theta) < FLT_EPSILON) { 81 | return *this; 82 | } 83 | if (fabs(90.0f - theta) < FLT_EPSILON) { 84 | return Matrix(C, D, -A, -B, E, F); 85 | } 86 | if (fabs(180.0f - theta) < FLT_EPSILON) { 87 | return Matrix(-A, -B, -C, -D, E, F); 88 | } 89 | if (fabs(270.0f - theta) < FLT_EPSILON) { 90 | return Matrix(-C, -D, A, B, E, F); 91 | } 92 | float s = sin(theta * FZ_PI / 180); 93 | float c = cos(theta * FZ_PI / 180); 94 | return Matrix(c * A + s * C, c * B + s * D, -s * A + c * C, -s * B + c * D, E, F); 95 | } 96 | 97 | MuPDF::Matrix MuPDF::Matrix::ShearTo(float h, float v) { 98 | return Matrix( 99 | v * C + A, 100 | v * D + B, 101 | h * A + C, 102 | h * B + D, 103 | E, F); 104 | } 105 | 106 | MuPDF::Matrix MuPDF::Matrix::Rotate(float theta) { 107 | float s; 108 | float c; 109 | 110 | while (theta < 0) 111 | theta += 360; 112 | while (theta >= 360) 113 | theta -= 360; 114 | 115 | if (fabs(0 - theta) < FLT_EPSILON) { 116 | s = 0; 117 | c = 1; 118 | } 119 | else if (fabs(90.0f - theta) < FLT_EPSILON) { 120 | s = 1; 121 | c = 0; 122 | } 123 | else if (fabs(180.0f - theta) < FLT_EPSILON) { 124 | s = 0; 125 | c = -1; 126 | } 127 | else if (fabs(270.0f - theta) < FLT_EPSILON) { 128 | s = -1; 129 | c = 0; 130 | } 131 | else { 132 | s = sin(theta * FZ_PI / 180); 133 | c = cos(theta * FZ_PI / 180); 134 | } 135 | return MuPDF::Matrix(c, s, -s, c, 0, 0); 136 | } 137 | 138 | MuPDF::Quad MuPDF::Quad::Union(Quad other) { 139 | float x1 = fz_min(fz_min(UpperLeft.X, other.UpperLeft.X), fz_min(LowerLeft.X, other.LowerLeft.X)); 140 | float x2 = fz_max(fz_max(UpperLeft.X, other.UpperLeft.X), fz_max(LowerLeft.X, other.LowerLeft.X)); 141 | float y1 = fz_min(fz_min(UpperLeft.Y, other.UpperLeft.Y), fz_min(LowerLeft.Y, other.LowerLeft.Y)); 142 | float y2 = fz_max(fz_max(UpperLeft.Y, other.UpperLeft.Y), fz_max(LowerLeft.Y, other.LowerLeft.Y)); 143 | return Quad(Point(x1, y1), Point(x2, y2), Point(x1, y2), Point(x2, y2)); 144 | } 145 | 146 | MuPDF::Box MuPDF::Quad::ToBox() { 147 | float x0, y0, x1, y1; 148 | x0 = fz_min(fz_min(LowerLeft.X, LowerRight.X), fz_min(UpperLeft.X, UpperRight.X)); 149 | y0 = fz_min(fz_min(LowerLeft.Y, LowerRight.Y), fz_min(UpperLeft.Y, UpperRight.Y)); 150 | x1 = fz_max(fz_max(LowerLeft.X, LowerRight.X), fz_max(UpperLeft.X, UpperRight.X)); 151 | y1 = fz_max(fz_max(LowerLeft.Y, LowerRight.Y), fz_max(UpperLeft.Y, UpperRight.Y)); 152 | return Box(x0, y0, x1, y1); 153 | } 154 | 155 | bool MuPDF::Quad::IsPointInsideTriangle(Point p, Point a, Point b, Point c) { 156 | float s, t, area; 157 | s = a.Y * c.X - a.X * c.Y + (c.Y - a.Y) * p.X + (a.X - c.X) * p.Y; 158 | t = a.X * b.Y - a.Y * b.X + (a.Y - b.Y) * p.X + (b.X - a.X) * p.Y; 159 | 160 | if ((s < 0) != (t < 0)) 161 | return 0; 162 | 163 | area = -b.Y * c.X + a.Y * (c.X - b.X) + a.X * (b.Y - c.Y) + b.X * c.Y; 164 | 165 | return area < 0 ? 166 | (s <= 0 && s + t >= area) : 167 | (s >= 0 && s + t <= area); 168 | } 169 | -------------------------------------------------------------------------------- /MuPDFLib/Rendition/Pixmap.cpp: -------------------------------------------------------------------------------- 1 | #include "Pixmap.h" 2 | 3 | #pragma unmanaged 4 | static fz_pixmap* GetPixmap(fz_context* ctx, fz_colorspace* cs, int width, int height) { 5 | fz_pixmap* p; 6 | MuTryReturn(ctx, fz_new_pixmap(ctx, cs, width, height, NULL, 0), p); 7 | } 8 | static fz_pixmap* GetPixmap(fz_context* ctx, fz_colorspace* cs, fz_irect rect) { 9 | fz_pixmap* p; 10 | MuTryReturn(ctx, fz_new_pixmap_with_bbox(ctx, cs, rect, NULL, 0), p); 11 | } 12 | 13 | DLLEXP fz_pixmap* NewPixmapWithBBox(fz_context* ctx, fz_colorspace* colorspace, fz_irect bbox, fz_separations* seps, int alpha) { 14 | fz_pixmap* r; 15 | MuTryReturn(ctx, fz_new_pixmap_with_bbox(ctx, colorspace, bbox, seps, alpha), r); 16 | } 17 | 18 | DLLEXP int TintPixmap(fz_context* ctx, fz_pixmap* pixmap, int black, int white) { 19 | MuTry(ctx, fz_tint_pixmap(ctx, pixmap, black, white)); 20 | } 21 | 22 | #pragma managed 23 | 24 | MuPDF::Pixmap^ MuPDF::Pixmap::Create(ColorspaceKind colorspace, int width, int height) { 25 | fz_pixmap* pixmap = GetPixmap(Context::Ptr, Context::GetFzColorspace(colorspace), width, height); 26 | if (pixmap) { 27 | return gcnew Pixmap(pixmap); 28 | } 29 | throw MuException::FromContext(); 30 | } 31 | 32 | MuPDF::Pixmap^ MuPDF::Pixmap::Create(ColorspaceKind colorspace, MuPDF::BBox box) { 33 | fz_pixmap* pixmap = GetPixmap(Context::Ptr, Context::GetFzColorspace(colorspace), box); 34 | if (pixmap) { 35 | return gcnew Pixmap(pixmap); 36 | } 37 | throw MuException::FromContext(); 38 | } 39 | 40 | bool MuPDF::Pixmap::Tint(int black, int white) { 41 | return TintPixmap(Context::Ptr, _pixmap, black, white); 42 | } -------------------------------------------------------------------------------- /MuPDFLib/Rendition/TextPage.cpp: -------------------------------------------------------------------------------- 1 | #include "TextPage.h" 2 | 3 | MuPDF::TextOptions::operator fz_stext_options(TextOptions^ options) { 4 | fz_stext_options s{}; 5 | if (options) { 6 | s.flags = (int)options->Flags; 7 | s.scale = options->Scale; 8 | } 9 | return s; 10 | } 11 | 12 | String^ MuPDF::TextSpan::ToString() { 13 | int l = _length; 14 | auto sb = gcnew StringBuilder(l); 15 | fz_stext_char* c = _ch; 16 | do { 17 | sb->Append((Char)c->c); 18 | } while (--l > 0 && (c = c->next)); 19 | return sb->ToString(); 20 | } 21 | 22 | String^ MuPDF::TextLine::ToString() { 23 | auto sb = gcnew StringBuilder(16); 24 | fz_stext_char* c = _line->first_char; 25 | do { 26 | sb->Append((Char)c->c); 27 | } while (c = c->next); 28 | return sb->ToString(); 29 | } 30 | 31 | String^ MuPDF::TextBlock::ToString() { 32 | if (Type != BlockType::Text) { 33 | return String::Empty; 34 | } 35 | StringBuilder^ sb = gcnew StringBuilder(16); 36 | fz_stext_line* l = _block->u.t.first_line; 37 | do { 38 | fz_stext_char* c = l->first_char; 39 | do { 40 | sb->Append((Char)c->c); 41 | } while (c = c->next); 42 | sb->AppendLine(); 43 | } while (l = l->next); 44 | return sb->ToString(); 45 | } 46 | 47 | bool MaybeUtf8(const char* text) { 48 | unsigned int b = 0; // byte count 49 | const char* p = text; 50 | char c; 51 | while (c = *p) { 52 | if (b == 0) { 53 | if (c < 0x80) { 54 | goto NEXT; 55 | } 56 | // multibyte 57 | if (c < 0xC0) { 58 | b = 1; 59 | } 60 | else if (c < 0xE0) { 61 | b = 2; 62 | } 63 | else if (c < 0xF0) { 64 | b = 3; 65 | } 66 | else if (c < 0xF8) { 67 | b = 4; 68 | } 69 | else if (c < 0xFE) { 70 | b = 5; 71 | } 72 | else { 73 | return false; 74 | } 75 | } 76 | else { 77 | // multi-byte subsequent char: 10xxxxxx 78 | if ((c & 0xC0) != 0x80) { 79 | return false; 80 | } 81 | b--; 82 | } 83 | NEXT: 84 | ++p; 85 | } 86 | return b == 0; 87 | } 88 | 89 | bool MuPDF::TextLine::TextLineSpanContainer::MoveNext() { 90 | if (!_start) { 91 | return false; 92 | } 93 | auto end = _start; 94 | auto p = end->next; 95 | auto font = _start->font; 96 | auto color = _start->argb; 97 | auto size = _start->size; 98 | Quad quad = _start->quad; 99 | int length = 1; 100 | while (p) { 101 | if (p->font != font || p->size != size || p->argb != color) { 102 | _Current = gcnew TextSpan(_start, length, quad.Union(p->quad).ToBox(), _Line->IsVertical); 103 | _start = p; 104 | return true; 105 | } 106 | end = p; 107 | p = p->next; 108 | ++length; 109 | } 110 | _Current = gcnew TextSpan(_start, length, end == _start ? quad.ToBox() : quad.Union(end->quad).ToBox(), _Line->IsVertical); 111 | _start = NULL; 112 | return true; 113 | } 114 | 115 | void MuPDF::TextLine::TextLineSpanContainer::Reset() { 116 | _Current = nullptr; 117 | _active = NULL; 118 | _start = _Line->_line->first_char; 119 | } 120 | -------------------------------------------------------------------------------- /MuPDFLib/gen_libmupdf.def.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Generates a list of all exports from libmupdf.dll from the function lists 5 | contained in the mupdf/include/* headers (only MuPDF and MuXPS are included) 6 | and adds exports for the other libraries contained within libmupdf.dll but 7 | used by SumatraPDF-no-MuPDF.exe (unarr, libdjvu, zlib, lzma, libwebp). 8 | """ 9 | 10 | import os, re 11 | import pathlib 12 | 13 | def generateExports(header, exclude, pattern = '/*.h'): 14 | if os.path.isdir(header): 15 | return "\r\n".join([generateExports(os.path.join(file), exclude) for file in pathlib.Path().glob(header + pattern)]) 16 | 17 | data = open(header, "r").read() 18 | data = re.sub(r"(?sm)^#ifndef NDEBUG\s.*?^#endif", "", data, count= 0) 19 | data = re.sub(r"(?sm)^#ifdef ARCH_ARM\s.*?^#endif", "", data, count= 0) 20 | data = re.sub(r"(?sm)^#ifdef FITZ_DEBUG_LOCKING\s.*?^#endif", "", data, count= 0) 21 | data = data.replace(" FZ_NORETURN;", ";") 22 | functions = re.findall(r"(?sm)^\w+ (?:\w+ )?\*?(\w+)\(.*?\);", data) 23 | return "\r\n".join(["\t" + name for name in functions if name not in exclude]) 24 | 25 | def collectFunctions(file): 26 | data = open(file, "r").read() 27 | return re.findall(r"(?sm)^\w+(?: \*\n|\n| \*| )((?:fz_|pdf_|xps_|jbig2_)\w+)\(", data) 28 | 29 | LIBMUPDF_DEF = """\ 30 | ; This file is auto-generated by gen_libmupdf.def.py 31 | 32 | LIBRARY MuPDFLib 33 | EXPORTS 34 | 35 | ; Fitz exports 36 | 37 | %(fitz_exports)s 38 | 39 | ; MuPDF exports 40 | 41 | %(mupdf_exports)s 42 | 43 | ; JBIG2 exports 44 | 45 | %(jbig2_exports)s 46 | 47 | ; Leptonica exports 48 | 49 | %(leptonica_exports)s 50 | 51 | ; Tesseract exports 52 | 53 | %(tesseract_exports)s 54 | 55 | """ 56 | 57 | def main(): 58 | os.chdir(os.path.join(os.path.dirname(__file__), "../mupdf")) 59 | 60 | # don't include/export doc_* functions, support for additional input/output formats and form support 61 | doc_exports = collectFunctions("source/fitz/document-all.c") + ["fz_get_annot_type", "fz_log_dump_store","fz_outline_from_iterator"] 62 | more_formats = collectFunctions("source/fitz/svg-device.c") + collectFunctions("source/fitz/output-pcl.c") + collectFunctions("source/fitz/output-pwg.c") 63 | form_exports = collectFunctions("source/pdf/pdf-form.c") + collectFunctions("source/pdf/pdf-event.c") + collectFunctions("source/pdf/pdf-appearance.c") + ["pdf_access_submit_event", "pdf_init_ui_pointer_event"] 64 | misc_exports = collectFunctions("source/fitz/test-device.c") + ["fz_set_stderr", "fz_set_stdout", "fz_colorspace_name_process_colorants", "fz_getoptw", "fz_valgrind_pixmap", "fz_stderr", "track_usage", "fz_log_errorFL", "fz_log_error_printfFL", "fz_morph_errorFL", "fz_do_catchFL", "fz_rethrowFL", "fz_rethrow_ifFL", "fz_rethrow_unlessFL", "fz_throwFL", "fz_vlog_error_printfFL", "fz_vthrowFL", "fz_vwarnFL", "fz_warnFL", "HEAP_CAT"] 65 | sign_exports = ["pdf_crypt_buffer", "pdf_read_pfx", "pdf_sign_signature", "pdf_signer_designated_name", "pdf_free_designated_name"] 66 | jbig2_exclude = collectFunctions("thirdparty/jbig2dec/jbig2_image_rw.h") + ["jbig2_dump_huffman_binary", "jbig2_dump_huffman_state", "jbig2_arith_has_reached_marker"] 67 | tesseract_exclude = ["TessBaseAPIInitLangMod", "TessBaseAPIClearAdaptiveClassifier", "TessBaseAPIAdaptToWordStr", "TessBaseAPIDetectOrientationScript"] 68 | 69 | fitz_exports = generateExports("include/mupdf/fitz", doc_exports + more_formats + misc_exports) 70 | mupdf_exports = generateExports("include/mupdf/pdf", form_exports + sign_exports + ["pdf_drop_designated_name", "pdf_print_xref", "pdf_recognize", "pdf_resolve_obj", "pdf_open_compressed_stream", "pdf_finish_edit"]) 71 | jbig2_exports = generateExports("thirdparty/jbig2dec", jbig2_exclude, "/jbig2*.h") 72 | leptonica_exports = generateExports("thirdparty/leptonica/src", [], "/allheaders.h") 73 | tesseract_exports = generateExports("thirdparty/tesseract/include/tesseract", tesseract_exclude, "/capi.h") 74 | 75 | list = LIBMUPDF_DEF % locals() 76 | open("../MuPDFLib/libmupdf.def", "wt").write(list.replace('\r\n', "\n")) 77 | 78 | print("generated libmupdf.def") 79 | 80 | if __name__ == "__main__": 81 | main() 82 | -------------------------------------------------------------------------------- /MuPDFLib/modify_vcxprojs.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Rewrite libmupdf.vcxproj: 5 | 1. insert reference to mupdf_load_system_font.c, 6 | 2. add preprocessor TOFU;TOFU_CJK_EXT 7 | 8 | Rewrite other vcxproj files to place output files into the proper directory. 9 | 10 | Run this script before compiling libmupdf.vcxproj 11 | """ 12 | 13 | import os 14 | import pathlib 15 | import xml.etree.ElementTree as ET 16 | import shutil 17 | 18 | def main(): 19 | os.chdir(os.path.dirname(__file__)) 20 | os.chdir("..\\mupdf\\platform\\win32\\") 21 | 22 | modified_files = [] 23 | default_namespace = "http://schemas.microsoft.com/developer/msbuild/2003" 24 | 25 | for filename in ["bin2coff.vcxproj", "libextract.vcxproj", "libharfbuzz.vcxproj", "libleptonica.vcxproj", "libluratech.vcxproj", "libmupdf.vcxproj", "libpkcs7.vcxproj", "libresources.vcxproj", "libtesseract.vcxproj", "libthirdparty.vcxproj", "libmubarcode.vcxproj", "libzxing.vcxproj", "sodochandler.vcxproj"]: 26 | print(f'Processing {filename}...') 27 | doc = ET.parse(filename) 28 | ET.register_namespace("", default_namespace) 29 | ns = {'ms': default_namespace} 30 | root = doc.getroot() 31 | any_modification = False 32 | 33 | for pg in root.findall("ms:PropertyGroup", ns): 34 | condition = pg.get('Condition') 35 | if condition is not None: 36 | if condition.endswith("|Win32'"): 37 | any_modification |= update_property_group(pg, ns, 'Win32') 38 | elif condition.endswith("|x64'"): 39 | any_modification |= update_property_group(pg, ns, 'x64') 40 | 41 | if filename.endswith("libmupdf.vcxproj"): 42 | any_modification |= modify_libmupdf(root, ns) 43 | 44 | if any_modification: 45 | # backup original file 46 | backup_filename = filename + '.bak' 47 | shutil.copy(filename, backup_filename) 48 | print(f'Backup created for {filename}.') 49 | # save modified file 50 | doc.write(filename, encoding='utf-8', xml_declaration=True) 51 | print(f'Processed {filename}.') 52 | modified_files.append(filename) 53 | else: 54 | print(f'No modifications needed for {filename}.') 55 | 56 | print(f'Files modified: {modified_files}') 57 | 58 | def modify_preprocessor(preprocessors, preprocessor, value = None): 59 | pe = preprocessor + "="; 60 | for p in preprocessors: 61 | if preprocessor == p or p.startswith(pe): # skip if preprocessor already defined 62 | return False 63 | preprocessors.insert(0, preprocessor + "=" + value if value is not None else preprocessor) 64 | return True 65 | 66 | def modify_libmupdf(root, ns): 67 | # find all ItemGroup/ClCompile 68 | modified = False 69 | 70 | # modify ItemDefinitionGroup/ClCompile/PreprocessorDefinitions elements 71 | preprocessor_elements = root.findall("ms:ItemDefinitionGroup/ms:ClCompile/ms:PreprocessorDefinitions", ns) 72 | 73 | if preprocessor_elements is not None: 74 | for elem in preprocessor_elements: 75 | preprocessors = elem.text.split(';') 76 | # check if contains "TOFU;TOFU_CJK_EXT;" 77 | modified |= modify_preprocessor(preprocessors, "TOFU") 78 | modified |= modify_preprocessor(preprocessors, "TOFU_CJK_EXT") 79 | modified |= modify_preprocessor(preprocessors, "FZ_ENABLE_CBZ", "0") 80 | modified |= modify_preprocessor(preprocessors, "FZ_ENABLE_EPUB", "0") 81 | modified |= modify_preprocessor(preprocessors, "FZ_ENABLE_FB2", "0") 82 | modified |= modify_preprocessor(preprocessors, "FZ_ENABLE_HTML", "0") 83 | modified |= modify_preprocessor(preprocessors, "FZ_ENABLE_JS", "0") 84 | modified |= modify_preprocessor(preprocessors, "FZ_ENABLE_MOBI", "0") 85 | modified |= modify_preprocessor(preprocessors, "FZ_ENABLE_OFFICE", "0") 86 | modified |= modify_preprocessor(preprocessors, "FZ_ENABLE_OCR_OUTPUT", "0") 87 | modified |= modify_preprocessor(preprocessors, "FZ_ENABLE_ODT_OUTPUT", "0") 88 | modified |= modify_preprocessor(preprocessors, "FZ_ENABLE_DOCX_OUTPUT", "0") 89 | modified |= modify_preprocessor(preprocessors, "FZ_ENABLE_TXT", "0") 90 | modified |= modify_preprocessor(preprocessors, "FZ_ENABLE_XPS", "0") 91 | if modified: 92 | elem.text = ';'.join(preprocessors) 93 | 94 | cl_compile_elements = root.findall("ms:ItemGroup/ms:ClCompile", ns) 95 | 96 | # check if included Include='..\..\..\MuPDFLib\Document\mupdf_load_system_font.c' 97 | target_include = "..\\..\\..\\MuPDFLib\\Document\\mupdf_load_system_font.c" 98 | if not any(elem.get('Include') == target_include for elem in cl_compile_elements): 99 | # get first ItemGroup element 100 | first_item_group = root.find("ms:ItemGroup[ms:ClCompile]", ns) 101 | if first_item_group is not None: 102 | new_cl_compile = ET.SubElement(first_item_group, "ClCompile") 103 | new_cl_compile.set('Include', target_include) 104 | modified = True 105 | return modified 106 | 107 | def update_property_group(pg, ns, platform): 108 | """Update PropertyGroup / OutDir or IntDir when needed.""" 109 | modified = False 110 | if platform == 'Win32': 111 | out_dir = pg.find('ms:OutDir', ns) 112 | if out_dir is not None and out_dir.text != '$(Configuration)\\': 113 | out_dir.text = '$(Configuration)\\' 114 | modified = True 115 | elif out_dir is None: 116 | ET.SubElement(pg, "OutDir").text = '$(Configuration)\\' 117 | modified = True 118 | 119 | int_dir = pg.find('ms:IntDir', ns) 120 | if int_dir is not None and int_dir.text != '$(Configuration)\\$(ProjectName)\\': 121 | int_dir.text = '$(Configuration)\\$(ProjectName)\\' 122 | modified = True 123 | elif platform == 'x64': 124 | out_dir = pg.find('ms:OutDir', ns) 125 | if out_dir is not None and out_dir.text != '$(Platform)\\$(Configuration)\\': 126 | out_dir.text = '$(Platform)\\$(Configuration)\\' 127 | modified = True 128 | elif out_dir is None: 129 | ET.SubElement(pg, "OutDir").text = '$(Platform)\\$(Configuration)\\' 130 | modified = True 131 | 132 | int_dir = pg.find('ms:IntDir', ns) 133 | if int_dir is not None and int_dir.text != '$(Platform)\\$(Configuration)\\$(ProjectName)\\': 134 | int_dir.text = '$(Platform)\\$(Configuration)\\$(ProjectName)\\' 135 | modified = True 136 | return modified 137 | 138 | if __name__ == "__main__": 139 | main() 140 | -------------------------------------------------------------------------------- /MuPDFLib/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by MuPDFLib.rc 4 | 5 | // Next default values for new objects 6 | // 7 | #ifdef APSTUDIO_INVOKED 8 | #ifndef APSTUDIO_READONLY_SYMBOLS 9 | #define _APS_NEXT_RESOURCE_VALUE 101 10 | #define _APS_NEXT_COMMAND_VALUE 40001 11 | #define _APS_NEXT_CONTROL_VALUE 1001 12 | #define _APS_NEXT_SYMED_VALUE 101 13 | #endif 14 | #endif 15 | -------------------------------------------------------------------------------- /MuPDFLib/sync_name_table.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Generates PDF names for name-table.h, replacing symbols invalid for .NET fields. 5 | """ 6 | 7 | import os, re, time 8 | import pathlib 9 | 10 | def replaceInvalidSymbol(m): 11 | return "PDF_MAKE_NAME(\""+m.group(1)+"\", _"+m.group(2)+")" 12 | 13 | def main(): 14 | os.chdir(os.path.join(os.path.dirname(__file__), "..")) 15 | 16 | src = "mupdf/include/mupdf/pdf/name-table.h" 17 | dest = "MuPDFLib/!Include/name-table.h" 18 | 19 | ms = os.path.getmtime(src) 20 | 21 | if os.path.isfile(dest): 22 | md = os.path.getmtime(dest) 23 | if ms == md: 24 | print("skipped up-to-date name-table.h") 25 | return; 26 | 27 | name_table = open(src).read() 28 | name_table = re.sub(r"PDF_MAKE_NAME\(\"(.+?)\", (\d.*)\)", replaceInvalidSymbol, name_table) 29 | name_table = re.sub(r"/[/\*].*?\r?\n", "", name_table) 30 | 31 | target = open(dest, "wt") 32 | target.write("// This file is automatically generated by sync_name_table.py from mupdf/include/mupdf/pdf/name-table.h\n") 33 | target.write("// Time: " + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())) 34 | target.write(name_table) 35 | 36 | os.utime(dest, (time.time(), ms)) 37 | 38 | print("synced name-table.h") 39 | 40 | if __name__ == "__main__": 41 | main() 42 | -------------------------------------------------------------------------------- /MuPDFLib/version.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Rewrite version numbers in AssemblyInfo and resource 5 | """ 6 | 7 | import os, re 8 | import pathlib 9 | 10 | MAJOR = "2" 11 | MAJOR_REV = "1" 12 | MINOR = "26" 13 | MINOR_REV = "0" 14 | 15 | def rewriteRevision(m): 16 | return m.group(1) + MAJOR + m.group(2) + MAJOR_REV + m.group(2) + MINOR + m.group(2) + MINOR_REV + m.group(4) 17 | 18 | def main(): 19 | os.chdir(os.path.dirname(__file__)) 20 | 21 | file = "AssemblyInfo.cpp" 22 | content = open(file).read() 23 | newContent = re.sub(r"(AssemblyFileVersion(?:Attribute?)\(\")\d+\.\d+\.\d+(\.)(\d+)(\"\))", rewriteRevision, content) 24 | if newContent != content: 25 | open(file, "wt").write(newContent) 26 | print("rewrite " + file) 27 | else: 28 | print("skipped " + file) 29 | 30 | file = "MuPDFLib.rc" 31 | content = open(file, encoding="utf-16").read() 32 | newContent = re.sub(r"([A-Z]+VERSION\s+)\d+,\d+,\d+(,)(\d+)(\s*?)", rewriteRevision, content) 33 | if newContent != content: 34 | newContent = re.sub(r"(VALUE\s+\"\w+Version\", \")\d+\.\d+\.\d+(\.)(\d+)(\")", rewriteRevision, newContent) 35 | open(file, "wt", encoding="utf-16").write(newContent) 36 | print("rewrite " + file) 37 | else: 38 | print("skipped " + file) 39 | 40 | if __name__ == "__main__": 41 | main() 42 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Sharp MuPDF 2 | 3 | Sharp MuPDF demonstrates how to compile MuPDF source code into a dynamic link library and consume its functionality in .NET. 4 | 5 | ## Compile 6 | 7 | To compile the source code. 8 | 9 | 1. Install _Visual Studio 2019_ or newer versions. 10 | 11 | 2. Install _python 3_ (`Python.exe` must be accessible via the PATH environment variable). 12 | 13 | 3. Open the `MuPDF.sln` in the solution folder with Visual Studio. 14 | 15 | 4. Compile the solution. 16 | 17 | 5. During compilation, Python will be called to generate the definition file for the target dll file. 18 | 19 | 6. Results: 20 | 21 | `MuPDFLib` project will produce two DLL files for mupdf, one for x86 and the other for x64. 22 | 23 | `Demo` project contains some code to demonstrate how to use functions in MuPDFLib.dll 24 | 25 | ## System font loading 26 | 27 | In order to support loading system fonts for documents with unembedded fonts and avoid the performance lost across DLL files, a code file named `mupdf_load_system_font.c` shall be compiled with the `libmupdf` project. 28 | 29 | We have to modify that project and reference the code file from `MuPDFLib\Document\mupdf_load_system_font.c`. 30 | 31 | That code file is copied from project *SumatraPDF* and all credits goes to them. 32 | 33 | ## Shrinking MuPDFLib.dll 34 | 35 | The default compilation of MuPDFLib contains a large Unicode font TOFU. 36 | 37 | Usually we don't need it. We can exclude it by the following procedure. 38 | 39 | Open the property page for the `libmupdf` project. 40 | 41 | Add `;TOFU;TOFU_CJK_EXT` to _C/C++_/_Preprocessor_/_Preprocessor Definitions_ for _All Configurations_ and _All Platforms_ in configuration manager. 42 | 43 | For more information, see `config.h` file within the `!include/fitz` folder in `libmupdf` project. 44 | 45 | ## Compilation helper scripts 46 | 47 | There are several Python scripts in the folder of MuPDFLib. You can open and read the comment on top of the scripts to learn their usage. 48 | 49 | Those scripts are run before compiling the `MuPDFLib` project automatically. 50 | 51 | Especially, the `modify_vcxprojs.py` script should be run before compiling the `libmupdf` project, to make modifications about _System font loading_ and _Shrinking MuPDFLib.dll_. 52 | 53 | ## .NET assembly reference of MuPDFLib.dll 54 | 55 | From version 2.* on, it is possible to reference MuPDFLib.dll as a .NET assembly, since it is compiled with C++/CLI. 56 | 57 | If you redistribute the MuPDFLib.dll which is referenced as a .NET assembly in your application, your users may encounter a problem that *the MuPDFLib.dll could not be loaded*. 58 | 59 | To fix the problem, enclose the Visual C++ Runtime library files with your redistribution. At least, `vcruntime140.dll` and `msvcp140.dll` are the minimum set of required DLL files. 60 | 61 | If you don't reference MuPDFLib.dll as a .NET assembly, those Visual C++ Runtime library files are not necessary. 62 | 63 | ## License 64 | 65 | This project follows the license terms of *MuPDF*. 66 | 67 | ## Update source code 68 | 69 | 1. Use `git pull` command to update the repository. 70 | 71 | 2. To update source code, tags and submodules, use: 72 | 73 | ``` bash 74 | cd mupdf 75 | git pull origin master --recurse-submodules 76 | ``` 77 | 78 | It is possible that local modifications have been made. To discard local modifications when updating submodules, use the following command before `pull`ing from master: 79 | 80 | ``` bash 81 | git reset --hard --recurse-submodules origin/master 82 | git reset --hard --recurse-submodules 83 | ``` 84 | 85 | To fetch remote tags, use: 86 | 87 | ``` bash 88 | git fetch origin --tags 89 | ``` 90 | 91 | Afterwards, it is possible to check out the newly added tags: 92 | ``` bash 93 | git checkout 94 | ``` 95 | 96 | Alternatively, we can also execute the following commands against each changed files: 97 | 98 | ``` bash 99 | git reset HEAD 100 | git checkout -- 101 | ``` 102 | 103 | We may see the following warning when we `pull` from master: 104 | 105 | ``` 106 | error: You have not concluded your merge (MERGE_HEAD exists). 107 | hint: Please, commit your changes before merging. 108 | fatal: Exiting because of unfinished merge. 109 | ``` 110 | 111 | To fix this, run the following commands: 112 | 113 | ``` bash 114 | git fetch --all 115 | git reset --hard origin/master 116 | ``` 117 | 118 | Afterwards, we can `pull` from master then. 119 | 120 | Sometimes, new submodules could be added to the origin repository. Use the following command to update them into your repository. 121 | 122 | ``` bash 123 | git submodule update --init --recursive 124 | ``` 125 | 126 | 3. The first a few lines in the `name-table.h` file have slight modifications from the original one in the `libmupdf` project, for the sake of making field names valid in .NET. Check whether it is changed and make the corresponding synchronization. To facilitate this operation, run the `sync_name_table.py` script within the `MuPDFLib` project folder. 127 | 128 | ## Git Proxy 129 | If accessing the Internet requires HTTPS proxy, use the following command: 130 | 131 | ``` bash 132 | git config --global http.proxy 133 | git config --global https.proxy 134 | ``` 135 | 136 | When you are done, use the following command to reset the proxy to default: 137 | 138 | ``` bash 139 | git config --global --unset http.proxy 140 | git config --global --unset https.proxy 141 | ``` 142 | --------------------------------------------------------------------------------