1{
2 stdenv,
3 lib,
4 fetchFromGitHub,
5 python,
6 buildPythonPackage,
7 imagemagick,
8 pip,
9 pytestCheckHook,
10 pymupdf,
11 fire,
12 fonttools,
13 numpy,
14 opencv4,
15 tkinter,
16 python-docx,
17}:
18let
19 version = "0.5.8";
20in
21buildPythonPackage {
22 pname = "pdf2docx";
23 inherit version;
24 format = "setuptools";
25
26 src = fetchFromGitHub {
27 owner = "dothinking";
28 repo = "pdf2docx";
29 rev = "refs/tags/v${version}";
30 hash = "sha256-tMITDm2NkxWS+H/hhd2LlaPbyuI86ZKaALqqHJqb8V0=";
31 };
32
33 nativeBuildInputs = [
34 pip
35 imagemagick
36 ];
37
38 pythonRemoveDeps = [ "opencv-python" ];
39
40 preBuild = "echo '${version}' > version.txt";
41
42 propagatedBuildInputs = [
43 tkinter
44 pymupdf
45 fire
46 fonttools
47 numpy
48 opencv4
49 python-docx
50 ];
51
52 postInstall = lib.optionalString stdenv.isLinux ''
53 # on linux the icon file can only be xbm format
54 convert $out/${python.sitePackages}/pdf2docx/gui/icon.ico \
55 $out/${python.sitePackages}/pdf2docx/gui/icon.xbm
56 substituteInPlace $out/${python.sitePackages}/pdf2docx/gui/App.py \
57 --replace 'icon.ico' 'icon.xbm' \
58 --replace 'iconbitmap(icon_path)' "iconbitmap(f'@{icon_path}')"
59 '';
60
61 nativeCheckInputs = [ pytestCheckHook ];
62
63 pytestFlagsArray = [
64 "-v"
65 "./test/test.py::TestConversion"
66 ];
67
68 # Test fails due to "RuntimeError: cannot find builtin font with name 'Arial'":
69 disabledTests = [ "test_unnamed_fonts" ];
70
71 meta = with lib; {
72 description = "Convert PDF to DOCX";
73 mainProgram = "pdf2docx";
74 homepage = "https://github.com/dothinking/pdf2docx";
75 changelog = "https://github.com/dothinking/pdf2docx/releases/tag/v${version}";
76 license = licenses.gpl3Only;
77 maintainers = with maintainers; [ happysalada ];
78 };
79}