{"action":"created","issue":{"url":"https://api.github.com/repos/matplotlib/matplotlib/issues/6317","repository_url":"https://api.github.com/repos/matplotlib/matplotlib","labels_url":"https://api.github.com/repos/matplotlib/matplotlib/issues/6317/labels{/name}","comments_url":"https://api.github.com/repos/matplotlib/matplotlib/issues/6317/comments","events_url":"https://api.github.com/repos/matplotlib/matplotlib/issues/6317/events","html_url":"https://github.com/matplotlib/matplotlib/issues/6317","id":149314189,"number":6317,"title":"PDF file generation is not deterministic - results in different outputs on the same input","user":{"login":"drufat","id":1400254,"avatar_url":"https://avatars.githubusercontent.com/u/1400254?v=3","gravatar_id":"","url":"https://api.github.com/users/drufat","html_url":"https://github.com/drufat","followers_url":"https://api.github.com/users/drufat/followers","following_url":"https://api.github.com/users/drufat/following{/other_user}","gists_url":"https://api.github.com/users/drufat/gists{/gist_id}","starred_url":"https://api.github.com/users/drufat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/drufat/subscriptions","organizations_url":"https://api.github.com/users/drufat/orgs","repos_url":"https://api.github.com/users/drufat/repos","events_url":"https://api.github.com/users/drufat/events{/privacy}","received_events_url":"https://api.github.com/users/drufat/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/matplotlib/matplotlib/labels/backend/pdf","name":"backend/pdf","color":"c7def8"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/matplotlib/matplotlib/milestones/12","html_url":"https://github.com/matplotlib/matplotlib/milestones/2.1%20(next%20point%20release)","labels_url":"https://api.github.com/repos/matplotlib/matplotlib/milestones/12/labels","id":534144,"number":12,"title":"2.1 (next point release)","description":"Next feature release.\r\n\r\nBig ticket items:\r\n\r\n - MEP 22/27\r\n - traitlets","creator":{"login":"tacaswell","id":199813,"avatar_url":"https://avatars.githubusercontent.com/u/199813?v=3","gravatar_id":"","url":"https://api.github.com/users/tacaswell","html_url":"https://github.com/tacaswell","followers_url":"https://api.github.com/users/tacaswell/followers","following_url":"https://api.github.com/users/tacaswell/following{/other_user}","gists_url":"https://api.github.com/users/tacaswell/gists{/gist_id}","starred_url":"https://api.github.com/users/tacaswell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tacaswell/subscriptions","organizations_url":"https://api.github.com/users/tacaswell/orgs","repos_url":"https://api.github.com/users/tacaswell/repos","events_url":"https://api.github.com/users/tacaswell/events{/privacy}","received_events_url":"https://api.github.com/users/tacaswell/received_events","type":"User","site_admin":false},"open_issues":477,"closed_issues":343,"state":"open","created_at":"2014-01-13T03:21:09Z","updated_at":"2016-04-20T01:40:56Z","due_on":null,"closed_at":null},"comments":17,"created_at":"2016-04-19T00:54:43Z","updated_at":"2016-04-20T05:54:57Z","closed_at":null,"body":"Suppose you want to generate a pdf file with matplotlib and save it. \r\n\r\n`genfigure.py`:\r\n```\r\nimport matplotlib.pyplot as plt\r\nimport sys\r\nplt.plot([0, 1], [0, 1])\r\nplt.savefig(sys.argv[1])\r\n```\r\n\r\nRun the script from the command line\r\n\r\n```\r\n$ python genfigure.py 1.pdf\r\n$ python genfigure.py 2.pdf\r\n```\r\n\r\nGiven that we are saving the same figure, we would expect the output to be the same. However, after looking at the file hashes, they appear to be different. In my particular case:\r\n\r\n```\r\n$ md5sum 1.pdf 2.pdf\r\ne54cdbd65a6baaa5152d90743d800039  1.pdf\r\n4b0ac2a7c046c4813114c63f3c4d27e7  2.pdf\r\n```\r\n\r\nOn the other hand, no such issue exists when saving png files. \r\n\r\n```\r\n$ python genfigure.py 1.png\r\n$ python genfigure.py 2.png\r\n\r\n```\r\nThe two `png` files are exactly the same\r\n\r\n```\r\n$ md5sum 1.png 2.png\r\n5d22187827337cd9262ee248550fab6f  1.png\r\n5d22187827337cd9262ee248550fab6f  2.png\r\n```\r\nIt appears that pdf saving has some source of non-determinism.\r\n\r\nIs there a way to ensure that saving the same figure multiple times, results in exactly the same pdf file?"},"comment":{"url":"https://api.github.com/repos/matplotlib/matplotlib/issues/comments/212271971","html_url":"https://github.com/matplotlib/matplotlib/issues/6317#issuecomment-212271971","issue_url":"https://api.github.com/repos/matplotlib/matplotlib/issues/6317","id":212271971,"user":{"login":"jkseppan","id":92814,"avatar_url":"https://avatars.githubusercontent.com/u/92814?v=3","gravatar_id":"","url":"https://api.github.com/users/jkseppan","html_url":"https://github.com/jkseppan","followers_url":"https://api.github.com/users/jkseppan/followers","following_url":"https://api.github.com/users/jkseppan/following{/other_user}","gists_url":"https://api.github.com/users/jkseppan/gists{/gist_id}","starred_url":"https://api.github.com/users/jkseppan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jkseppan/subscriptions","organizations_url":"https://api.github.com/users/jkseppan/orgs","repos_url":"https://api.github.com/users/jkseppan/repos","events_url":"https://api.github.com/users/jkseppan/events{/privacy}","received_events_url":"https://api.github.com/users/jkseppan/received_events","type":"User","site_admin":false},"created_at":"2016-04-20T05:54:57Z","updated_at":"2016-04-20T05:54:57Z","body":"I still think it's simpler to iterate dicts in order than to replace them with OrderedDicts. The `pdfRepr` function is a chokepoint through which all page content passes, so it should be enough to change the iteration order there. I don't have time right now to test and submit a patch, but it should be a one- or two-line change.\r\n\r\nIMHO we should add separate options to set the creation date to a user-supplied value (or to remove it) and to disable font subsetting (the pdf spec requires the addition of tags for subsets, so not adding them makes the resulting file non-compliant), and any other sources of nondeterminism that we discover. I think it's likely that there are such sources that we may have missed so far."}}