Skip to content

Commit cdba4e0

Browse files
Merge pull request #231 from ArtifexSoftware/9feb2026-fix-issues
added supports for new version of MuPDF 1.27.2
2 parents aabf8a8 + 3b2e2b8 commit cdba4e0

21 files changed

Lines changed: 847 additions & 95 deletions

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
### [3.2.13-rc.14] - 2026-02-11
4+
- Upgraded `MuPDF.NativeAssets` to 1.27.2 and refreshed generated MuPDF bindings for Windows and Linux.
5+
- Implemented `IDisposable` on core types (`Document`, `Page`, `TextPage`, `Story`, `DocumentWriter`, `DisplayList`, `Font`, `GraftMap`, `DeviceWrapper`, `Outline`) and made `Document.Dispose()` idempotent.
6+
- Hardened native resource handling (e.g. `Document.Convert2Pdf`, `Pixmap.InvertIrect`) to be exception-safe, fixed `Pixmap.InvertIrect` null/stencil handling, and added tests for table extraction and disposal patterns.
7+
38
### [3.2.13-rc.6] - 2025-12-26
49
- Fixed the issues in `ResolveNames` method.
510
- Fixed the issues in `DrawShape`

Demo/Program.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,30 @@ static void Main(string[] args)
8484
TestTable();
8585
TestGetText();
8686
TestMarkdownReader();
87+
TestRecompressJBIG2();
8788

8889
return;
8990
}
9091

92+
static void TestRecompressJBIG2()
93+
{
94+
Console.WriteLine("\n=== TestJBIG2 =======================");
95+
96+
string testFilePath = Path.GetFullPath("../../../TestDocuments/Jbig2.pdf");
97+
98+
Document doc = new Document(testFilePath);
99+
100+
PdfImageRewriterOptions opts = new PdfImageRewriterOptions();
101+
102+
opts.bitonal_image_recompress_method = mupdf.mupdf.FZ_RECOMPRESS_FAX;
103+
opts.recompress_when = mupdf.mupdf.FZ_RECOMPRESS_WHEN_ALWAYS;
104+
105+
doc.RewriteImage(options: opts);
106+
107+
doc.Save(@"e:\TestRecompressJBIG2.pdf");
108+
doc.Close();
109+
}
110+
91111
static void TestMarkdownReader()
92112
{
93113
Console.WriteLine("\n=== TestMarkdownReader =======================");

Demo/TestDocuments/Jbig2.pdf

128 KB
Binary file not shown.
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
using System;
2+
using System.IO;
3+
using NUnit.Framework;
4+
using MuPDF.NET;
5+
6+
namespace MuPDF.NET.Test
7+
{
8+
public class DisposePatternTest
9+
{
10+
private const string TocPath = "../../../resources/toc.pdf";
11+
12+
[Test]
13+
public void Document_Dispose_MultipleTimes_DoesNotThrow()
14+
{
15+
var doc = new Document(TocPath);
16+
17+
doc.Dispose();
18+
19+
Assert.DoesNotThrow(() => doc.Dispose());
20+
}
21+
22+
[Test]
23+
public void Page_Dispose_MultipleTimes_DoesNotThrow()
24+
{
25+
var doc = new Document(TocPath);
26+
var page = doc[0];
27+
28+
page.Dispose();
29+
30+
Assert.DoesNotThrow(() => page.Dispose());
31+
32+
doc.Dispose();
33+
}
34+
35+
[Test]
36+
public void TextPage_Dispose_MultipleTimes_DoesNotThrow()
37+
{
38+
var doc = new Document(TocPath);
39+
var page = doc[0];
40+
var textPage = page.GetTextPage();
41+
42+
textPage.Dispose();
43+
44+
Assert.DoesNotThrow(() => textPage.Dispose());
45+
46+
page.Dispose();
47+
doc.Dispose();
48+
}
49+
50+
[Test]
51+
public void Story_Dispose_MultipleTimes_DoesNotThrow()
52+
{
53+
var story = new Story("<p>Hello</p>");
54+
55+
story.Dispose();
56+
57+
Assert.DoesNotThrow(() => story.Dispose());
58+
}
59+
60+
[Test]
61+
public void DisplayList_Dispose_MultipleTimes_DoesNotThrow()
62+
{
63+
var rect = new Rect(0, 0, 100, 100);
64+
var dl = new DisplayList(rect);
65+
66+
dl.Dispose();
67+
68+
Assert.DoesNotThrow(() => dl.Dispose());
69+
}
70+
71+
[Test]
72+
public void DocumentWriter_Dispose_MultipleTimes_DoesNotThrow()
73+
{
74+
string path = Path.GetTempFileName();
75+
76+
try
77+
{
78+
var writer = new DocumentWriter(path);
79+
80+
writer.Dispose();
81+
82+
Assert.DoesNotThrow(() => writer.Dispose());
83+
}
84+
finally
85+
{
86+
if (File.Exists(path))
87+
File.Delete(path);
88+
}
89+
}
90+
91+
[Test]
92+
public void Font_Dispose_MultipleTimes_DoesNotThrow()
93+
{
94+
var font = new Font();
95+
96+
font.Dispose();
97+
98+
Assert.DoesNotThrow(() => font.Dispose());
99+
}
100+
101+
[Test]
102+
public void GraftMap_Dispose_MultipleTimes_DoesNotThrow()
103+
{
104+
var doc = new Document(TocPath);
105+
var map = new GraftMap(doc);
106+
107+
map.Dispose();
108+
109+
Assert.DoesNotThrow(() => map.Dispose());
110+
111+
doc.Dispose();
112+
}
113+
114+
// Outline is constructed internally from native MuPDF outline structures and
115+
// not exposed as a public constructor. Its disposal semantics are exercised
116+
// indirectly via Document/Document.GetToc tests, so we skip a direct idempotency test.
117+
}
118+
}
119+
0 Bytes
Binary file not shown.

MuPDF.NET/DeviceWrapper.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
using mupdf;
1+
using mupdf;
2+
using System;
23

34
namespace MuPDF.NET
45
{
5-
public class DeviceWrapper
6+
public class DeviceWrapper : IDisposable
67
{
78
static DeviceWrapper()
89
{

MuPDF.NET/DisplayList.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
using mupdf;
1+
using mupdf;
2+
using System;
23

34
namespace MuPDF.NET
45
{
5-
public class DisplayList
6+
public class DisplayList : IDisposable
67
{
78

89
static DisplayList()

0 commit comments

Comments
 (0)