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