yes using Document.BackgroundOpen as @Kulkul says is useful, but it’s not enough to complete your task.
You must modify @Konrad_K_Sobon 's print pdf node a little bit :
change the line :
doc = DocumentManager.Instance.CurrentDBDocument
to
doc = IN[7]
then add an extra input to the python node and feed it the document. I just tried and it works well !