从MatPlotLib导入PDF图像到ReportLab

时间:2018-10-28 19:52:08

标签: python-3.x pdf matplotlib reportlab pypdf2

我正在尝试将保存的PDF图像插入ReportLab Flowable。

我已经看到了类似问题的多个答案,其中许多涉及使用Py2PDF,如下所示:

class Program {
    static void Main(string[] args) {
        string pathToCmd = GetPathToCmd("file-to-look-for.py", @"c:\scripts");
        Console.WriteLine(pathToCmd ?? "Not found");
    }

    static string GetPathToCmd(string cmd, string alsoLookIn) {
        using (PowerShell powerShell = PowerShell.Create()) {
            // Anyway to add "alsoLookIn" to powerShell's path?

            powerShell.AddCommand("get-command")
                .AddArgument(new[] {$@".\{cmd}", cmd})
                .AddParameter("Type", new[] {"Application", "ExternalScript"})
                .AddParameter("ErrorAction", "Ignore")
                ;

            CommandInfo commandInfo = powerShell.Invoke<CommandInfo>().FirstOrDefault();
            return commandInfo?.Source;
        }
    }
}

我遇到的麻烦是与从MatPlotLib中保存为PDF的示例图像有关。当我尝试使用上面的代码访问该保存的图像时,它在import PyPDF2 import PIL input1 = PyPDF2.PdfFileReader(open(path+"image.pdf", "rb")) page0 = input1.getPage(0) xObject = page0['/Resources']['/XObject'].getObject() for obj in xObject: #Do something here 下不返回任何内容。

实际上,这是我在查看page0和/ XObject时看到的:

'/ XObject':{}

这是我用来生成PDF的代码:

page0['/Resources']['/XObject']

谢谢!

0 个答案:

没有答案